import { HttpResponse, http } from "msw"; import { setupServer } from "msw/node"; import { afterAll, beforeAll, describe, expect, it } from "vitest"; import { createHttpClient } from "../../src/adapters/http/client.js"; import { createQueryCacheAdapter, createQueryClient, } from "../../src/adapters/query-cache/tanstack-query-cache.js"; import { queryKeys } from "../../src/contracts/query-keys.js"; import { createSampleFacade } from "../../src/sample/contract-fixture/sample-facade.js"; const server = setupServer( http.get("https://api.test/api/sample/resources", () => HttpResponse.json({ success: true, data: [{ id: "resource-1", name: "Example" }], meta: { requestId: "request-1", traceId: "trace-1" }, }), ), ); beforeAll(() => server.listen({ onUnhandledRequest: "error" })); afterAll(() => server.close()); describe("sample vertical contract fixture", () => { it("traverses API, schema, mapper, application facade, and cache", async () => { const queryClient = createQueryClient(); const cache = createQueryCacheAdapter(queryClient); const facade = createSampleFacade({ http: createHttpClient({ baseUrl: "https://api.test", clock: { now: () => 0, sleep: async () => {} }, }), cache, }); await expect(facade.listResources()).resolves.toEqual({ ok: true, value: [ { resourceId: "resource-1", title: "Example", createdAtLabel: null, }, ], }); expect(cache.read(queryKeys.resource.list({}))).toMatchObject({ ok: true, value: [{ id: "resource-1", displayName: "Example" }], }); }); });