* Creates a mock NextRequest with cookies support for testing.
(
method = 'GET',
body?: unknown,
headers: Record<string, string> = {},
url = 'http://localhost:3000/api/test'
)
| 20 | * Creates a mock NextRequest with cookies support for testing. |
| 21 | */ |
| 22 | function createMockNextRequest( |
| 23 | method = 'GET', |
| 24 | body?: unknown, |
| 25 | headers: Record<string, string> = {}, |
| 26 | url = 'http://localhost:3000/api/test' |
| 27 | ): any { |
| 28 | const headersObj = new Headers({ |
| 29 | 'Content-Type': 'application/json', |
| 30 | ...headers, |
| 31 | }) |
| 32 | |
| 33 | const parsedUrl = new URL(url) |
| 34 | |
| 35 | return { |
| 36 | method, |
| 37 | headers: headersObj, |
| 38 | nextUrl: parsedUrl, |
| 39 | cookies: { |
| 40 | get: vi.fn().mockReturnValue(undefined), |
| 41 | }, |
| 42 | json: |
| 43 | body !== undefined |
| 44 | ? vi.fn().mockResolvedValue(body) |
| 45 | : vi.fn().mockRejectedValue(new Error('No body')), |
| 46 | url, |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | const createMockStream = () => { |
| 51 | return new ReadableStream({ |