Architecture

The suite uses two tiers:

Tier Target Purpose Run Command
Route-Layer Elysia().handle() in-process Validates schema, wiring, handler logic bun test or bun run test
Integration http://localhost:4000 (live proxy->backend) Real HTTP pipeline through privacy proxy to backend bun run test:integration

Route-layer tests use no network – they invoke Elysia handlers directly via app.handle(new Request(...)). They embed inline handler stubs that mirror the real route logic (validation, status codes, response shapes) without touching DB, Cosmos, or Pinata. Integration tests hit real containers and skip gracefully if they’re down.

A root bunfig.toml excludes **/integration/** from test discovery so bun test at root only runs route-layer tests. Integration tests must be run explicitly via bun run test:integration.

How to Run

# Run all route-layer tests (backend + privacy-proxy) from root
bun test

# Same, via package.json script
bun run test

# Run only backend route-layer tests
cd backend && bun test --path-ignore-patterns='**/integration/**'

# Run only privacy-proxy route-layer tests
cd privacy-proxy && bun test

# Run live integration tests (requires backend + proxy containers running)
bun run test:integration

Backend Route-Layer Tests (13 files, 138 tests)

1. backend/tests/Anonymous-submission.test.ts (13 tests)

Type: Route-layer, No mocks – uses inline Elysia handler stub

What it tests: POST /api/complaints/anonymous/submit schema validation and Cosmos config.

How it works: Builds an inline Elysia app with the same t.Object body schema as the real route. The handler generates a mock tracking code (SAWTAK-XXXX) and transaction ID. Tests send real Request objects through app.handle().

Validation tests (expect 422):

Success tests (expect 200):

Config tests (dynamic import()):


2. backend/tests/auth.routes.test.ts (8 tests)

Type: Route-layer, No mocks – inline Elysia handler stub

What it tests: Auth route validation for login, OAuth callbacks, and JWT verification.