Communication Service — Testing Strategy
Status: populated Owner: TBD Last updated: 2026-04-17 Companion: Service Template · Testing standards
1. Coverage targets
| Layer | Statements | Branches |
|---|---|---|
| Domain | ≥ 95% | ≥ 90% |
| Application (use cases) | ≥ 90% | ≥ 85% |
| Infrastructure | ≥ 75% | ≥ 70% |
| Presentation | ≥ 80% | ≥ 75% |
| Service overall | ≥ 85% | ≥ 80% |
Aligned to NFR-DCOM-007.
2. Unit tests
- Domain: state machines (
MessageThread,VirtualSession), invariants (non-empty body, terminal-state rejection, participant-only writes), value objects (Urgency, Channel). - Use cases: mocked ports; validate orchestration including outbox writes and error mapping.
- Template renderer: golden tests per locale including RTL.
- No I/O in unit tests.
3. Integration tests (mandatory set)
| Test | File | Requirement |
|---|---|---|
| Tenant isolation | test/integration/tenant-isolation.spec.ts | Two tenants cannot read each other's threads / intents / sessions |
| Outbox pattern | test/integration/outbox.spec.ts | Message insert commits outbox row in same tx; relay publishes exactly-once |
| Inbox dedupe | test/integration/inbox.spec.ts | Re-delivered scheduling.appointment.created creates at most one virtual session |
| Idempotency | test/integration/idempotency.spec.ts | Same Idempotency-Key returns prior response |
| Thread RLS | test/integration/thread-rls.spec.ts | RLS prevents direct SQL cross-tenant leak |
| Virtual session lifecycle | test/integration/vs-lifecycle.spec.ts | End-to-end state machine including fallback |
4. Contract tests
| Contract | Counterparty | Framework |
|---|---|---|
/v1/communication/* OpenAPI | ehr-web, patient-mobile, clinician-mobile | OpenAPI diff + Pact |
ghasi.digital_communication.* event schemas | all consumers | JSON Schema conformance |
SmsProvider adapter | Ghasi-SMS-Gateway | Pact (consumer) |
PushNotificationProvider adapter | FCM / APNs | Adapter harness with sandbox |
EmailProvider adapter | SES / SendGrid | Adapter harness |
VirtualMeetingProvider | Jitsi | Contract test against Jitsi sandbox |
FHIR Communication write | interop-service | Pact |
5. E2E scenarios (Playwright / Detox)
| Scenario | Persona |
|---|---|
| Clinician sends provider-provider message | Physician |
| Clinician sends patient message + patient reads via portal | Physician + Patient |
| Scheduled virtual visit: patient joins waiting room, provider admits, session ends | Both |
| Virtual session fails mid-call → fallback thread auto-created | Provider |
| Appointment reminder via Ghasi-SMS-Gateway | Patient |
| Critical-result escalation fans out to push + SMS + in-app | Physician |
6. Load & chaos
- Load: 500 msg/s sustained, 2000 msg/s burst per tenant (test with K6).
- Chaos: SMS adapter latency injection; NATS reconnect storm; DLR flood; check SLOs hold.
7. Security / compliance tests
- PHI-never-in-push: dispatch unit tests assert no message body field in push payload.
- Cross-tenant participant rejection.
- Join-token reuse denied.
- Attachment virus simulation (EICAR) → quarantine + event.
8. Test data
- Fake providers registered via DI in
NODE_ENV=test. - Seed data: two tenants, 5 clinicians each, 20 patients each, 50 threads.