Skip to main content

Testing

:::info Source Sourced from services/marketplace-service/TESTING_STRATEGY.md in the documentation repo. :::

1. Coverage Targets

Domain 95% line / 98% branch / 80% mutation. Integration 80%.

2. Unit Tests

  • Listing state machine (draft → submitted → approved → live → suspended → retired).
  • PricingPlan valid combinations (one_time, subscription, seat_pack, site_license).
  • Order line computation (currency, tax, discounts, coupons).
  • License invariants (seats ≤ purchased; remainingSeats ≥ 0).
  • Purchase saga state machine transitions + compensations.

3. Integration Tests (Testcontainers)

  • Postgres + NATS + mock billing.
  • Complete purchase flow: order → payment.succeeded → license.granted → enrollment.created.
  • Refund flow: order → refund → license.revoked → enrollment.revoked.
  • Saga failure at each step → compensation.
  • Listing submit → approval → marketplace visibility event.

4. Contract Tests

Pact:

  • marketplace → billing: order.placed.v1 triggers payment intent.
  • marketplace ← billing: consumes payment.succeeded.v1, .failed.v1.
  • marketplace → enrollment: license.granted.v1.
  • marketplace → notification: order.fulfilled.v1.
  • marketplace → search: listing.approved.v1.
  • OpenAPI diff in CI.

5. E2E Tests

  • J-06: browse → buy → receive license → enroll → play → certificate.
  • J-07: refund initiated → license revoked → learner loses access.
  • J-18: subscription purchase → monthly renewal → cancel.

6. Load Tests

  • Flash sale: 10k orders/min, p95 < 2s.
  • Saga throughput: 1k/sec sustained.
  • Marketplace browse: 100k concurrent.

7. Chaos

  • Billing service outage mid-saga → saga timeouts → compensation.
  • NATS partition → outbox drains on reconnect.
  • Database failover mid-purchase → resume from saga state.
  • Double-pay scenarios → idempotency on Idempotency-Key.

8. Saga Tests

  • Happy path each saga type.
  • Failure injection at every step.
  • Timeout scenarios.
  • Compensation correctness (no orphan state).

9. Security Tests

  • Cross-tenant listing access → 403.
  • Coupon injection via filters → typed parser rejects.
  • Chargeback simulation.
  • Fake review detection.
  • KYC bypass attempt.

10. AI Tests

  • Listing improve accept-rate eval.
  • Taxonomy suggestion consistency.
  • Pricing suggestion bias eval.

11. Offline Tests

  • Marketplace browse offline (cached).
  • Purchase attempt offline → error "online required."
  • License visible offline after purchase.

12. CI Gates

  • Unit + integration green.
  • Saga chaos tests per PR.
  • OpenAPI + Pact verified.
  • Two-tenant iso green.
  • Mutation ≥ 80%.