translation-terrace/app/lib/__tests__/settings.spec.tsx
2025-03-02 20:15:27 -08:00

85 lines
2.6 KiB
TypeScript

import { Settings } from '@/app/lib/settings';
import { getDb } from '@/app/lib/db';
import { Knex } from 'knex';
describe('Settings', () => {
let settings : Settings;
let db : Knex;
beforeEach(async () => {
db = await getDb("development");
settings = new Settings(db)
});
afterEach(async () => {
await db.migrate.down();
});
it('should set the host language in the database', async () => {
const value = 'en';
await settings.setHostLanguage(value);
const result = await settings.getHostLanguage();
expect(result).toEqual(value);
});
describe('getHostLanguage', () => {
it('should return the host language from the database', async () => {
const value = 'fr';
await settings.setHostLanguage(value);
const result = await settings.getHostLanguage();
expect(result).toEqual(value);
});
it('should return null if the host language is not set', async () => {
const result = await settings.getHostLanguage();
expect(result).toBeUndefined();
});
});
describe('setLibretranslateBaseUrl', () => {
it('should set the LibreTranslate base URL in the database', async () => {
const value = 'https://example.com';
await settings.setLibretranslateBaseUrl(value);
const result = await settings.getLibretranslateBaseUrl();
expect(result).toEqual(value);
});
});
describe('getLibretranslateBaseUrl', () => {
it('should return null if the LibreTranslate base URL is not set', async () => {
const result = await settings.getLibretranslateBaseUrl();
expect(result).toBeUndefined();
});
});
describe('setWhisperModel', () => {
it('should set the Whisper model in the database', async () => {
const value = 'base';
await settings.setWhisperModel(value);
const result = await settings.getWhisperModel();
expect(result).toEqual(value);
});
});
describe('setWhisperModel', () => {
it('should set the Whisper model in the database', async () => {
const value = 'base';
await settings.setWhisperModel(value);
const result = await settings.getWhisperModel();
expect(result).toEqual(value);
});
});
describe('getWhisperModel', () => {
it('should return null if the Whisper model is not set', async () => {
const result = await settings.getWhisperModel();
expect(result).toBeUndefined();
});
});
});