Skip to main content

Facility Service — Testing Strategy

Status: populated Owner: TBD Last updated: 2026-04-17 Companion: TESTING_STANDARDS · DEFINITION_OF_DONE

1. Coverage targets

LayerTarget
Domain layer≥ 95 %
Application layer≥ 90 %
Infrastructure adapters≥ 80 %
Presentation≥ 80 %
Overall service≥ 80 % line, ≥ 70 % branch

2. Unit tests

AreaKey cases
HierarchyNode aggregatetype validation against profile, single-root rule, soft-delete only
HierarchyEdge aggregatecycle detection, self-loop rejection, allowed relationship
HierarchyProfilenon-retroactive profile updates, default uniqueness
Location aggregateanchored-node required, deactivation with/without force
Bed aggregatefull state-machine transitions, BR-FAC-001 conflict
Membership aggregateprimary uniqueness per provider
Value objectsbranded type construction, enum bounds

3. Integration tests

Mandatory per platform standard:

SpecPurpose
test/integration/tenant-isolation.spec.tsCross-tenant reads blocked by RLS
test/integration/outbox.spec.tsOutbox row → NATS publish
test/integration/inbox.spec.tsInbox deduplication on tenant.tenant.created.v1

Service-specific:

SpecPurpose
hierarchy-cycle.integration.spec.tsPostgres CTE cycle detection
subtree-query.integration.spec.tsDeep tree traversal correctness
context-cache.integration.spec.tsRedis cache hit/miss + invalidation
bed-concurrent-transition.integration.spec.tsSerializable conflict on status change
import-export.integration.spec.tsFull snapshot round-trip
fhir-location-projection.integration.spec.tsFHIR Location mapping

4. Contract tests

TypeToolWhat
Consumer-drivenPactContracts with scheduling-service, registration-service, billing-service, access-policy
Schema conformanceschema-registryEvents facility.* match registered JSON Schema
OpenAPISpectral + oatsPrevent breaking changes

5. E2E tests

FlowTool
Tenant onboarding seeds default profile + rootPlaywright + service harness
Ward admin creates ward → adds beds → status flows to OCCUPIED on admissionPlaywright
Deactivate location with occupied beds blocked, then admin force → auditPlaywright

6. Performance tests

ScenarioTarget
10k-node subtree fetch≤ 500 ms p95
Context lookup 1k rpsp99 ≤ 20 ms (cache hit)
Bed status update burst 500/sNo 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.