Skip to main content

Immunizations 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)≥ 90%

2. Test Types

TypeFrameworkScope
UnitJestUse cases, forecast engine, domain model, value objects
IntegrationJest + Testcontainers (PostgreSQL)Repository adapters, outbox relay, RLS policies
Contract (consumer)PactEvents produced: immunization.recorded, forecast.updated; events consumed: patient.registered, patient.merged
API (E2E)SupertestREST endpoints against in-process NestJS app
Performancek6Forecast endpoint; record create endpoint

3. Mandatory Integration Tests

The following integration tests must pass before any release:

  1. tenant-isolation.integration.spec.ts — Verify that immunization records from tenant A are never accessible to tenant B under RLS.
  2. outbox.integration.spec.ts — Verify that recording an immunization writes to the outbox in the same transaction; outbox relay publishes to NATS exactly once.
  3. forecast-refresh.integration.spec.ts — Verify that after recording dose 1 of a multi-dose series, the forecast correctly advances the next due date and emits forecast.updated.

4. Scenario Coverage Matrix

ScenarioUnitIntegrationContract
Record administration — happy pathYesYesYes
Record refusal — happy pathYesYesYes
Contraindication blocks administrationYesYesNo
Contraindication override with reasonYesNoNo
Forecast computation — EPI schedule full seriesYesYesNo
Forecast after dose 1 of 3YesYesNo
Forecast after all doses completeYesNoNo
Forecast suppressed for deceased patientYesYesNo
Historical import triggers forecast refreshYesYesNo
Merge — immunization records reassignedNoYesNo
Defaulter query — overdue patientsYesYesNo
Coverage report — correct countYesYesNo
Digital certificate — valid JWT signatureYesNoNo
Registry sync — success pathNoYesNo
Registry sync — retry on failureNoYesNo
Tenant isolation (RLS)NoYesNo
Optimistic lock conflict on amendmentYesYesNo
Patient not found returns 404YesNoNo
Module not entitled returns 403YesNoNo

5. Contract Tests

EventRoleConsumer
IMMUNIZATIONS.immunization.recorded.v1Producercommunication-service, analytics-service
IMMUNIZATIONS.forecast.updated.v1Producercommunication-service
REGISTRATION.patient.registered.v1Consumerimmunizations-service
REGISTRATION.patient.merged.v1Consumerimmunizations-service

6. Performance Tests

ScenarioToolTarget
POST /v1/immunizations — 50 concurrent usersk6p95 < 500 ms
GET /v1/immunizations/forecast/:patientId — 100 concurrentk6p95 < 2 000 ms
GET /v1/immunizations/defaulters — 10 concurrentk6p95 < 1 000 ms