mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-13 11:10:43 +00:00
test: tighten image provider header assertions
This commit is contained in:
@@ -60,6 +60,17 @@ vi.mock("openclaw/plugin-sdk/provider-http", () => ({
|
||||
sanitizeConfiguredModelProviderRequest: sanitizeConfiguredModelProviderRequestMock,
|
||||
}));
|
||||
|
||||
function requireFirstRequestHeaders(mock: ReturnType<typeof vi.fn>): Headers {
|
||||
const request = mock.mock.calls[0]?.[0] as { headers?: Headers } | undefined;
|
||||
const headers = request?.headers;
|
||||
expect(request).toBeDefined();
|
||||
expect(headers).toBeInstanceOf(Headers);
|
||||
if (!headers) {
|
||||
throw new Error("expected request headers");
|
||||
}
|
||||
return headers;
|
||||
}
|
||||
|
||||
function createProvider(overrides: Partial<OpenAiCompatibleImageProviderOptions> = {}) {
|
||||
return createOpenAiCompatibleImageGenerationProvider({
|
||||
id: "sample",
|
||||
@@ -185,7 +196,7 @@ describe("OpenAI-compatible image provider helper", () => {
|
||||
},
|
||||
}),
|
||||
);
|
||||
const headers = postJsonRequestMock.mock.calls[0]?.[0].headers as Headers;
|
||||
const headers = requireFirstRequestHeaders(postJsonRequestMock);
|
||||
expect(headers.get("Content-Type")).toBe("application/json");
|
||||
expect(result).toMatchObject({
|
||||
model: "custom-image",
|
||||
@@ -212,7 +223,7 @@ describe("OpenAI-compatible image provider helper", () => {
|
||||
body: expect.any(FormData),
|
||||
}),
|
||||
);
|
||||
const headers = postMultipartRequestMock.mock.calls[0]?.[0].headers as Headers;
|
||||
const headers = requireFirstRequestHeaders(postMultipartRequestMock);
|
||||
expect(headers.has("Content-Type")).toBe(false);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user