fix(backend): repair backend CI — auth mocks targeted the wrong module#625
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 thestreamsintegration 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-exportsauthMiddlewareas an alias. The routes importrequireAuthdirectly fromsrc/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.mockatsrc/middleware/auth.jsand overriderequireAuth, usingimportOriginalso 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)Frontend (lint/test/build) and contracts (95 tests, tarpaulin 98.76%) jobs remain green.