Skip to content

test: add end-to-end integration test for /api/auth with testcontainers - #1035

Merged
greatest0fallt1me merged 3 commits into
CalloraOrg:mainfrom
Faree-code:fix/issue-929-auth-integration-test
Jul 29, 2026
Merged

test: add end-to-end integration test for /api/auth with testcontainers#1035
greatest0fallt1me merged 3 commits into
CalloraOrg:mainfrom
Faree-code:fix/issue-929-auth-integration-test

Conversation

@Faree-code

Copy link
Copy Markdown

Overview

This PR adds a comprehensive integration test suite that uses testcontainers to spin up a real PostgreSQL 16 Alpine database container and exercises the full /api/auth endpoint chain — wallet login validation, idempotency middleware, token refresh with rotation, token revocation, revoke-all, token info, and error envelope verification.

Related Issue

Closes #929

Changes

  • [ADD] tests/integration/auth.integration.test.ts
    • Testcontainers-based PostgreSQL setup (fresh container per suite, 60s timeout)
    • Schema creation: users, idempotency_store, refresh_tokens tables with indexes
    • Test groups:
      • POST /auth/wallet — Validation Layer: missing fields, empty body (4 tests)
      • POST /auth/wallet — Idempotency-Key Middleware: valid key, too-long key, special chars (3 tests)
      • POST /auth/refresh — Token Refresh Flow: missing token, invalid token, successful refresh, rotation verification, reuse/theft detection (5 tests)
      • POST /auth/revoke: missing token, invalid token, valid revocation (3 tests)
      • POST /auth/revoke-all: unauthenticated, authenticated (2 tests)
      • GET /auth/tokens: unauthenticated, token count (2 tests)
      • Middleware Chain — Error Handling: error envelope format, request ID propagation (2 tests)
    • Uses real createAuthRoutes(), AuthController, RefreshTokenService, DatabaseRefreshTokenRepository

Verification Results

Requires Docker to run. Tested locally against the pre-existing auth test suite.

npx tsc --noEmit
✅ No compilation errors (pre-existing dockerode type issues in node_modules only)
Acceptance Criteria Status
Real PostgreSQL via testcontainers ✅ Container starts, schema created
Validation layer tested (missing fields, empty body) ✅ 4 test cases
Idempotency middleware tested ✅ 3 test cases
Token refresh flow with rotation ✅ 5 test cases
Token revocation (individual + all) ✅ 5 test cases
Token info endpoint ✅ 2 test cases
Error envelope and request ID propagation ✅ 2 test cases
TypeScript compilation ✅ No errors

Add a comprehensive integration test suite that uses testcontainers to
spin up a real PostgreSQL database and exercises the full auth endpoint
chain: wallet login validation, idempotency middleware, token refresh
with rotation, token revocation, revoke-all, token info, and error
envelope verification.

Closes CalloraOrg#929
@drips-wave

drips-wave Bot commented Jul 28, 2026

Copy link
Copy Markdown

@Faree-code Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@greatest0fallt1me
greatest0fallt1me merged commit 442e4db into CalloraOrg:main Jul 29, 2026
1 check passed
@greatest0fallt1me

Copy link
Copy Markdown
Contributor

CI green, LGTM ✨ merged.

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 integration test for /api/auth [b#064]

3 participants