MCPcopy
hub / github.com/fccview/jotty / createMockRequest

Function createMockRequest

tests/api/setup.ts:116–141  ·  view source on GitHub ↗
(
  method: string,
  url: string,
  body?: any,
  headers: Record<string, string> = {},
)

Source from the content-addressed store, hash-verified

114}
115
116export 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
143export async function getResponseJson(response: Response) {
144 return response.json();

Callers 7

checklists.test.tsFile · 0.90
exports.test.tsFile · 0.90
items.test.tsFile · 0.90
notes.test.tsFile · 0.90
tasks.test.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected