feat: integrate learning module
This commit is contained in:
32
tests/unit/learning-speech-client.test.ts
Normal file
32
tests/unit/learning-speech-client.test.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { createLearningSpeechClient } from '@electron/services/learning-speech-client';
|
||||
|
||||
describe('Learning speech client', () => {
|
||||
it('keeps authentication in Main and forwards bounded multipart audio', async () => {
|
||||
const fetchImpl = vi.fn<typeof fetch>().mockResolvedValue(new Response(
|
||||
JSON.stringify({ text: '什么是变量', model: 'stt' }),
|
||||
{ status: 200, headers: { 'Content-Type': 'application/json' } },
|
||||
));
|
||||
const client = createLearningSpeechClient({
|
||||
fetchImpl,
|
||||
getAccessToken: vi.fn().mockResolvedValue('main-owned-token'),
|
||||
apiBaseUrl: 'https://square.example',
|
||||
});
|
||||
|
||||
await expect(client.transcribe({
|
||||
audio: new Uint8Array([1, 2, 3]),
|
||||
fileName: 'voice.webm',
|
||||
mimeType: 'audio/webm',
|
||||
language: 'zh-CN',
|
||||
})).resolves.toEqual({ text: '什么是变量' });
|
||||
|
||||
const [url, init] = fetchImpl.mock.calls[0];
|
||||
expect(url).toBe('https://square.example/api/speech/transcriptions');
|
||||
expect(init?.headers).toEqual({ Authorization: 'Bearer main-owned-token' });
|
||||
const form = init?.body as FormData;
|
||||
expect(form.get('language')).toBe('zh-CN');
|
||||
const file = form.get('audio') as File;
|
||||
expect(file.name).toBe('voice.webm');
|
||||
expect(new Uint8Array(await file.arrayBuffer())).toEqual(new Uint8Array([1, 2, 3]));
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user