From e5f2b25f25d440d8e32640a980dcc96fa43fbb6b Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Mon, 20 Apr 2026 18:09:27 +0100 Subject: [PATCH] test: share openai speech fetch fixture --- extensions/openai/speech-provider.test.ts | 24 +++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/extensions/openai/speech-provider.test.ts b/extensions/openai/speech-provider.test.ts index 6d1b50b94f8..4efa3ac13e1 100644 --- a/extensions/openai/speech-provider.test.ts +++ b/extensions/openai/speech-provider.test.ts @@ -16,6 +16,16 @@ function parseRequestBody(init: RequestInit | undefined): { response_format?: st return body; } +function mockSpeechFetchExpectingFormat(responseFormat: string) { + const fetchMock = vi.fn(async (_url: string, init?: RequestInit) => { + const body = parseRequestBody(init); + expect(body.response_format).toBe(responseFormat); + return new Response(new Uint8Array([1, 2, 3]), { status: 200 }); + }); + globalThis.fetch = fetchMock as unknown as typeof fetch; + return fetchMock; +} + describe("buildOpenAISpeechProvider", () => { const originalFetch = globalThis.fetch; @@ -140,12 +150,7 @@ describe("buildOpenAISpeechProvider", () => { it("uses wav for Groq-compatible OpenAI TTS endpoints", async () => { const provider = buildOpenAISpeechProvider(); - const fetchMock = vi.fn(async (_url: string, init?: RequestInit) => { - const body = parseRequestBody(init); - expect(body.response_format).toBe("wav"); - return new Response(new Uint8Array([1, 2, 3]), { status: 200 }); - }); - globalThis.fetch = fetchMock as unknown as typeof fetch; + mockSpeechFetchExpectingFormat("wav"); const result = await provider.synthesize({ text: "hello", @@ -167,12 +172,7 @@ describe("buildOpenAISpeechProvider", () => { it("honors explicit responseFormat overrides and clears voice-note compatibility when not opus", async () => { const provider = buildOpenAISpeechProvider(); - const fetchMock = vi.fn(async (_url: string, init?: RequestInit) => { - const body = parseRequestBody(init); - expect(body.response_format).toBe("wav"); - return new Response(new Uint8Array([1, 2, 3]), { status: 200 }); - }); - globalThis.fetch = fetchMock as unknown as typeof fetch; + mockSpeechFetchExpectingFormat("wav"); const result = await provider.synthesize({ text: "hello",