Testing
:::info Source
Sourced from services/billing-service/TESTING_STRATEGY.md in the documentation repo.
:::
1. Coverage Targets
Domain 95% / 98% branch / 80% mutation. Integration 85%.
2. Unit Tests
- Invoice total computation (currency rounding, tax stacking).
- Subscription state machine.
- Dunning stage advancement (time-based).
- Refund invariants (amount ≤ refundable).
- Tax line calculation across jurisdictions.
- Payout amount computation (revenue share, refund deductions).
- Money arithmetic (micro-units; no floats).
3. Integration Tests (Testcontainers)
- Postgres + NATS + Stripe test mode.
- Full payment flow: intent → confirm → webhook → event emitted.
- Subscription renewal batch.
- Refund flow.
- Webhook signature validation (valid + invalid + replay).
4. Contract Tests
Pact:
- billing ← marketplace:
order.placed.v1→ create intent. - billing → marketplace:
payment.succeeded.v1,.failed.v1. - billing → notification: receipts, dunning messages.
- billing → analytics: revenue events.
- OpenAPI diff in CI.
5. Stripe Mock
- Use Stripe test mode in CI.
- Stripe Mock server for fully offline tests.
- Scenario scripts: successful payments, decline, 3DS required, disputed.
6. E2E Tests
- J-06: purchase → payment → license → enrollment.
- J-17: subscription signup → trial → convert → renewal → cancel.
- J-19: payment fail → dunning → resolve via new card.
- J-20: refund → license revoked.
7. Load Tests
- 10k payment intents/min.
- 1k webhooks/sec incoming (Stripe can batch).
- Monthly renewal batch: 100k subscriptions.
8. Chaos
- Stripe outage simulation → retries + alert.
- Webhook delivery delayed 30 min → replay still works.
- Reconciliation catches injected drift.
- Double webhook event → single side-effect.
9. Tax Tests
- Jurisdiction fixtures: US (per state), EU (VAT), Canada (GST/HST/PST), India (GST), UAE (VAT), UK (VAT post-Brexit).
- Digital goods tax rules per jurisdiction.
- Reverse-charge VAT for B2B EU.
10. PCI Tests
- No PAN in any log (CI grep for card patterns).
- Tokenization flow tested end-to-end.
- Annual PCI SAQ-A self-assessment.
11. Fraud Tests
- Simulated fraudulent patterns → flagged.
- 3DS challenge flow.
- Velocity limit triggers.
12. GDPR Tests
- Erasure saga: anonymize customer but retain billing records.
- Data export for subject access request.
13. Reconciliation Tests
- Inject drift between our ledger and Stripe mock → reconciliation detects.
- Monthly tax export fixtures.
14. CI Gates
- Unit + integration + contract green.
- Stripe mock flows green.
- OpenAPI + Pact verified.
- PCI scope test (no PAN in logs).
- Two-tenant iso green.
- Mutation ≥ 80%.