routing-engine — Testing Strategy
Status: populated | Last updated: 2026-04-18
1. Coverage Target
Minimum 80% line coverage enforced in CI.
2. Test Pyramid
2.1 Unit Tests
Framework: Jest + ts-jest
What to unit-test:
RoutingStrategyService: test COST, PRIORITY, FAILOVER strategy selection with mock candidate lists.PrefixMatchingService: longest-prefix match algorithm with edge cases (exact match, no match, overlapping prefixes).CacheKeyBuilder: key generation for all combinations of prefix/accountId/messageType.HealthEventHandler: Redis write logic, cache invalidation logic, NAK on Redis failure.- Input validation logic for
SelectOperatorRequest.
Key test cases:
describe('RoutingStrategyService', () => {
it('COST strategy selects operator with lowest cost', () => {});
it('PRIORITY strategy selects operator with lowest priority number', () => {});
it('FAILOVER strategy skips UNBOUND operators and picks first BOUND', () => {});
it('returns null when all candidates are UNBOUND', () => {});
});
describe('PrefixMatchingService', () => {
it('matches longest prefix for +447911123456', () => {});
it('returns null when no prefix matches', () => {});
it('prefers +4479 over +447 for +44791*', () => {});
});
2.2 Integration Tests
Framework: Jest + testcontainers (PostgreSQL, Redis)
Scope: Full SelectOperator handler with real DB and Redis containers.
What to integration-test:
- Full routing resolution from DB seed → cache write → cached response on second call.
- Cache invalidation when
operator.healthUNBOUND event is processed. /readyendpoint returns 503 when Redis or PostgreSQL is unavailable.- NATS health event consumer correctly updates Redis state.
Test data:
- Seed scripts in
test/fixtures/ops_routing.sql. - Cover: UK prefix (+44), Afghanistan prefix (+93/+9375), no-rule prefix.
2.3 Contract Tests (Consumer-Driven)
Framework: Pact (protobuf provider tests)
Scope: Verify that routing-engine satisfies the proto contract that sms-orchestrator depends on.
sms-orchestratorpublishes a Pact consumer contract forSelectOperator.routing-engineCI pipeline runs the provider verification step.- Pact Broker is deployed in the cluster CI environment.
2.4 Performance / Latency Tests
Framework: ghz (gRPC load testing tool) in CI smoke environment.
Acceptance criteria:
- 500 req/s sustained for 30 s → P95 latency ≤ 50 ms, 0 error responses.
- Run against a pre-seeded environment with 50 routing rules and 10 operators.
3. CI Pipeline Gates
| Stage | Tool | Pass criteria |
|---|---|---|
| Unit tests | Jest | All pass; ≥ 80% coverage |
| Integration tests | Jest + Testcontainers | All pass |
| Contract verification | Pact | Provider verification passes |
| Lint | ESLint | 0 errors |
| Type check | tsc --noEmit | 0 errors |
| Performance smoke | ghz | P95 ≤ 50 ms at 500 RPS |