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:
cliffhall 2026-07-08 16:43:41 -04:00
commit 98517c2758

View file

@ -131,19 +131,22 @@ describe("createRemoteOAuthPersistBackend", () => {
});
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({
baseUrl,
storeId,
fetchFn: ok as unknown as typeof fetch,
fetchFn: ok,
});
await backend.write(SNAPSHOT);
expect(ok).toHaveBeenCalledWith(
url,
expect.objectContaining({ method: "POST" }),
);
const body = ok.mock.calls[0][1].body;
expect(JSON.parse(body)).toEqual(SNAPSHOT);
expect(JSON.parse(capturedBody ?? "")).toEqual(SNAPSHOT);
const failing = createRemoteOAuthPersistBackend({
baseUrl,