| 22 | /** Records what the adapter put on the wire, so the assertions are about the |
| 23 | * request the server actually receives rather than the adapter's internals. */ |
| 24 | const recordingFetch = (respond: (url: string) => Response) => { |
| 25 | const calls: Array<{ url: string; body: unknown; headers: Record<string, string> }> = []; |
| 26 | const fetch: typeof globalThis.fetch = async (input, init) => { |
| 27 | const url = String(input); |
| 28 | calls.push({ |
| 29 | url, |
| 30 | body: typeof init?.body === "string" ? decodeRequestBody(init.body) : undefined, |
| 31 | headers: Object.fromEntries(new Headers(init?.headers).entries()), |
| 32 | }); |
| 33 | return respond(url); |
| 34 | }; |
| 35 | return { calls, fetch }; |
| 36 | }; |
| 37 | |
| 38 | const completed = () => |
| 39 | jsonResponse({ status: "completed", text: "ok", structured: {}, isError: false }); |