Files
browser/platform_web/api/client.env.test.ts
T
2026-07-11 14:56:10 +08:00

28 lines
895 B
TypeScript

import { afterEach, describe, expect, it, vi } from "vitest";
describe("platformApiClient runtime environment", () => {
afterEach(() => {
vi.restoreAllMocks();
vi.unstubAllEnvs();
vi.resetModules();
});
it("uses VITE_PLATFORM_API_BASE_URL for the shared client", async () => {
vi.stubEnv("VITE_PLATFORM_API_BASE_URL", "http://127.0.0.1:18080/api/v1");
vi.resetModules();
const fetchMock = vi.fn(async () =>
new Response(JSON.stringify({ items: [], count: 0 }), {
status: 200,
headers: { "Content-Type": "application/json" }
})
);
vi.stubGlobal("fetch", fetchMock);
const { platformApiClient } = await import("./client");
await expect(platformApiClient.listUsers()).resolves.toMatchObject({ count: 0 });
expect(fetchMock).toHaveBeenCalledWith("http://127.0.0.1:18080/api/v1/users", expect.any(Object));
});
});