First Release of Claw3D (#11)

Co-authored-by: iamlukethedev <iamlukethedev@users.noreply.github.com>
This commit is contained in:
Luke The Dev
2026-03-19 23:14:04 -05:00
committed by GitHub
parent 5ea96b2650
commit 4fa4f13558
431 changed files with 105438 additions and 14 deletions
+39
View File
@@ -0,0 +1,39 @@
import { describe, expect, it, vi, afterEach } from "vitest";
import { fetchJson } from "@/lib/http";
type MockResponse = {
ok: boolean;
status: number;
text: () => Promise<string>;
};
const createResponse = (body: string, ok: boolean, status: number): MockResponse => ({
ok,
status,
text: vi.fn().mockResolvedValue(body),
});
describe("fetchJson", () => {
afterEach(() => {
vi.restoreAllMocks();
});
it("throws when response is not ok", async () => {
const fetchMock = vi.fn().mockResolvedValue(
createResponse(JSON.stringify({ error: "Nope" }), false, 400)
);
globalThis.fetch = fetchMock as unknown as typeof fetch;
await expect(fetchJson("/api/test")).rejects.toThrow("Nope");
});
it("returns parsed JSON for ok responses", async () => {
const fetchMock = vi.fn().mockResolvedValue(
createResponse(JSON.stringify({ ok: true }), true, 200)
);
globalThis.fetch = fetchMock as unknown as typeof fetch;
await expect(fetchJson("/api/test")).resolves.toEqual({ ok: true });
});
});