feat: add application productivity foundations
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
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" });
|
||||
});
|
||||
Reference in New Issue
Block a user