test: dedupe vydra fetch mock calls

This commit is contained in:
Peter Steinberger
2026-05-12 15:26:45 +01:00
parent 646ef0c78f
commit 684e13c7fd

View File

@@ -8,6 +8,14 @@ import {
stubVydraApiKey,
} from "./provider-test-helpers.test.js";
function fetchCall(fetchMock: ReturnType<typeof vi.fn>, index = 0): [string, RequestInit] {
const call = fetchMock.mock.calls.at(index);
if (!call) {
throw new Error(`Expected fetch call ${index}`);
}
return call as [string, RequestInit];
}
describe("vydra image-generation provider", () => {
installPinnedHostnameTestHooks();
@@ -35,18 +43,16 @@ describe("vydra image-generation provider", () => {
cfg: {},
});
const createCall = fetchMock.mock.calls[0];
expect(createCall?.[0]).toBe("https://www.vydra.ai/api/v1/models/grok-imagine");
const createInit = createCall?.[1] as { method?: string; body?: unknown } | undefined;
expect(createInit?.method).toBe("POST");
expect(createInit?.body).toBe(
const createCall = fetchCall(fetchMock);
expect(createCall[0]).toBe("https://www.vydra.ai/api/v1/models/grok-imagine");
expect(createCall[1].method).toBe("POST");
expect(createCall[1].body).toBe(
JSON.stringify({
prompt: "draw a cat",
model: "text-to-image",
}),
);
const [, init] = fetchMock.mock.calls[0] as [string, RequestInit];
const headers = new Headers(init.headers);
const headers = new Headers(createCall[1].headers);
expect(headers.get("authorization")).toBe("Bearer vydra-test-key");
expect(result).toEqual({
images: [
@@ -93,10 +99,9 @@ describe("vydra image-generation provider", () => {
ssrfPolicy: { allowRfc2544BenchmarkRange: true },
});
const createCall = fetchMock.mock.calls[0];
expect(createCall?.[0]).toBe("https://198.18.0.10/api/v1/models/grok-imagine");
const createInit = createCall?.[1] as { method?: string } | undefined;
expect(createInit?.method).toBe("POST");
const createCall = fetchCall(fetchMock);
expect(createCall[0]).toBe("https://198.18.0.10/api/v1/models/grok-imagine");
expect(createCall[1].method).toBe("POST");
});
it("polls jobs when the create response is not completed yet", async () => {
@@ -119,9 +124,8 @@ describe("vydra image-generation provider", () => {
cfg: {},
});
const pollCall = fetchMock.mock.calls[1];
expect(pollCall?.[0]).toBe("https://www.vydra.ai/api/v1/jobs/job-456");
const pollInit = pollCall?.[1] as { method?: string } | undefined;
expect(pollInit?.method).toBe("GET");
const pollCall = fetchCall(fetchMock, 1);
expect(pollCall[0]).toBe("https://www.vydra.ai/api/v1/jobs/job-456");
expect(pollCall[1].method).toBe("GET");
});
});