Medication Service — Testing Strategy
Status: populated Owner: TBD Last updated: 2026-04-17 Companion: Service Template · Testing standards
1. Coverage Targets
| Layer | Coverage |
|---|---|
| Domain | ≥ 95% line + branch |
| Application | ≥ 90% |
| Infrastructure | ≥ 80% |
| Presentation | ≥ 80% |
| Overall | ≥ 85% |
2. Unit Tests
- Prescription state transitions (every legal / illegal pair).
Sigparsing and UCUM validation.- Drug-drug, drug-allergy, drug-condition, duplicate, dose-range rule functions.
- Counter-sign invariant (dispenser ≠ countersigner).
- Inventory invariant (
quantity_on_hand ≥ 0). - Override-reason length validator.
- MAR correction linkage.
- Reconciliation diff algorithm.
3. Integration Tests (mandatory)
| Test | Purpose |
|---|---|
tenant-isolation.spec.ts | Cross-tenant read/write blocked |
outbox.spec.ts | Event committed to outbox inside transaction |
inbox.spec.ts | Duplicate gateway event not double-processed |
dispense-atomicity.spec.ts | Inventory decrement rolls back on failure |
rls-controlled-substance.spec.ts | CS records only visible to licensed actors |
ncpdp-adapter.spec.ts (optional adapter) | Retry + DLQ behavior |
gateway-post-mr.spec.ts | Pact against ghasi-eprescribing-gateway-service |
4. Contract Tests
- Pact consumer tests against
ghasi-eprescribing-gateway-service(POST MedicationRequest / MedicationDispense). - Pact provider tests for: orders-service (MR event consumer), billing-service (dispense event consumer).
- Schema-registry conformance for every emitted event.
5. E2E Tests
| Scenario | Path |
|---|---|
| Prescribe → allergy alert → override → sign → dispense → MAR | e2e/allergy-override-happy-path.spec.ts |
| Controlled-substance prescribe → dispense → counter-sign | e2e/cs-dispense.spec.ts |
| Reconciliation on admission | e2e/reconciliation-admission.spec.ts |
| Offline pharmacy portal: dispense → sync | e2e/offline-pharmacy.spec.ts |
| Gateway MR ingested → fulfillment queue → dispense | e2e/gateway-ingest-dispense.spec.ts |
6. Performance Tests
- k6 script: sign at 50 rps sustained → verify p95 < 1500 ms.
- k6 dispense: 100 rps → verify inventory consistency via post-run audit query (no negative stock).
7. Chaos Tests
- Drug KB outage → verify safety-critical operations return 503, non-safety-critical queries continue with cached formulary.
- NATS partition during dispense → outbox retains event, delivery resumes.
- Postgres failover during dispense → idempotency-key prevents double-decrement on client retry.
8. Test Data
- Seeded tenants:
ten_demo_afg_01,ten_demo_uae_01. - RxNorm fixtures (150 common meds), allergy list, drug-drug interaction matrix from WHO EML.