Facility Service — Testing Strategy
Status: populated Owner: TBD Last updated: 2026-04-17 Companion: TESTING_STANDARDS · DEFINITION_OF_DONE
1. Coverage targets
| Layer | Target |
|---|---|
| Domain layer | ≥ 95 % |
| Application layer | ≥ 90 % |
| Infrastructure adapters | ≥ 80 % |
| Presentation | ≥ 80 % |
| Overall service | ≥ 80 % line, ≥ 70 % branch |
2. Unit tests
| Area | Key cases |
|---|---|
| HierarchyNode aggregate | type validation against profile, single-root rule, soft-delete only |
| HierarchyEdge aggregate | cycle detection, self-loop rejection, allowed relationship |
| HierarchyProfile | non-retroactive profile updates, default uniqueness |
| Location aggregate | anchored-node required, deactivation with/without force |
| Bed aggregate | full state-machine transitions, BR-FAC-001 conflict |
| Membership aggregate | primary uniqueness per provider |
| Value objects | branded type construction, enum bounds |
3. Integration tests
Mandatory per platform standard:
| Spec | Purpose |
|---|---|
test/integration/tenant-isolation.spec.ts | Cross-tenant reads blocked by RLS |
test/integration/outbox.spec.ts | Outbox row → NATS publish |
test/integration/inbox.spec.ts | Inbox deduplication on tenant.tenant.created.v1 |
Service-specific:
| Spec | Purpose |
|---|---|
hierarchy-cycle.integration.spec.ts | Postgres CTE cycle detection |
subtree-query.integration.spec.ts | Deep tree traversal correctness |
context-cache.integration.spec.ts | Redis cache hit/miss + invalidation |
bed-concurrent-transition.integration.spec.ts | Serializable conflict on status change |
import-export.integration.spec.ts | Full snapshot round-trip |
fhir-location-projection.integration.spec.ts | FHIR Location mapping |
4. Contract tests
| Type | Tool | What |
|---|---|---|
| Consumer-driven | Pact | Contracts with scheduling-service, registration-service, billing-service, access-policy |
| Schema conformance | schema-registry | Events facility.* match registered JSON Schema |
| OpenAPI | Spectral + oats | Prevent breaking changes |
5. E2E tests
| Flow | Tool |
|---|---|
| Tenant onboarding seeds default profile + root | Playwright + service harness |
| Ward admin creates ward → adds beds → status flows to OCCUPIED on admission | Playwright |
| Deactivate location with occupied beds blocked, then admin force → audit | Playwright |
6. Performance tests
| Scenario | Target |
|---|---|
| 10k-node subtree fetch | ≤ 500 ms p95 |
| Context lookup 1k rps | p99 ≤ 20 ms (cache hit) |
| Bed status update burst 500/s | No outbox backlog > 2s |
7. Security tests
- Postgres RLS active on every tenant-scoped table (assert via role-scoped query).
- No endpoint returns cross-tenant data (property-based with 100 tenants).
- Import endpoint enforces size cap and JSON schema.
- Guard ordering: license gate → access-policy → handler.