Skip to main content

Tenant Service — Testing Strategy

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

1. Coverage targets

TierTargetEnforced by
Unit≥ 80% statements + linesVitest --coverage in CI
IntegrationMandatory scenarios belowCI gate
Contract (Pact)All published + consumed eventsPact broker
E2ECritical tenant flowsPlaywright staging

2. Mandatory integration tests

2.1 Tenant isolation (test/integration/tenant-isolation.spec.ts)

ScenarioAssertion
Tenant A admin cannot read Tenant B hierarchy nodes403 / RLS blocks
Tenant A user cannot hold membership in Tenant B nodesRLS enforced
Cross-tenant evaluate() call rejected403 TENANT_CROSS_TENANT

2.2 Outbox (test/integration/outbox.spec.ts)

ScenarioAssertion
ActivateTenant writes tenant row and outbox row atomicallyDB transaction
Outbox relay publishes tenant.tenant.activated.v1 to NATSEvent received
Partial saga failure leaves tenant in PENDING; outbox not publishedCompensated state

2.3 Inbox (test/integration/inbox.spec.ts)

ScenarioAssertion
identity.user.registered.v1 consumed once (NATS redelivery)No duplicate profiles
identity.user.deactivated.v1 anonymizes profile idempotentlyIdempotent apply

2.4 Activation saga

ScenarioAssertion
All downstream steps succeed → tenant becomes ACTIVEStatus confirmed
Hierarchy call fails → retried 3 times → PENDING with alertBounded backoff
Idempotency token prevents duplicate activationSame token returns original result

2.5 RBAC/ABAC evaluate

ScenarioAssertion
CLINICIAN allowed patient_chart:read at member nodedecision: allow
CLINICIAN denied patient_chart:write at non-member nodedecision: deny
Built-in role cannot be deleted422 returned

3. Contract tests (Pact)

SubjectFile
tenant.tenant.activated.v1test/contract/tenant.activated.schema.spec.ts
tenant.tenant.suspended.v1test/contract/tenant.suspended.schema.spec.ts
tenant.role_assignment.created.v1test/contract/tenant.role.schema.spec.ts
identity-service consumertest/contract/identity-service.pact.spec.ts

4. E2E tests (staging)

ScenarioFile
Full onboarding: create → activate → create node → invite user → assign roletenant-onboarding.e2e.spec.ts
Suspend tenant → confirm identity session invalidation within TTLtenant-suspension.e2e.spec.ts
ABAC evaluate for clinical user at nodeabac-evaluate.e2e.spec.ts

5. Test data strategy

ConcernApproach
Tenant isolationEach suite creates isolated tenant via tenant_rls_bypass role
Downstream stubsWiremock stubs for identity-service and facility-service in integration
Idempotency testsUse fixed idempotency key per test; teardown between tests
Subscription expiryInject clock via ClockPort; freeze time to trigger expiry cron