mirror of
https://github.com/grp06/openclaw-studio.git
synced 2026-08-14 08:52:03 +00:00
- Introduced components.json for UI configuration with Tailwind and icon library settings. - Updated ESLint configuration to include Prettier for consistent code formatting. - Added Playwright and Vitest configurations for end-to-end and unit testing. - Implemented environment variable validation using Zod and added logging utilities. - Refactored API routes to improve error handling and logging. - Enhanced global styles and markdown rendering capabilities. - Established a new directory structure for better organization of features and components.
40 lines
1.0 KiB
TypeScript
40 lines
1.0 KiB
TypeScript
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 });
|
|
});
|
|
});
|