
























@@ -8,6 +8,14 @@ import {
88stubVydraApiKey,
99} from "./provider-test-helpers.test.js";
101011+function fetchCall(fetchMock: ReturnType<typeof vi.fn>, index = 0): [string, RequestInit] {
12+const call = fetchMock.mock.calls.at(index);
13+if (!call) {
14+throw new Error(`Expected fetch call ${index}`);
15+}
16+return call as [string, RequestInit];
17+}
18+1119describe("vydra image-generation provider", () => {
1220installPinnedHostnameTestHooks();
1321@@ -35,18 +43,16 @@ describe("vydra image-generation provider", () => {
3543cfg: {},
3644});
374538-const createCall = fetchMock.mock.calls[0];
39-expect(createCall?.[0]).toBe("https://www.vydra.ai/api/v1/models/grok-imagine");
40-const createInit = createCall?.[1] as { method?: string; body?: unknown } | undefined;
41-expect(createInit?.method).toBe("POST");
42-expect(createInit?.body).toBe(
46+const createCall = fetchCall(fetchMock);
47+expect(createCall[0]).toBe("https://www.vydra.ai/api/v1/models/grok-imagine");
48+expect(createCall[1].method).toBe("POST");
49+expect(createCall[1].body).toBe(
4350JSON.stringify({
4451prompt: "draw a cat",
4552model: "text-to-image",
4653}),
4754);
48-const [, init] = fetchMock.mock.calls[0] as [string, RequestInit];
49-const headers = new Headers(init.headers);
55+const headers = new Headers(createCall[1].headers);
5056expect(headers.get("authorization")).toBe("Bearer vydra-test-key");
5157expect(result).toEqual({
5258images: [
@@ -93,10 +99,9 @@ describe("vydra image-generation provider", () => {
9399ssrfPolicy: { allowRfc2544BenchmarkRange: true },
94100});
9510196-const createCall = fetchMock.mock.calls[0];
97-expect(createCall?.[0]).toBe("https://198.18.0.10/api/v1/models/grok-imagine");
98-const createInit = createCall?.[1] as { method?: string } | undefined;
99-expect(createInit?.method).toBe("POST");
102+const createCall = fetchCall(fetchMock);
103+expect(createCall[0]).toBe("https://198.18.0.10/api/v1/models/grok-imagine");
104+expect(createCall[1].method).toBe("POST");
100105});
101106102107it("polls jobs when the create response is not completed yet", async () => {
@@ -119,9 +124,8 @@ describe("vydra image-generation provider", () => {
119124cfg: {},
120125});
121126122-const pollCall = fetchMock.mock.calls[1];
123-expect(pollCall?.[0]).toBe("https://www.vydra.ai/api/v1/jobs/job-456");
124-const pollInit = pollCall?.[1] as { method?: string } | undefined;
125-expect(pollInit?.method).toBe("GET");
127+const pollCall = fetchCall(fetchMock, 1);
128+expect(pollCall[0]).toBe("https://www.vydra.ai/api/v1/jobs/job-456");
129+expect(pollCall[1].method).toBe("GET");
126130});
127131});
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。