Skip to main content

Medication Service — Testing Strategy

Status: populated Owner: TBD Last updated: 2026-04-17 Companion: Service Template · Testing standards

1. Coverage Targets

LayerCoverage
Domain≥ 95% line + branch
Application≥ 90%
Infrastructure≥ 80%
Presentation≥ 80%
Overall≥ 85%

2. Unit Tests

  • Prescription state transitions (every legal / illegal pair).
  • Sig parsing 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)

TestPurpose
tenant-isolation.spec.tsCross-tenant read/write blocked
outbox.spec.tsEvent committed to outbox inside transaction
inbox.spec.tsDuplicate gateway event not double-processed
dispense-atomicity.spec.tsInventory decrement rolls back on failure
rls-controlled-substance.spec.tsCS records only visible to licensed actors
ncpdp-adapter.spec.ts (optional adapter)Retry + DLQ behavior
gateway-post-mr.spec.tsPact 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

ScenarioPath
Prescribe → allergy alert → override → sign → dispense → MARe2e/allergy-override-happy-path.spec.ts
Controlled-substance prescribe → dispense → counter-signe2e/cs-dispense.spec.ts
Reconciliation on admissione2e/reconciliation-admission.spec.ts
Offline pharmacy portal: dispense → synce2e/offline-pharmacy.spec.ts
Gateway MR ingested → fulfillment queue → dispensee2e/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.