Skip to content

test(backend): add route-level integration tests for admin indexer endpoints (#847) - #1174

Open
jotel-dev wants to merge 4 commits into
LabsCrypt:mainfrom
jotel-dev:847-testing-admin-indexer-routes
Open

test(backend): add route-level integration tests for admin indexer endpoints (#847)#1174
jotel-dev wants to merge 4 commits into
LabsCrypt:mainfrom
jotel-dev:847-testing-admin-indexer-routes

Conversation

@jotel-dev

Copy link
Copy Markdown
Contributor

Description

Adds comprehensive route-level integration tests for the administrative indexer endpoints: GET /v1/admin/indexer/status, POST /v1/admin/indexer/reset, and POST /v1/admin/indexer/replay.

Previously, these operational endpoints lacked route-level test coverage in tests/integration/admin-metrics.test.ts. This left the requireAdmin authentication middleware, query/body parameter validation logic, status code outputs (200, 202, 400, 401, 403, 500), and downstream service function invocations unverified.

Type of Change

  • 🧪 Test addition or update

Related Issues

Closes #847

Changes Made

  • Middleware & Router Integration:
    • Updated admin-metrics.test.ts to use the actual requireAdmin middleware implementation instead of stubbing auth to a no-op handler.
    • Configured test JWT signing helpers (signJwt) and environment key setup (process.env.ADMIN_PUBLIC_KEY) to ensure end-to-end routing validation.
  • Route-Level Assertions:
    • GET /v1/admin/indexer/status:
      • Asserts 401 Unauthorized when no token is present and 403 Forbidden for non-admin tokens.
      • Asserts 200 OK and returned payload matching getIndexerStatus() for valid admin requests.
      • Asserts 500 Internal Server Error handling when getIndexerStatus() throws.
    • POST /v1/admin/indexer/reset:
      • Asserts 401 Unauthorized and 403 Forbidden auth enforcement.
      • Asserts 400 Bad Request with error message "ledger must be a non-negative integer" for missing body, negative integers (-1), floating-point values (12.34), or non-numeric strings ("not-a-number"), ensuring resetIndexer is not called.
      • Asserts 200 OK response { ok: true, lastLedger: expected } and verifies resetIndexer is called with parsed integer values (500, 0, '123').
      • Asserts 500 Internal Server Error handling when resetIndexer throws.
    • POST /v1/admin/indexer/replay:
      • Asserts 401 Unauthorized and 403 Forbidden auth enforcement.
      • Asserts 400 Bad Request with error message "from_ledger must be a non-negative integer" for missing from_ledger query parameter, negative values (-1, -50), floating-point numbers (3.14), or non-numeric strings ("invalid"), ensuring replayFromLedger is not called.
      • Asserts 202 Accepted response { ok: true, replayingFrom: expected } and verifies replayFromLedger is called with parsed integer values (200, 0).
      • Asserts 500 Internal Server Error handling when replayFromLedger throws.

Testing

Test Coverage

  • Integration tests added/updated

Test Steps

  1. Run the targeted admin route integration suite:
    npx vitest run backend/tests/integration/admin-metrics.test.ts
    

closes #847

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.

[Testing] Admin indexer routes /v1/admin/indexer/{status,reset,replay} have no route-level test

1 participant