Skip to content

test: add edge-case coverage for POST /api/auth/refresh - #748

Merged
Jambox11 merged 2 commits into
mux-labs:stagingfrom
Sundayabel222:staging
Aug 31, 2026
Merged

test: add edge-case coverage for POST /api/auth/refresh#748
Jambox11 merged 2 commits into
mux-labs:stagingfrom
Sundayabel222:staging

Conversation

@Sundayabel222

Copy link
Copy Markdown
Contributor

Closes #656
Closes #657
Closes #658
Closes #659

Summary

Expands the POST /api/auth/refresh route test suite from 7 → 15 tests, filling coverage gaps identified in the #745 audit. Also fixes the vitest coverage config so API route tests count toward reported numbers.

What changed

src/app/api/auth/refresh/route.test.ts — 8 new tests

Test Gap filled
sets secure flag on the session cookie when NODE_ENV=production Cookie secure: true in prod builds was untested
forwards the caller's cookie header to the upstream Caller's Cookie header reaching the backend wasn't verified
forwards upstream auth headers (x-api-key, x-api-secret) getUpstreamAuthHeaders() propagation was untested
forwards the request body to the upstream Body passthrough to backend wasn't verified
recognises the sessionToken key for cookie rotation extractSessionToken with sessionToken key wasn't tested
recognises the token key for cookie rotation extractSessionToken with token key wasn't tested
does not set a session cookie when the backend returns no token field No-token → no-cookie path was untested
returns 503 with a descriptive message Ensures error message is present in production 503 response

vitest.config.ts — coverage config fix

Added "src/app/api/**" to the default coverage.include list. Previously, route handler tests ran but didn't count toward reported coverage (only the separate vitest.coverage.full.config.ts included them).

Why

The refresh route is the production auth renewal path — src/lib/api.js and src/utils/fetchWithAuth.ts both call it on 401. Without edge-case coverage:

  • A regression in cookie secure flag could leak session tokens over HTTP in production
  • Missing upstream auth header forwarding would silently break backend authentication
  • The extractSessionToken key variants (token, accessToken, sessionToken) could silently stop rotating cookies
  • No-cookie-set when the backend omits a token field was an untested contract

Verification

```bash
pnpm vitest run src/app/api/auth/refresh/route.test.ts

✓ 15 tests passed

```

All 15 tests pass. The pre-existing logout route test failure (POST() missing a Request arg) is unrelated and exists on staging.

Related

🤖 Generated with Codebuff
Co-Authored-By: Codebuff noreply@codebuff.com

Sundayabel222 and others added 2 commits August 31, 2026 12:58
Expands the refresh-route test suite from 7 to 15 tests, covering gaps
identified during the mux-labs#745 audit:

- Cookie secure flag when NODE_ENV=production
- Caller's cookie header forwarded to upstream backend
- Upstream auth headers (x-api-key, x-api-secret) propagated
- Request body forwarded to backend
- extractSessionToken handling all three response keys (token,
  accessToken, sessionToken)
- No cookie set when backend response has no token field
- Descriptive error message present in 503 response

Also adds src/app/api/** to the default vitest coverage include list so
route handler tests count toward reported coverage numbers.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
…cases

test: add edge-case coverage for POST /api/auth/refresh
@drips-wave

drips-wave Bot commented Aug 31, 2026

Copy link
Copy Markdown

@Sundayabel222 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

@Jambox11
Jambox11 merged commit 6d112cd into mux-labs:staging Aug 31, 2026
1 of 4 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

2 participants