mock-service — Local Third-Party Provider API Host

By Engineering Team•October 2, 2026•5 min read

Responsibility

mock-service is the local/dev HTTP stand-in for a third-party provider’s real API, so a consuming service can be exercised locally and in CI without real sandbox credentials, real network calls, or real account state. Shiprocket is the first provider mocked — built generically from the start so a second provider’s mock is a new flat <provider>.module.ts feature module, not a restructure.

  • One feature module per provider — shiprocket.module.ts today, mirroring the “one repository method per provider endpoint” doctrine (the platform’s layered architecture standard) applied to the serving side of a provider API instead of the calling side: one service file per endpoint, each with its own interface.
  • Scenario-selectable responses — an optional X-Mock-Scenario request header (resolved via a provider-agnostic resolveMockScenario() helper) selects an alternate canned fixture per endpoint (e.g. kyc-blocked/already-assigned on AWB assignment, not-found on label/invoice, already-scheduled on pickup, invalid-credentials on login, no-couriers on serviceability). Some scenarios are state-derived and fire without a header — a repeat AWB-assignment call for the same shipment_id automatically returns the already-assigned response.
  • Simulated asynchronous tracking webhooks — after a successful AWB assignment, a scheduled job advances that order through a status sequence (AWB ASSIGNED → PICKED UP → IN TRANSIT → OUT FOR DELIVERY → DELIVERED), POSTing a real-shaped webhook to the consuming service on each of the last four steps — the only way the simulated tracking flow is exercised locally; there is no on-demand “fire one webhook” endpoint.
  • Persists almost nothing beyond its own process lifetime — the one exception is the webhook-simulation state itself, which must survive across scheduler ticks.
  • No tenant-auth gate — reached directly over the Docker network in place of a real public third-party API, which has no X-Tenant-ID/X-User-Id/X-Role concept to simulate.

Tech Stack

Concern Choice
Language Node (NestJS)
Data store MongoDB — one collection, used only to back the webhook-simulation scheduler
Template @templates/node-mongo-microservice’s two-module shape, Symbol-token ports-and-adapters DI mirroring tenant-migration’s hardened pattern
Scheduling @nestjs/schedule’s @Interval(...) — the first scheduled/interval job among this monorepo’s Node services
Outbound HTTP node-lang-core-lib’s createHttpClient — never a hand-rolled HTTP client

Ports

Gateway HTTP (host → container) Service Name
— (reached directly over the Docker network by its consumer, never through cdn-edge/Nginx) 8096 → 8080 mock-service

Data Model — MongoDB

Collection Purpose
mock_shiprocket_webhook_event One record per order with an assigned AWB — tracks which status step the simulated webhook sequence has reached, so the scheduler can resume correctly across ticks. The sole persistence exception in this service.

Scenario Coverage — Shiprocket endpoints mocked today

Endpoint Scenarios
Auth login default success; invalid-credentials → 401
Order creation (adhoc) always succeeds — mirrors Shiprocket’s documented dummy-order-without-KYC allowance
Assign AWB default success; kyc-blocked → 400 KYC message; already-assigned (explicit or automatic repeat-call detection) → 400
Generate label default success; not-found → 400
Print invoice default success; not-found → 400
Generate pickup default success; already-scheduled → 400
Serviceability default success (2 couriers); no-couriers → empty array

Only these six endpoints — the ones shipment-service actually integrates — are mocked; the rest of Shiprocket’s documented API surface (bulk order import, order update/cancel, manifest, polling-based tracking, returns/RTO, wallet/billing) is out of scope for this service since nothing calls it.

Implementation Notes

  • This service’s own scheduler is coded as a 5-second interval, but the behavior actually observed in the running stack is a 30-second tick — a full simulated order reaches DELIVERED roughly 2 minutes after AWB assignment, not ~20 seconds. Treat the running behavior as authoritative when timing a local test of the tracking flow, not the interval value in source.
  • Routing a real Shiprocket call through this mock instead of the live API is a per-endpoint .env override on the consuming service’s side (shipment-service’s SHIPROCKET_*_BASE_URL vars, plus provider-auth-service’s seeded login-endpoint override) — this service itself has no feature flag or mode switch; it simply answers whatever base URL is pointed at it.
  • No file, directory, or flag name in this service may contain secret, token, or credential (case-insensitive) — enforced by a repo-wide pre-tool-use hook. This is why the bearer-issuance file is named for “bearer,” not “token,” even though the JSON response body it returns freely contains a token field.

Mocked for: shipment-service (all six integrated Shiprocket endpoints) and provider-auth-service (login). Fulfillment architecture overview: Architecture: Multi-Courier Fulfillment via Shiprocket. Why this service exists instead of calling Shiprocket’s live API in non-production environments: ADR-00023 — Internal Mock Service vs. Direct Live API for Non-Production Shiprocket Calls. Endpoint-level detail for every mocked call, including the exact simulated-webhook payload and schedule: Shiprocket Integration implementer reference series, particularly its Local Webhook Simulator page.