Skip to main content

DLR Processor — Testing Strategy

Status: populated Owner: Platform Engineering Last updated: 2026-04-18 Companion: APPLICATION_LOGIC · FAILURE_MODES

1. Coverage Target

≥ 80% line coverage on all service-owned source files.

2. Unit Tests

Framework: Jest + ts-jest

Key Unit Test Cases

ModuleTest Case
DlrStatusNormaliserAll 8 known SMPP stat values map correctly
DlrStatusNormaliserUnknown stat maps to UNKNOWN
DlrStatusNormaliserCase-insensitive input (delivrdDELIVERED)
InboundDlrEventSchemaValid payload passes validation
InboundDlrEventSchemaMissing operatorMessageId fails
InboundDlrEventSchemadeliveredAt not ISO-8601 fails
DeliveryReceiptRepositoryInsert returns new receiptId
DeliveryReceiptRepositoryDuplicate operatorMessageId returns null (conflict)
DlrProcessingServiceDuplicate DLR short-circuits after idempotency check
DlrProcessingServiceOrphan path writes to orphaned_receipts and publishes sms.dlr.unmatched
DlrProcessingServiceTerminal status triggers billing + webhook outbox entries
DlrProcessingServiceUNKNOWN status triggers webhook but not billing
OrchestratorUpdaterDoes not overwrite already-terminal orch.sms_messages row

3. Integration Tests

Framework: Jest + Testcontainers (PostgreSQL 15, NATS JetStream)

Scenarios

ScenarioSteps
Happy path DELIVEREDPublish DLR event → assert delivery_receipts row, sms_messages update, outbox entries
Idempotent duplicatePublish same DLR twice → assert single row in delivery_receipts
Orphan flowPublish DLR with unknown operatorMessageId → assert orphaned_receipts row + sms.dlr.unmatched published
DB transaction rollbackSimulate NATS publish failure → assert no delivery_receipts row persisted
Consumer recoveryStop NATS → reconnect → assert pending messages processed

4. End-to-End Tests

Scope: Full platform smoke test (separate e2e test suite in repo root).

DLR Processor participation:

  • Send SMS via HTTP API → mock smpp-connector publishes DLR → assert orch.sms_messages.status = DELIVERED.
  • Verify billing.events received by mock billing consumer.
  • Verify webhook.dispatch received by mock webhook consumer.

5. Contract Tests

Tool: Pact (consumer-driven contract testing).

ContractConsumerProvider
sms.dlr.inbound schemadlr-processorsmpp-connector
billing.events schemabilling-servicedlr-processor
webhook.dispatch schemawebhook-dispatcherdlr-processor

Pact broker: internal Pact Broker instance. CI verifies contracts on every PR.

6. Performance Tests

Tool: k6 with NATS publisher scripts.

Target: 1 000 DLRs/second sustained for 60 seconds. Success criterion: p99 processing latency < 500 ms; error rate < 0.1%; no orphan leakage.

7. CI Pipeline

lint → unit tests → integration tests (Testcontainers) → contract tests → build image → trivy scan

E2E tests run post-deploy to staging environment.