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
| Module | Test Case |
|---|---|
DlrStatusNormaliser | All 8 known SMPP stat values map correctly |
DlrStatusNormaliser | Unknown stat maps to UNKNOWN |
DlrStatusNormaliser | Case-insensitive input (delivrd → DELIVERED) |
InboundDlrEventSchema | Valid payload passes validation |
InboundDlrEventSchema | Missing operatorMessageId fails |
InboundDlrEventSchema | deliveredAt not ISO-8601 fails |
DeliveryReceiptRepository | Insert returns new receiptId |
DeliveryReceiptRepository | Duplicate operatorMessageId returns null (conflict) |
DlrProcessingService | Duplicate DLR short-circuits after idempotency check |
DlrProcessingService | Orphan path writes to orphaned_receipts and publishes sms.dlr.unmatched |
DlrProcessingService | Terminal status triggers billing + webhook outbox entries |
DlrProcessingService | UNKNOWN status triggers webhook but not billing |
OrchestratorUpdater | Does not overwrite already-terminal orch.sms_messages row |
3. Integration Tests
Framework: Jest + Testcontainers (PostgreSQL 15, NATS JetStream)
Scenarios
| Scenario | Steps |
|---|---|
| Happy path DELIVERED | Publish DLR event → assert delivery_receipts row, sms_messages update, outbox entries |
| Idempotent duplicate | Publish same DLR twice → assert single row in delivery_receipts |
| Orphan flow | Publish DLR with unknown operatorMessageId → assert orphaned_receipts row + sms.dlr.unmatched published |
| DB transaction rollback | Simulate NATS publish failure → assert no delivery_receipts row persisted |
| Consumer recovery | Stop 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.eventsreceived by mock billing consumer. - Verify
webhook.dispatchreceived by mock webhook consumer.
5. Contract Tests
Tool: Pact (consumer-driven contract testing).
| Contract | Consumer | Provider |
|---|---|---|
sms.dlr.inbound schema | dlr-processor | smpp-connector |
billing.events schema | billing-service | dlr-processor |
webhook.dispatch schema | webhook-dispatcher | dlr-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.