MCPcopy Create free account
hub / github.com/simstudioai/sim / createMockNextRequest

Function createMockNextRequest

apps/sim/app/api/chat/[identifier]/route.test.ts:22–48  ·  view source on GitHub ↗

* Creates a mock NextRequest with cookies support for testing.

(
  method = 'GET',
  body?: unknown,
  headers: Record<string, string> = {},
  url = 'http://localhost:3000/api/test'
)

Source from the content-addressed store, hash-verified

20 * Creates a mock NextRequest with cookies support for testing.
21 */
22function 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
50const createMockStream = () => {
51 return new ReadableStream({

Callers 1

route.test.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected