Skip to content

Task 3-3: Integration Test - Invitation Lifecycle

Phase: 3 - Testing Priority: Medium Depends on: task-1-1 Reference: docs/BountyHunter-Backend/details/feature-matching-matchmaking/SPEC.md

Background

Test end-to-end cho invitation flow: send → accept/deny → expiry.

Test scenarios

Happy path

  • [ ] Player A gửi SEND_INVITATION tới Player B → Player B nhận INVITATION_RECEIVED
  • [ ] Player B gửi ACCEPT_INVITATION → match initiated, cả 2 nhận MATCH_FOUND
  • [ ] Room được tạo thành công với đúng prizes
  • [ ] Invitation record removed sau khi accepted

Deny path

  • [ ] Player B gửi DENY_INVITATION → Player A nhận INVITATION_DENIED
  • [ ] Invitation record removed từ DB/Redis
  • [ ] Player A có thể gửi lại invitation mới sau deny

Expiry

  • [ ] Gửi invitation → wait for TTL to expire (mock thời gian hoặc set TTL ngắn trong test) → ACCEPT_INVITATION trả về VALIDATE_GAME với reason MatchingReasonCode.INVITATION_EXPIRED
  • [ ] Batch DeleteExpiredInvitationConfig dọn sạch expired records đúng:
  • Chạy batch manually hoặc trigger scheduled job
  • Verify record không còn trong DB sau cleanup
  • [ ] Idempotent: chạy cleanup batch 2 lần cho cùng expired invitation → không lỗi

Error cases (dùng MatchingReasonCode từ task-1-1)

  • [ ] ACCEPT_INVITATION với invitationId không tồn tại → reason MatchingReasonCode.INVITATION_NOT_FOUND
  • [ ] Target user đang busy (trong queue hoặc đang play) → reason MatchingReasonCode.TARGET_USER_BUSY

Verification / Acceptance Criteria

  • [ ] Happy path: cả 2 players nhận MATCH_FOUND, room tạo thành công
  • [ ] Deny path: Player A nhận INVITATION_DENIED, record cleanup đúng
  • [ ] Expiry: ACCEPT_INVITATION sau TTL trả lỗi với INVITATION_EXPIRED reason
  • [ ] Cleanup batch: expired records removed, không lỗi khi chạy nhiều lần
  • [ ] Tất cả error reason codes dùng MatchingReasonCode.* constants

Files to Modify

  • Test files trong websocket/src/test/ hoặc integration test module