35 lines
1.4 KiB
TypeScript
35 lines
1.4 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import { HarnessApi } from "../src/api/harness-api.js";
|
|
|
|
afterEach(() => vi.unstubAllGlobals());
|
|
|
|
describe("HarnessApi request headers", () => {
|
|
it("does not claim an empty POST contains JSON", async () => {
|
|
const fetchMock = vi.fn().mockResolvedValue(new Response(JSON.stringify({
|
|
sessionId: "ses_1",
|
|
requestId: "req_1",
|
|
}), { status: 201, headers: { "Content-Type": "application/json" } }));
|
|
vi.stubGlobal("fetch", fetchMock);
|
|
|
|
await new HarnessApi().createSession();
|
|
|
|
const request = fetchMock.mock.calls[0]?.[1] as RequestInit;
|
|
expect(new Headers(request.headers).has("Content-Type")).toBe(false);
|
|
expect(request.body).toBeUndefined();
|
|
});
|
|
|
|
it("sets JSON content type when a structured body is present", async () => {
|
|
const fetchMock = vi.fn().mockResolvedValue(new Response(JSON.stringify({
|
|
runId: "run_1",
|
|
requestId: "req_1",
|
|
}), { status: 202, headers: { "Content-Type": "application/json" } }));
|
|
vi.stubGlobal("fetch", fetchMock);
|
|
|
|
await new HarnessApi().sendMessage("ses_1", { text: "hello", attachmentIds: [] });
|
|
|
|
const request = fetchMock.mock.calls[0]?.[1] as RequestInit;
|
|
expect(new Headers(request.headers).get("Content-Type")).toBe("application/json");
|
|
expect(request.body).toBe(JSON.stringify({ text: "hello", attachmentIds: [] }));
|
|
});
|
|
});
|