Notification Service — Testing Strategy
Status: populated Owner: Platform Engineering + QA Last updated: 2026-04-18
1. Coverage Targets
| Layer | Target | Tool |
|---|---|---|
| Domain aggregates + VOs | 95% | Vitest |
| Domain services (PreferenceResolver, TemplateRenderer) | 90% | Vitest |
| Application use cases (all 6 notification types) | 90% (branch) | Vitest |
| Integration (NATS consumer + PG + mock SendGrid) | All critical paths | Testcontainers + nock |
| Mutation on domain | ≥ 75% | Stryker |
2. Unit Tests
PreferenceResolver: opted-out returns suppressed; SYSTEM_SECURITY always delivers; missing preference row defaults to opted-in.TemplateRenderer: valid Handlebars + Mjml renders correctly; missing required variable throwsTemplateRenderError; plain-text fallback returned on Mjml error.NotificationDispatcher: happy path (SENT); opt-out path (SUPPRESSED); delivery failure after 3 retries (FAILED + log).- Dedup logic: second dispatch with same
sourceEventId+SENTlog entry → SUPPRESSED.
3. Integration Tests
test/integration/tenant-isolation.spec.ts— notification_log rows not visible across accounts.test/integration/ingest-user-registered.spec.ts—auth.user.registered.v1→ email dispatched via SendGrid mock → log=SENT.test/integration/ingest-invoice-generated.spec.ts—billing.invoice.generated.v1→ email to all account.admin users → log=SENT.test/integration/ingest-operator-down.spec.ts—operator.healthDOWN event → email + SMS dispatched → logs=SENT.test/integration/ingest-system-critical.spec.ts—system.alertsCRITICAL → opt-out ignored → delivered.test/integration/dedup-delivery.spec.ts— samesourceEventIddelivered twice → second delivery SUPPRESSED.test/integration/opt-out.spec.ts— OPERATOR_ALERT opt-out set → notification SUPPRESSED.test/integration/template-missing.spec.ts— no active template for event type → log=FAILED, alert emitted.test/integration/template-crud.spec.ts— create/update template via internal endpoint; verify active version changes; verify old version retained.
4. Contract Tests
- Schema conformance for all 4 consumed event types against schema registry.
sms-orchestratorPact: SMS delivery POST request shape matches sms-orchestrator API contract.
5. E2E
test/e2e/invoice-notification.e2e.spec.ts: billing-service stub → NATS → notification-service → SendGrid mock → notification_log=SENT.test/e2e/operator-alert.e2e.spec.ts: operator.health NATS event → email + SMS dispatched → both logs=SENT.
6. Template Quality Tests
- Snapshot test: rendered HTML for each default template compared against stored snapshot; CI fails on unintentional template change.
- Mjml lint: all
bodyHtmlfields passmjml --validatein CI. variablesSchemavalidation test: template with all required variables renders; missing required variable throws.