Task 4-1: Integration Test - PVE Free Play Flow
Phase: 4 - Testing Priority: Medium Depends on: task-1-1 Reference:
docs/BountyHunter-Backend/details/feature-game-room-management/SPEC.md
Background
Cần test coverage đầy đủ cho PVE Free Play room lifecycle qua WebSocket.
Setup Note: Integration tests cần: - Embedded Redis (hoặc test Redis container) cho room state - Embedded ActiveMQ (hoặc test JMS broker) cho queue routing verification - 2 WebSocket client connections (player 1 và player 2) để test multi-player scenarios -
task-1-1phải hoàn thành trước để dùngRoomReasonCode.*constants trong assertions
Test scenarios
Happy path
- [ ] Send
CREATE_PVE_FREE_PLAY_ROOM→ receiveROOM_CREATED - Clarification: Verify response chứa
roomIdfield để dùng cho các bước tiếp theo - [ ] Verify room state in Redis:
status=WAITING, player added - Clarification: Dùng Redis test client để check key tương ứng với
roomId - [ ] Second player sends
JOIN_PVE_FREE_PLAY_ROOMvới đúngroomId→ receivePLAYER_JOINED - [ ] Both players send
READY_FOR_START_GAME→ cả 2 receiveGAME_START - Clarification: Verify player 1 nhận
GAME_STARTVÀ player 2 cũng nhận — không chỉ 1 trong 2 - [ ] One player sends
QUIT_GAME→ receiveGAME_CANCELLED, room cleaned up in Redis - Clarification: Verify Redis key cho room đã bị xóa (hoặc status =
CANCELLED)
Validation errors
- [ ] Create room khi user đang ở room khác →
VALIDATE_GAMEevent vớireason=ROOM_ALREADY_EXIST - Clarification: Sau task-1-1, assert bằng
RoomReasonCode.ROOM_ALREADY_EXISTconstant - [ ] Join room khi đã đầy →
VALIDATE_GAMEevent vớireason=ROOM_IS_FULL - Clarification: "Đầy" nghĩa là PVE Free Play room đã có đủ số player tối đa (check SPEC.md để biết max players)
Queue routing
- [ ] Confirm
CREATE_PVE_FREE_PLAY_ROOMroutes tớiqueue-prize-allocation-UNLIMITED - Clarification: Verify bằng cách listen trên queue đó và kiểm tra message nhận được
- [ ] Confirm không có message còn lại trong queue sau khi flow hoàn thành
- Clarification: Check queue depth = 0 sau khi đợi đủ thời gian xử lý (e.g., 5 giây)
Verification / Acceptance Criteria
- [ ] Tất cả test scenarios trên pass với màu xanh (0 failures)
- [ ] Happy path test hoàn thành trong < 10 giây (không có infinite wait)
- [ ] Validation error tests verify đúng
reasoncode từRoomReasonCode.*(không dùng string literal) - [ ] Queue routing test confirm đúng queue name
queue-prize-allocation-UNLIMITED - [ ] Redis state được cleanup sau mỗi test (không để lại stale data ảnh hưởng test khác)
- [ ] Tests chạy được độc lập mà không cần external services (dùng embedded/test doubles)
- [ ] Test class được đặt đúng trong module test của
websocketservice