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_INVITATIONtới Player B → Player B nhậnINVITATION_RECEIVED - [ ] Player B gửi
ACCEPT_INVITATION→ match initiated, cả 2 nhậnMATCH_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ậnINVITATION_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_INVITATIONtrả vềVALIDATE_GAMEvới reasonMatchingReasonCode.INVITATION_EXPIRED - [ ] Batch
DeleteExpiredInvitationConfigdọ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_INVITATIONvớiinvitationIdkhông tồn tại → reasonMatchingReasonCode.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_INVITATIONsau TTL trả lỗi vớiINVITATION_EXPIREDreason - [ ] 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