|
1 | 1 | import { describe, it, expect, vi, beforeEach } from 'vitest'; |
2 | 2 | import request from 'supertest'; |
3 | 3 |
|
4 | | -// Simple factory — no importOriginal — reliable with pool:forks. |
5 | | -vi.mock('../src/middleware/auth.js', () => ({ |
6 | | - requireAuth: (req: any, _res: any, next: any) => { |
7 | | - req.user = { publicKey: 'GTEST_USER_PUBLIC_KEY' }; |
8 | | - next(); |
9 | | - }, |
10 | | - requireAdmin: (_req: any, res: any, _next: any) => { |
11 | | - res.status(403).json({ error: 'Forbidden' }); |
12 | | - }, |
13 | | -})); |
| 4 | +// Preserve the module's real exports (issueChallenge, verifyChallenge, |
| 5 | +// verifyJwt) — auth.routes wires them up at app construction — while stubbing |
| 6 | +// only the middleware so requests bypass JWT verification. |
| 7 | +vi.mock('../src/middleware/auth.js', async (importOriginal) => { |
| 8 | + const actual = await importOriginal<typeof import('../src/middleware/auth.js')>(); |
| 9 | + return { |
| 10 | + ...actual, |
| 11 | + requireAuth: (req: any, _res: any, next: any) => { |
| 12 | + req.user = { publicKey: 'GTEST_USER_PUBLIC_KEY' }; |
| 13 | + next(); |
| 14 | + }, |
| 15 | + requireAdmin: (_req: any, res: any, _next: any) => { |
| 16 | + res.status(403).json({ error: 'Forbidden' }); |
| 17 | + }, |
| 18 | + }; |
| 19 | +}); |
14 | 20 |
|
15 | 21 | vi.mock('../src/middleware/stream-rate-limiter.middleware.js', () => ({ |
16 | 22 | streamCreationRateLimiter: (_req: any, _res: any, next: any) => next(), |
|
0 commit comments