Files
Clintchiz 64ab20cc95
Quality / quality (ubuntu-latest) (push) Failing after 22s
Quality / quality (windows-latest) (push) Canceled after 0s
feat: add application productivity foundations
2026-08-23 11:13:03 +05:30

24 lines
759 B
TypeScript

import { expect, test } from "bun:test";
import { createApiClient } from "../src/index.ts";
test("typed API client expands params, query and JSON input", async () => {
let request: Request | undefined;
const call = createApiClient({
baseUrl: "https://app.test",
fetch: async (input, init) => {
request = new Request(input, init);
return Response.json({ ok: true });
},
});
expect(
await call<{ ok: boolean }, { name: string }>("/api/users/[id]", {
method: "PUT",
params: { id: 7 },
query: { audit: true },
body: { name: "Ada" },
}),
).toEqual({ ok: true });
expect(request?.url).toBe("https://app.test/api/users/7?audit=true");
expect(await request?.json()).toEqual({ name: "Ada" });
});