Skip to content

fix(backend): repair backend CI — auth mocks targeted the wrong module#625

Merged
ogazboiz merged 1 commit into
mainfrom
fix/backend-auth-mock-target-ci
Jun 1, 2026
Merged

fix(backend): repair backend CI — auth mocks targeted the wrong module#625
ogazboiz merged 1 commit into
mainfrom
fix/backend-auth-mock-target-ci

Conversation

@ogazboiz
Copy link
Copy Markdown
Contributor

@ogazboiz ogazboiz commented Jun 1, 2026

Problem

After the recent backend coverage tests were merged, the Backend CI job is red: 22 tests fail across stream, top-up, cancel, withdraw, and the streams integration suite. Every authenticated request returns 401 instead of the expected status.

Root cause

The route integration tests bypass auth by mocking src/middleware/auth.middleware.js, which only re-exports authMiddleware as an alias. The routes import requireAuth directly from src/middleware/auth.js, so the mock never intercepts anything and the real JWT middleware rejects the test requests.

Fix

Point each affected test's vi.mock at src/middleware/auth.js and override requireAuth, using importOriginal so the module's other exports (requireAdmin, issueChallenge, verifyChallenge, verifyJwt) stay intact for the rest of the app.

Test-only change — no production code touched.

Verification

Backend test suite locally against Postgres:

  • Test Files 36 passed (36)
  • Tests 184 passed (184)
  • Coverage: statements 69.94 / branches 67.02 / functions 72.34 / lines 69.94 — all above the 60% gate.

Frontend (lint/test/build) and contracts (95 tests, tarpaulin 98.76%) jobs remain green.

The stream route integration tests stubbed out authentication by mocking
src/middleware/auth.middleware.js (which only re-exports authMiddleware as
an alias). The routes import requireAuth directly from src/middleware/auth.js,
so the mock never took effect and every authenticated request returned 401,
failing 22 tests across stream/top-up/cancel/withdraw and the streams
integration suite.

Point each mock at src/middleware/auth.js and override requireAuth, using
importOriginal so the module's other exports (requireAdmin, issueChallenge,
verifyChallenge, verifyJwt) remain intact for the rest of the app.

No production code changes; test-only fix to restore a green backend CI job.
@ogazboiz ogazboiz merged commit f02a85d into main Jun 1, 2026
9 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.

1 participant