Skip to content

fix(backend): restore real auth.js exports in test mocks so suites load#706

Merged
ogazboiz merged 1 commit into
mainfrom
fix/main-ci-green-2
Jun 1, 2026
Merged

fix(backend): restore real auth.js exports in test mocks so suites load#706
ogazboiz merged 1 commit into
mainfrom
fix/main-ci-green-2

Conversation

@ogazboiz
Copy link
Copy Markdown
Contributor

@ogazboiz ogazboiz commented Jun 1, 2026

Why

main is red again on the Backend CI job. PR #703 (swagger-docs-auth-tests) rewrote the auth.js mock in the five stream route test files to a plain factory:

vi.mock('../src/middleware/auth.js', () => ({
  requireAuth: ...,
  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 "../src/middleware/auth.js" mock

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.mock with importOriginal to spread the module's real exports and override only requireAuth/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 claiming importOriginal was unreliable with pool: forks, but it runs fine here and in CI.)

Affected files:

  • backend/tests/stream.test.ts
  • backend/tests/integration/streams.test.ts
  • backend/tests/integration/top-up.test.ts
  • backend/tests/integration/streams/withdraw.test.ts
  • backend/tests/integration/streams/cancel.test.ts

Verification (local, against Postgres)

  • Test Files 36 passed (36)
  • Tests 184 passed (184)
  • Coverage: 70.15% stmts / 66.73% branches / 72.34% funcs / 70.15% lines — all above the 60% gate.

Frontend and contracts jobs are unaffected (already green on this main).

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.
@ogazboiz ogazboiz merged commit d60e2c2 into main Jun 1, 2026
9 checks passed
This was referenced Jun 1, 2026
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