test: preserve caller User-Agent headers
This commit is contained in:
@@ -32,3 +32,5 @@ report.[0-9]_.[0-9]_.[0-9]_.[0-9]_.json
|
|||||||
|
|
||||||
# Finder (MacOS) folder config
|
# Finder (MacOS) folder config
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
|
.codegraph
|
||||||
@@ -30,6 +30,7 @@ describe("authenticated API transport", () => {
|
|||||||
expect(new Headers(init?.headers).get("content-type")).toBe(
|
expect(new Headers(init?.headers).get("content-type")).toBe(
|
||||||
"application/json",
|
"application/json",
|
||||||
);
|
);
|
||||||
|
expect(new Headers(init?.headers).has("user-agent")).toBe(false);
|
||||||
expect(init?.body).toBe('{"name":"demo"}');
|
expect(init?.body).toBe('{"name":"demo"}');
|
||||||
return Response.json({ id: "workspace-1" });
|
return Response.json({ id: "workspace-1" });
|
||||||
},
|
},
|
||||||
@@ -64,6 +65,19 @@ describe("authenticated API transport", () => {
|
|||||||
).resolves.toBeUndefined();
|
).resolves.toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("preserves a caller-provided User-Agent without adding one by default", async () => {
|
||||||
|
const sent: Array<string | null> = [];
|
||||||
|
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 () => {
|
test("treats an empty successful JSON response as no content", async () => {
|
||||||
globalThis.fetch = mock(
|
globalThis.fetch = mock(
|
||||||
async () => new Response("", { status: 200 }),
|
async () => new Response("", { status: 200 }),
|
||||||
|
|||||||
Reference in New Issue
Block a user