obsidian-voice-note/tests/provider-check.test.ts
Andrey Epifancev 129e7c0b40 feat(core): provider check helpers — pick latest audio, format notice
Refs #5

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QKHeGuAYh4W1jNdjMConZa
2026-09-28 01:01:29 +04:00

57 lines
2.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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',
);
});
});