(
method: string,
url: string,
body?: any,
headers: Record<string, string> = {},
)
| 114 | } |
| 115 | |
| 116 | export function createMockRequest( |
| 117 | method: string, |
| 118 | url: string, |
| 119 | body?: any, |
| 120 | headers: Record<string, string> = {}, |
| 121 | ): NextRequest { |
| 122 | const requestHeaders = new Headers({ |
| 123 | "Content-Type": "application/json", |
| 124 | "x-api-key": "test-api-key", |
| 125 | ...headers, |
| 126 | }); |
| 127 | |
| 128 | const requestInit: RequestInit = { |
| 129 | method, |
| 130 | headers: requestHeaders, |
| 131 | }; |
| 132 | |
| 133 | if (body && (method === "POST" || method === "PUT" || method === "PATCH")) { |
| 134 | requestInit.body = JSON.stringify(body); |
| 135 | } |
| 136 | |
| 137 | return new NextRequest( |
| 138 | new URL(url, "http://localhost:3000"), |
| 139 | requestInit as any, |
| 140 | ); |
| 141 | } |
| 142 | |
| 143 | export async function getResponseJson(response: Response) { |
| 144 | return response.json(); |
no outgoing calls
no test coverage detected