@@ -118,16 +118,25 @@ describe("engine/utils/stt", () => {
|
118 | 118 | }); |
119 | 119 | |
120 | 120 | expect(transcript).toBe("hello from audio"); |
121 | | -expect(ssrfRuntimeMocks.fetchWithSsrFGuard).toHaveBeenCalledWith( |
122 | | -expect.objectContaining({ |
123 | | -url: "https://api.example.test/v1/audio/transcriptions", |
124 | | -auditContext: "qqbot-stt", |
125 | | -init: expect.objectContaining({ |
126 | | -method: "POST", |
127 | | -headers: { Authorization: "Bearer secret" }, |
128 | | -body: expect.any(FormData), |
129 | | -}), |
130 | | -}), |
| 121 | +expect(ssrfRuntimeMocks.fetchWithSsrFGuard).toHaveBeenCalledTimes(1); |
| 122 | +const request = ssrfRuntimeMocks.fetchWithSsrFGuard.mock.calls[0]?.[0] as { |
| 123 | +url?: unknown; |
| 124 | +auditContext?: unknown; |
| 125 | +init?: RequestInit; |
| 126 | +}; |
| 127 | +expect(request.url).toBe("https://api.example.test/v1/audio/transcriptions"); |
| 128 | +expect(request.auditContext).toBe("qqbot-stt"); |
| 129 | +expect(request.init?.method).toBe("POST"); |
| 130 | +expect(request.init?.headers).toEqual({ Authorization: "Bearer secret" }); |
| 131 | +expect(request.init?.body).toBeInstanceOf(FormData); |
| 132 | +const body = request.init?.body as FormData; |
| 133 | +expect(body.get("model")).toBe("whisper-1"); |
| 134 | +const file = body.get("file"); |
| 135 | +expect(file).toBeInstanceOf(File); |
| 136 | +expect((file as File).name).toBe("voice.wav"); |
| 137 | +expect((file as File).type).toBe("audio/wav"); |
| 138 | +expect(new Uint8Array(await (file as File).arrayBuffer())).toEqual( |
| 139 | +new Uint8Array([1, 2, 3, 4]), |
131 | 140 | ); |
132 | 141 | expect(release).toHaveBeenCalledTimes(1); |
133 | 142 | }); |
|