From 62f2362a2e55b3db33a9965a7c47370e67b0c660 Mon Sep 17 00:00:00 2001 From: dmgnr Date: Sun, 4 Oct 2026 18:54:15 +0000 Subject: [PATCH] test: preserve caller User-Agent headers --- .gitignore | 2 ++ tests/lib/api.test.ts | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/.gitignore b/.gitignore index a14702c..acb51f7 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,5 @@ report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json # Finder (MacOS) folder config .DS_Store + +.codegraph \ No newline at end of file diff --git a/tests/lib/api.test.ts b/tests/lib/api.test.ts index 2b5f8e8..b8071a6 100644 --- a/tests/lib/api.test.ts +++ b/tests/lib/api.test.ts @@ -30,6 +30,7 @@ describe("authenticated API transport", () => { expect(new Headers(init?.headers).get("content-type")).toBe( "application/json", ); + expect(new Headers(init?.headers).has("user-agent")).toBe(false); expect(init?.body).toBe('{"name":"demo"}'); return Response.json({ id: "workspace-1" }); }, @@ -64,6 +65,19 @@ describe("authenticated API transport", () => { ).resolves.toBeUndefined(); }); + test("preserves a caller-provided User-Agent without adding one by default", async () => { + const sent: Array = []; + globalThis.fetch = mock(async (_input, init) => { + sent.push(new Headers(init?.headers).get("user-agent")); + return new Response(null, { status: 204 }); + }) as unknown as typeof fetch; + + const options = { authenticated: false, baseUrl: "https://api.test" }; + await apiRequest("/plain", {}, options); + await apiRequest("/custom", { headers: { "user-agent": "my-app" } }, options); + expect(sent).toEqual([null, "my-app"]); + }); + test("treats an empty successful JSON response as no content", async () => { globalThis.fetch = mock( async () => new Response("", { status: 200 }),