Refs #5 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QKHeGuAYh4W1jNdjMConZa
44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { DEFAULT_OPENAI, readSettings } from '../src/core/openai';
|
|
|
|
describe('DEFAULT_OPENAI', () => {
|
|
it('points to AITUNNEL gpt-4o-transcribe with no key and auto language', () => {
|
|
expect(DEFAULT_OPENAI).toEqual({
|
|
baseUrl: 'https://api.aitunnel.ru/v1',
|
|
model: 'gpt-4o-transcribe',
|
|
apiKey: '',
|
|
language: '',
|
|
});
|
|
});
|
|
});
|
|
|
|
describe('readSettings', () => {
|
|
it.each([undefined, null, 'str', 42, []])('falls back to defaults for %j', (saved) => {
|
|
expect(readSettings(saved)).toEqual(DEFAULT_OPENAI);
|
|
});
|
|
|
|
it('overlays saved fields on defaults', () => {
|
|
expect(readSettings({ apiKey: 'sk-test-1' })).toEqual({ ...DEFAULT_OPENAI, apiKey: 'sk-test-1' });
|
|
});
|
|
|
|
it('trims all four fields', () => {
|
|
expect(
|
|
readSettings({ baseUrl: ' https://x/v1 ', model: ' m \n', apiKey: ' sk-test-1 \n', language: ' ru ' }),
|
|
).toEqual({ baseUrl: 'https://x/v1', model: 'm', apiKey: 'sk-test-1', language: 'ru' });
|
|
});
|
|
|
|
it('uses the default for a non-string field', () => {
|
|
expect(readSettings({ model: 5, apiKey: null })).toEqual(DEFAULT_OPENAI);
|
|
});
|
|
|
|
it('keeps an explicitly blanked baseUrl blank (precheck reports it)', () => {
|
|
expect(readSettings({ baseUrl: ' ' }).baseUrl).toBe('');
|
|
});
|
|
|
|
it('returns a fresh object', () => {
|
|
const s = readSettings(undefined);
|
|
s.apiKey = 'changed';
|
|
expect(DEFAULT_OPENAI.apiKey).toBe('');
|
|
});
|
|
});
|