Files
ThothII/frontend/src/api/client.test.ts
T
marcopanandClaude Opus 4.8 acb674b4bc fix(frontend): only send JSON content-type when a body is present
Body-less POSTs (resume, close) sent content-type: application/json with no
body, so Fastify rejected them with FST_ERR_CTP_EMPTY_JSON_BODY (400) and
clicking an existing session never reopened it. apiFetch now adds the header
only when init.body is set.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-28 18:05:23 +02:00

28 lines
1.0 KiB
TypeScript

import { http, HttpResponse } from "msw";
import { server } from "../test/msw";
import { apiFetch } from "./client";
test("body-less POST omits content-type (avoids Fastify empty-body 400)", async () => {
let contentType: string | null = "unset";
server.use(
http.post("http://localhost:8787/sessions/s1/resume", ({ request }) => {
contentType = request.headers.get("content-type");
return HttpResponse.json({ id: "s1" });
}),
);
await apiFetch("/sessions/s1/resume", { method: "POST" });
expect(contentType).toBeNull();
});
test("POST with a body sends application/json content-type", async () => {
let contentType: string | null = null;
server.use(
http.post("http://localhost:8787/sessions/s1/steer", ({ request }) => {
contentType = request.headers.get("content-type");
return new HttpResponse(null, { status: 204 });
}),
);
await apiFetch("/sessions/s1/steer", { method: "POST", body: JSON.stringify({ text: "hi" }) });
expect(contentType).toContain("application/json");
});