Skip to content

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-1 phải hoàn thành trước để dùng RoomReasonCode.* constants trong assertions

Test scenarios

Happy path

  • [ ] Send CREATE_PVE_FREE_PLAY_ROOM → receive ROOM_CREATED
  • Clarification: Verify response chứa roomId field để 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_ROOM với đúng roomId → receive PLAYER_JOINED
  • [ ] Both players send READY_FOR_START_GAMEcả 2 receive GAME_START
  • Clarification: Verify player 1 nhận GAME_START VÀ player 2 cũng nhận — không chỉ 1 trong 2
  • [ ] One player sends QUIT_GAME → receive GAME_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_GAME event với reason=ROOM_ALREADY_EXIST
  • Clarification: Sau task-1-1, assert bằng RoomReasonCode.ROOM_ALREADY_EXIST constant
  • [ ] Join room khi đã đầy → VALIDATE_GAME event với reason=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_ROOM routes tới queue-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 reason code 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 websocket service