Skip to content

BE-20: Add integration tests for WebSocket endpoints using actix-web test helpers (#868) - #911

Open
JesseJohn7 wants to merge 1 commit into
OpenKnight-Foundation:mainfrom
JesseJohn7:issue-868
Open

BE-20: Add integration tests for WebSocket endpoints using actix-web test helpers (#868)#911
JesseJohn7 wants to merge 1 commit into
OpenKnight-Foundation:mainfrom
JesseJohn7:issue-868

Conversation

@JesseJohn7

Copy link
Copy Markdown

Closes #868

Summary

Adds a real integration test suite for /v1/ws/game/{game_id} using actix_web::test::TestServer and an awc WS 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

  • Successful connection with a valid JWT, then a simulated short chess game (MoveClockMoveClockEnd) pushed via LobbyState::Broadcast, asserting each frame is valid JSON, stamped with version: "1.0", and round-trips back into the exact WsMessage sent.
  • Rejected connection with no Authorization header.
  • Rejected connection with an invalid/malformed token.
  • Two simultaneous clients in the same game_id both receive the same broadcast.
  • Client-initiated Ping is answered with Pong.

Finding: client-sent moves are currently a no-op

While writing this suite I found that WsSession's StreamHandler for ws::Message::Text parses an incoming message into a WsMessage but its match arm body is empty — a client sending a Move over the socket today produces no broadcast, no validation, and no response. All "moves" in this test suite are therefore simulated via LobbyState::Broadcast directly (mirroring what real move-processing logic elsewhere in the app presumably does over some other path), not by sending a Move from the client side.

I added client_sent_move_message_currently_produces_no_response as 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 the chess crate, broadcasting the result) is a meaningfully larger change than this test-only issue asked for.

Changes

  • backend/modules/api/Cargo.toml: added awc and futures-util as 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: exposed pub mod ws; so the integration test (in tests/, which only sees a crate's public API) can reach WsMessage/LobbyState/Broadcast/ws_route. (Only if this was needed — see Step 4.)

Testing

cargo test --test ws_integration_test and cargo test --workspace pass. cargo clippy --workspace clean.

@drips-wave

drips-wave Bot commented Jul 29, 2026

Copy link
Copy Markdown

@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! 🚀

Learn more about application limits

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BE-20: Add integration tests for WebSocket endpoints using actix-web test helpers

1 participant