test: add fetch mock helper and reaction coverage

This commit is contained in:
Sebastian
2026-02-17 09:01:30 -05:00
parent 0e023e300e
commit cc359d338e
28 changed files with 193 additions and 106 deletions

View File

@@ -1,4 +1,5 @@
import { describe, expect, it, vi } from "vitest";
import { withFetchPreconnect } from "../test-utils/fetch-mock.js";
import { fetchAntigravityUsage } from "./provider-usage.fetch.antigravity.js";
const makeResponse = (status: number, body: unknown): Response => {
@@ -12,10 +13,12 @@ const toRequestUrl = (input: Parameters<typeof fetch>[0]): string =>
const createAntigravityFetch = (
handler: (url: string, init?: Parameters<typeof fetch>[1]) => Promise<Response> | Response,
) =>
vi.fn(async (input: string | Request | URL, init?: RequestInit) =>
) => {
const mockFetch = vi.fn(async (input: string | Request | URL, init?: RequestInit) =>
handler(toRequestUrl(input), init),
);
return withFetchPreconnect(mockFetch) as typeof fetch & typeof mockFetch;
};
const getRequestBody = (init?: Parameters<typeof fetch>[1]) =>
typeof init?.body === "string" ? init.body : undefined;