BE-20: Add integration tests for WebSocket endpoints using actix-web test helpers (#868) - #911
Open
JesseJohn7 wants to merge 1 commit into
Open
BE-20: Add integration tests for WebSocket endpoints using actix-web test helpers (#868)#911JesseJohn7 wants to merge 1 commit into
JesseJohn7 wants to merge 1 commit into
Conversation
|
@JesseJohn7 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #868
Summary
Adds a real integration test suite for
/v1/ws/game/{game_id}usingactix_web::test::TestServerand anawcWS client — connecting over an actual bound socket rather than calling the handler function directly, so the test exercises auth, the real handshake, and the actor message-passing path end to end.Coverage
Move→Clock→Move→Clock→End) pushed viaLobbyState::Broadcast, asserting each frame is valid JSON, stamped withversion: "1.0", and round-trips back into the exactWsMessagesent.Authorizationheader.game_idboth receive the same broadcast.Pingis answered withPong.Finding: client-sent moves are currently a no-op
While writing this suite I found that
WsSession'sStreamHandlerforws::Message::Textparses an incoming message into aWsMessagebut its match arm body is empty — a client sending aMoveover the socket today produces no broadcast, no validation, and no response. All "moves" in this test suite are therefore simulated viaLobbyState::Broadcastdirectly (mirroring what real move-processing logic elsewhere in the app presumably does over some other path), not by sending aMovefrom the client side.I added
client_sent_move_message_currently_produces_no_responseas an explicit, documented test of this current behavior (with a comment explaining it should be updated, not deleted, once real move-ingestion is implemented) rather than silently working around it — flagging this as a recommended follow-up issue, since implementing real client-move ingestion (validation via thechesscrate, broadcasting the result) is a meaningfully larger change than this test-only issue asked for.Changes
backend/modules/api/Cargo.toml: addedawcandfutures-utilas dev-dependencies for the WS test client.backend/modules/api/tests/ws_integration_test.rs(new): the integration suite described above.backend/modules/api/src/lib.rs: exposedpub mod ws;so the integration test (intests/, which only sees a crate's public API) can reachWsMessage/LobbyState/Broadcast/ws_route. (Only if this was needed — see Step 4.)Testing
cargo test --test ws_integration_testandcargo test --workspacepass.cargo clippy --workspaceclean.