Refs #5 Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QKHeGuAYh4W1jNdjMConZa
57 lines
2.3 KiB
TypeScript
57 lines
2.3 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
||
import { checkNotice, pickCheckAudio } from '../src/core/provider-check';
|
||
|
||
describe('pickCheckAudio', () => {
|
||
it('picks the last audio file by name directly in voice/source/', () => {
|
||
expect(
|
||
pickCheckAudio([
|
||
'voice/source/20260927-111503-0000.m4a',
|
||
'voice/source/20260927-120000-abcd.webm',
|
||
'voice/source/20260926-235959-ffff.ogg',
|
||
'voice/inbox/2026-09-27 15-00-00.md',
|
||
]),
|
||
).toEqual({ path: 'voice/source/20260927-120000-abcd.webm', mime: 'audio/webm' });
|
||
});
|
||
|
||
it('ignores .bin, unknown extensions, subfolders and look-alike folders', () => {
|
||
expect(
|
||
pickCheckAudio([
|
||
'voice/source/20260927-111503-0000.m4a',
|
||
'voice/source/20260928-000000-0000.bin',
|
||
'voice/source/20260928-000000-0001.mp3',
|
||
'voice/source/old/20260929-000000-0000.m4a',
|
||
'voice/sources/20260929-000000-0000.m4a',
|
||
'voice/source/noext',
|
||
]),
|
||
).toEqual({ path: 'voice/source/20260927-111503-0000.m4a', mime: 'audio/mp4' });
|
||
});
|
||
|
||
it('returns null when nothing fits', () => {
|
||
expect(pickCheckAudio([])).toBeNull();
|
||
expect(pickCheckAudio(['voice/source/a.bin', 'notes/x.m4a'])).toBeNull();
|
||
});
|
||
});
|
||
|
||
describe('checkNotice', () => {
|
||
it('shows the start of the text', () => {
|
||
expect(checkNotice({ ok: true, text: ' Привет, мир ' })).toBe('Провайдер работает: «Привет, мир»');
|
||
});
|
||
|
||
it('cuts long text to 100 chars with an ellipsis', () => {
|
||
expect(checkNotice({ ok: true, text: 'а'.repeat(150) })).toBe(`Провайдер работает: «${'а'.repeat(100)}…»`);
|
||
});
|
||
|
||
it('reports no speech for empty text', () => {
|
||
expect(checkNotice({ ok: true, text: ' ' })).toBe('Провайдер работает, но речь в записи не распознана');
|
||
});
|
||
|
||
it('shows kind and reason of an error', () => {
|
||
expect(checkNotice({ ok: false, kind: 'temporary', message: 'HTTP 429' })).toBe(
|
||
'Провайдер: временная ошибка — HTTP 429',
|
||
);
|
||
expect(checkNotice({ ok: false, kind: 'permanent', message: 'HTTP 401: Invalid API key' })).toBe(
|
||
'Провайдер: постоянная ошибка — HTTP 401: Invalid API key',
|
||
);
|
||
});
|
||
});
|