Skip to content

Task 3-2: Integration Test - Apple & Google IAP

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

Background

Test Apple In-App Purchase và Google Play billing flows.

Test scenarios

Apple IAP

  • [ ] POST /api/coin/buy-by-apple với valid receipt → order created, status=PENDING
  • [ ] Apple verify callback (mock AppleIapService.verifyAppleReceipt()) trả success → coin credited, status=SUCCESS
  • [ ] Apple verify callback gọi 2 lần (retry simulation) → second call idempotent (no double credit)
  • [ ] Invalid receipt → Apple API rejects → response với APPLE_RECEIPT_INVALID
  • [ ] Apple server timeout (mock RestTemplate để throw ResourceAccessException) → circuit breaker triggers → APPLE_VERIFY_UNAVAILABLE

Google Play

  • [ ] POST /api/coin/buy-by-google với valid purchaseToken → order created
  • [ ] Google verify callback (mock GooglePlayService.verifyPurchase()) trả success → coin credited
  • [ ] Invalid purchaseTokenGOOGLE_PURCHASE_INVALID
  • [ ] Duplicate purchaseToken (already consumed): idempotent skip — no double credit

Expiry batch

  • [ ] Create Apple/Google pending order → mock expiry TTL → batch expires it (status=EXPIRED)
  • [ ] Verify: coin không được credited khi expired

Verification / Acceptance Criteria

  • [ ] Apple happy path: order SUCCESS, balance credited
  • [ ] Google happy path: order SUCCESS, balance credited
  • [ ] Timeout scenario: circuit breaker (hoặc timeout exception) throws gracefully, không hang
  • [ ] Duplicate purchaseToken: idempotent, no double credit
  • [ ] Expired order: not credited after batch

Files to Modify

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