Skip to content

test(etag): add test coverage for pairs-list ETag and 304 conditional… - #438

Merged
mikewheeleer merged 1 commit into
StableRoute-Org:mainfrom
Unclebaffa:test/caching-36-etag-pairs
Jul 26, 2026
Merged

test(etag): add test coverage for pairs-list ETag and 304 conditional…#438
mikewheeleer merged 1 commit into
StableRoute-Org:mainfrom
Unclebaffa:test/caching-36-etag-pairs

Conversation

@Unclebaffa

Copy link
Copy Markdown
Contributor

Summary of Changes

Added comprehensive test coverage for the GET /api/v1/pairs weak ETag and 304 Not Modified conditional response behavior in src/__tests__/etag.test.ts:

  1. Initial GET response:
    • Asserted that GET /api/v1/pairs returns status 200 with a weak ETag header (W/"...").
    • Asserted that the 200 body is valid JSON containing the pairs array.
  2. Conditional GET with matching If-None-Match:
    • Captured the weak ETag from the initial response header and reused it in a follow-up request with If-None-Match.
    • Asserted that the server returns 304 Not Modified with an empty body (text === "" and no JSON payload).
  3. GET without If-None-Match header:
    • Verified requests without If-None-Match return 200 with full body and ETag header.
  4. ETag invalidation on pair registration & unregistration:
    • Asserted that registering a pair updates the ETag and causes a request with a stale If-None-Match to return 200 with the new pair included.
    • Asserted that unregistering (deleting) a pair updates the ETag and causes a request with a stale If-None-Match to return 200 with the pair omitted.
  5. HEAD /api/v1/pairs coverage:
    • Asserted matching If-None-Match on HEAD returns 304 with empty body.
    • Asserted non-matching If-None-Match on HEAD returns 200 with empty body, Content-Length, Content-Type, and ETag headers matching GET.

Build and Test Verification

1. TypeScript Build (npm run build)

> stableroute-backend@0.1.0 build
> tsc

Build finished with 0 errors.

2. ESLint (npm run lint)

> stableroute-backend@0.1.0 lint
> eslint src

✖ 12 problems (0 errors, 12 warnings)

Lint finished with 0 errors.

3. Test Suite (npm test)

PASS src/__tests__/errorHandler.test.ts
PASS src/__tests__/durablePause.test.ts
PASS src/__tests__/apiKeyScopes.test.ts
PASS src/__tests__/config.test.ts
PASS src/__tests__/rateLimit.test.ts
PASS src/__tests__/pairsBulk.test.ts
PASS src/__tests__/metricsStoreGauges.test.ts
PASS src/__tests__/healthDeep.test.ts
PASS src/__tests__/webhooks.test.ts
PASS src/__tests__/server.test.ts
PASS src/__tests__/bulkQuote.test.ts
PASS src/__tests__/etag.test.ts
PASS src/__tests__/apiKeys.test.ts
PASS src/__tests__/events.test.ts
PASS src/__tests__/fallback404.test.ts
PASS src/__tests__/pauseGuard.test.ts
PASS src/__tests__/statsBreakdown.test.ts
PASS src/__tests__/auditLifecycle.test.ts
PASS src/__tests__/pairReadDelete.test.ts
PASS src/__tests__/persistence.test.ts
PASS src/__tests__/openapi-smoke.test.ts
PASS src/__tests__/stores.test.ts
PASS src/__tests__/index.test.ts
PASS src/__tests__/openapi.test.ts
PASS src/__tests__/cors.test.ts
PASS src/__tests__/pairsEtag.test.ts
PASS src/__tests__/parseAmountAssetCode.test.ts
PASS src/__tests__/readOnlyMode.test.ts
PASS src/__tests__/logger.test.ts
PASS src/__tests__/version.test.ts
PASS src/__tests__/utils.test.ts
PASS src/__tests__/pairMetaEnabled.test.ts
PASS src/__tests__/pricing.test.ts
PASS src/__tests__/securityHeaders.test.ts
PASS src/__tests__/store.adapter.test.ts

Test Suites: 35 passed, 35 total
Tests:       862 passed, 862 total
Snapshots:   0 total
Time:        19.826 s

4. Coverage Summary (npm run test:coverage)

File             | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s
-----------------|---------|----------|---------|---------|-------------------
All files        |   93.43 |    87.22 |   95.38 |   93.65 |
 src             |   93.04 |    86.67 |   95.19 |   93.33 |
  index.ts       |   90.97 |    84.59 |   94.48 |   91.41 | ...
  logger.ts      |     100 |      100 |     100 |     100 |
  openapi.ts     |     100 |      100 |     100 |     100 |
  pauseState.ts  |   96.15 |       90 |     100 |   95.65 |
  persistence.ts |   98.57 |    96.55 |     100 |     100 |
  pricing.ts     |     100 |      100 |     100 |     100 |
  server.ts      |   96.73 |    94.59 |   95.83 |   97.59 |
  stores.ts      |   97.15 |     90.9 |   94.11 |    96.7 |
 src/store       |   95.65 |    84.61 |      96 |   95.49 |
 src/utils       |     100 |      100 |     100 |     100 |
-----------------|---------|----------|---------|---------|-------------------
Test Suites: 35 passed, 35 total
Tests:       862 passed, 862 total

Closes #282

@mikewheeleer

Copy link
Copy Markdown
Contributor

solid — thanks for picking it up 🙌

@mikewheeleer
mikewheeleer merged commit 6562dbd into StableRoute-Org:main Jul 26, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add test coverage for the ETag/304 conditional GET on the pairs list

2 participants