Skip to main content

Orders Service — Testing Strategy

Status: populated Owner: TBD Last updated: 2026-04-18 Companion: Service Template

1. Coverage Targets

ScopeTarget
Line coverage≥ 80%
Branch coverage≥ 75%
Domain layer (use cases, domain model, CDS guard)≥ 90%

2. Test Types

TypeFrameworkScope
UnitJestUse cases, CDS guard logic, state machine, value objects
IntegrationJest + Testcontainers (PostgreSQL)Repository adapters, outbox relay, RLS policies, allergy cache
Contract (consumer)PactEvents produced: order.activated, referral.created; events consumed: allergy.recorded, patient.vital-status-changed
API (E2E)SupertestREST endpoints against in-process NestJS app
Performancek6Order creation with CDS; order list query

3. Mandatory Integration Tests

  1. tenant-isolation.integration.spec.ts — Verify orders from tenant A are never accessible to tenant B under RLS.
  2. outbox.integration.spec.ts — Verify that order activation writes to outbox in same transaction; relay publishes to NATS at-least-once.
  3. cds-guard.integration.spec.ts — Verify CDS allergy check hard-stop blocks activation; warning requires acknowledgement; after acknowledgement, activation succeeds.

4. Scenario Coverage Matrix

ScenarioUnitIntegrationContract
Create medication order — happy pathYesYesYes
Create lab order — happy pathYesYesNo
Create referral — happy pathYesYesYes
CDS allergy hard-stop blocks activationYesYesNo
CDS warning acknowledged, order activatedYesYesNo
CDS duplicate order warningYesNoNo
CDS dosing range hard-stopYesNoNo
Order activated → event emittedYesYesYes
Order cancelled — activeYesYesNo
Order cancelled — draftYesNoNo
Order terminal state (cancel completed order)YesNoNo
Optimistic lock conflictYesYesNo
Idempotent create (duplicate clientMutationId)YesYesNo
Order set instantiation (2 orders)YesYesNo
Referral activated → referral.created eventYesYesYes
Patient deceased blocks order createYesYesNo
Allergy cache updated on eventNoYesNo
Batch order — partial failureYesYesNo
Tenant isolation (RLS)NoYesNo
Module not entitled returns 403YesNoNo
FHIR ServiceRequest readNoYesNo

5. Contract Tests

EventRoleConsumer
clinical.orders.order.activated.v1Producerpharmacy-service, laboratory-service, radiology-service
clinical.orders.referral.created.v1Producerscheduling-service, communication-service
REGISTRATION.allergy.recorded.v1Consumerorders-service
REGISTRATION.patient.vital-status-changed.v1Consumerorders-service

6. CDS-Specific Tests

The CDS guard must have comprehensive unit test coverage for:

  • Allergy check: confirmed allergy → hard-stop; intolerance → warning
  • Drug-drug interaction: contraindicated pair → hard-stop; monitored pair → warning
  • Duplicate order: same code within 24h → warning; different code → no alert
  • Dosing: above max dose → hard-stop; above recommended → warning; within range → no alert
  • Multiple simultaneous alerts: all captured; any hard-stop blocks activation

7. Performance Tests

ScenarioToolTarget
POST /v1/orders with CDS — 50 concurrentk6p95 < 800 ms
GET /v1/orders?patientId= — 100 concurrentk6p95 < 600 ms
POST /v1/order-sets/:id/instantiate (5-order set)k6p95 < 2 000 ms