27 lines
941 B
TypeScript
27 lines
941 B
TypeScript
import { setupServer } from "msw/node";
|
|
import { afterAll, afterEach, beforeAll, expect, it, vi } from "vitest";
|
|
import { getHealthz } from "./endpoints/health/health";
|
|
import { getHealthMock } from "./endpoints/health/health.msw";
|
|
import { HealthResponse } from "./schemas";
|
|
|
|
const server = setupServer(...getHealthMock());
|
|
|
|
beforeAll(() => server.listen({ onUnhandledFrame: "error" }));
|
|
afterEach(() => {
|
|
vi.unstubAllGlobals();
|
|
server.resetHandlers();
|
|
});
|
|
afterAll(() => server.close());
|
|
|
|
it("serves the generated client through the generated MSW handler", async () => {
|
|
const interceptedFetch = globalThis.fetch;
|
|
// Node has no document origin for the browser client's relative URLs.
|
|
vi.stubGlobal("fetch", (input: string, init?: RequestInit) =>
|
|
interceptedFetch(new URL(input, "http://localhost"), init),
|
|
);
|
|
|
|
const response = await getHealthz();
|
|
|
|
expect(HealthResponse.parse(response)).toEqual({ status: "ok" });
|
|
});
|