BE-20: Add integration tests for WebSocket endpoints using actix-web test helpers (#868) - #911
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! 🚀 |
|
Hi maintainer , I hope you're doing well! I wanted to gently follow up on this PR I've fixed the issue it was addressing . I know you're busy, but it would mean a lot if you could take a look and merge it when you get a chance. I've been waiting a while and would really appreciate it 🙏 Thank you so much for maintaining this project! |
1 similar comment
|
Hi maintainer , I hope you're doing well! I wanted to gently follow up on this PR I've fixed the issue it was addressing . I know you're busy, but it would mean a lot if you could take a look and merge it when you get a chance. I've been waiting a while and would really appreciate it 🙏 Thank you so much for maintaining this project! |
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.