test(auth): fix type error in remote backend write() test
`tsc -b` (run in CI's validate step, but not by vitest locally) rejected `ok.mock.calls[0][1].body` — under the project's strict indexing the untyped mock's call tuple is `[]`, so `[0]` is possibly-undefined and `[1]` is out of range. Capture the request body inside a `vi.fn<typeof fetch>` implementation instead of indexing into `mock.calls`. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
4c30dc6e2e
commit
98517c2758
1 changed files with 7 additions and 4 deletions
|
|
@ -131,19 +131,22 @@ describe("createRemoteOAuthPersistBackend", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("write() POSTs the serialized snapshot and throws on failure", async () => {
|
it("write() POSTs the serialized snapshot and throws on failure", async () => {
|
||||||
const ok = vi.fn(async () => new Response("", { status: 200 }));
|
let capturedBody: string | undefined;
|
||||||
|
const ok = vi.fn<typeof fetch>(async (_input, init) => {
|
||||||
|
capturedBody = init?.body as string | undefined;
|
||||||
|
return new Response("", { status: 200 });
|
||||||
|
});
|
||||||
const backend = createRemoteOAuthPersistBackend({
|
const backend = createRemoteOAuthPersistBackend({
|
||||||
baseUrl,
|
baseUrl,
|
||||||
storeId,
|
storeId,
|
||||||
fetchFn: ok as unknown as typeof fetch,
|
fetchFn: ok,
|
||||||
});
|
});
|
||||||
await backend.write(SNAPSHOT);
|
await backend.write(SNAPSHOT);
|
||||||
expect(ok).toHaveBeenCalledWith(
|
expect(ok).toHaveBeenCalledWith(
|
||||||
url,
|
url,
|
||||||
expect.objectContaining({ method: "POST" }),
|
expect.objectContaining({ method: "POST" }),
|
||||||
);
|
);
|
||||||
const body = ok.mock.calls[0][1].body;
|
expect(JSON.parse(capturedBody ?? "")).toEqual(SNAPSHOT);
|
||||||
expect(JSON.parse(body)).toEqual(SNAPSHOT);
|
|
||||||
|
|
||||||
const failing = createRemoteOAuthPersistBackend({
|
const failing = createRemoteOAuthPersistBackend({
|
||||||
baseUrl,
|
baseUrl,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue