fix(backend): restore real auth.js exports in test mocks so suites load#706
Merged
Conversation
PR #703 changed the auth.js mock in the five stream route test files to a plain factory that returns only requireAuth and requireAdmin. auth.js also exports issueChallenge, verifyChallenge and verifyJwt, which auth.routes wires up when the app is constructed. With those exports missing from the mock, importing src/app.js throws [vitest] No "issueChallenge" export is defined on the "auth.js" mock so all five suites fail to load and the Backend CI job goes red (5 failed suites, coverage step skipped). Use vi.mock with importOriginal to spread the module's real exports and override only requireAuth/requireAdmin. The app loads, the middleware is still stubbed, and the suites run. Verified: 36 suites / 184 tests pass; coverage 70.15% stmts, 66.73% branches, 72.34% funcs, 70.15% lines — all above the 60% gate.
This was referenced Jun 1, 2026
Closed
Closed
Open
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.
Why
mainis red again on the Backend CI job. PR #703 (swagger-docs-auth-tests) rewrote theauth.jsmock in the five stream route test files to a plain factory:auth.jsalso exportsissueChallenge,verifyChallengeandverifyJwt, whichauth.routeswires up when the app is constructed. With those exports missing from the mock, importingsrc/app.jsthrows:so all five suites fail to load — CI reports
5 failed | 31 passed, 146 tests run instead of 184, and the coverage step is skipped.Fix
Use
vi.mockwithimportOriginalto spread the module's real exports and override onlyrequireAuth/requireAdmin. The app loads, the middleware is still stubbed for the tests, and the suites run. (This is the pattern from #625; #703 replaced it with a comment claimingimportOriginalwas unreliable withpool: forks, but it runs fine here and in CI.)Affected files:
backend/tests/stream.test.tsbackend/tests/integration/streams.test.tsbackend/tests/integration/top-up.test.tsbackend/tests/integration/streams/withdraw.test.tsbackend/tests/integration/streams/cancel.test.tsVerification (local, against Postgres)
Test Files 36 passed (36)Tests 184 passed (184)Frontend and contracts jobs are unaffected (already green on this
main).