Skip to main content

Notification Service — Testing Strategy

Status: populated Owner: Platform Engineering + QA Last updated: 2026-04-18

1. Coverage Targets

LayerTargetTool
Domain aggregates + VOs95%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 pathsTestcontainers + 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 throws TemplateRenderError; 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 + SENT log entry → SUPPRESSED.

3. Integration Tests

  • test/integration/tenant-isolation.spec.ts — notification_log rows not visible across accounts.
  • test/integration/ingest-user-registered.spec.tsauth.user.registered.v1 → email dispatched via SendGrid mock → log=SENT.
  • test/integration/ingest-invoice-generated.spec.tsbilling.invoice.generated.v1 → email to all account.admin users → log=SENT.
  • test/integration/ingest-operator-down.spec.tsoperator.health DOWN event → email + SMS dispatched → logs=SENT.
  • test/integration/ingest-system-critical.spec.tssystem.alerts CRITICAL → opt-out ignored → delivered.
  • test/integration/dedup-delivery.spec.ts — same sourceEventId delivered 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-orchestrator Pact: 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 bodyHtml fields pass mjml --validate in CI.
  • variablesSchema validation test: template with all required variables renders; missing required variable throws.