openreader/tests/unit/tts-settings-admin-view-model.spec.ts
Richard R 876ca7d774 feat(admin,config,ui,db): introduce runtime-editable site config and admin-managed TTS providers
Add database-backed runtime configuration for feature flags and TTS provider credentials, editable via a new admin UI panel. Replace static NEXT_PUBLIC_* and TTS provider env vars with admin-managed settings stored in the database and injected at SSR for client access. Implement admin-only panels for managing shared TTS provider credentials (with encrypted API keys) and live site feature flags. Add schema migrations, API routes, React contexts, and hooks for SSR-injected runtime config and live updates. Update client and server logic to resolve configuration from the database at runtime, enforcing admin restrictions and supporting migration from legacy env-based config.

BREAKING CHANGE: Feature flags and TTS provider credentials are now managed at runtime via the admin UI. Environment variables are only used for initial seeding and are ignored after first boot. Existing deployments must migrate configuration to the admin panel.
2026-05-12 22:39:24 -06:00

80 lines
2.5 KiB
TypeScript

import { expect, test } from '@playwright/test';
import { resolveTtsSettingsViewModel } from '../../src/lib/client/settings/tts-settings';
import type { SharedProviderEntry } from '../../src/hooks/useSharedProviders';
const SHARED: SharedProviderEntry[] = [
{
slug: 'shared-openai',
displayName: 'OpenAI Shared',
providerType: 'openai',
defaultModel: 'gpt-4o-mini-tts',
defaultInstructions: 'Default shared instructions',
},
{
slug: 'shared-replicate',
displayName: 'Replicate Shared',
providerType: 'replicate',
defaultModel: 'owner/model:ver',
defaultInstructions: null,
},
];
test.describe('resolveTtsSettingsViewModel (admin/shared modes)', () => {
test('restrict mode exposes only shared providers', () => {
const vm = resolveTtsSettingsViewModel({
provider: 'shared-openai',
modelValue: 'gpt-4o-mini-tts',
customModelInput: '',
showAllDeepInfra: false,
sharedProviders: SHARED,
allowBuiltInProviders: false,
});
expect(vm.providers.map((p) => p.id)).toEqual(['shared-openai', 'shared-replicate']);
expect(vm.providers.every((p) => p.shared)).toBe(true);
});
test('invalid provider falls back to first available option', () => {
const vm = resolveTtsSettingsViewModel({
provider: 'missing-provider',
modelValue: 'gpt-4o-mini-tts',
customModelInput: '',
showAllDeepInfra: false,
sharedProviders: SHARED,
allowBuiltInProviders: false,
});
expect(vm.selectedSharedProvider?.slug).toBe('shared-openai');
});
test('custom-model capable providers use custom mode for unknown model ids', () => {
const vm = resolveTtsSettingsViewModel({
provider: 'shared-replicate',
modelValue: 'my-custom-model',
customModelInput: '',
showAllDeepInfra: false,
sharedProviders: SHARED,
allowBuiltInProviders: false,
});
expect(vm.supportsCustomModel).toBe(true);
expect(vm.selectedModelId).toBe('custom');
expect(vm.canSubmit).toBe(false);
});
test('non-custom providers fall back to preset model selection', () => {
const vm = resolveTtsSettingsViewModel({
provider: 'shared-openai',
modelValue: 'not-in-presets',
customModelInput: '',
showAllDeepInfra: false,
sharedProviders: SHARED,
allowBuiltInProviders: false,
});
expect(vm.supportsCustomModel).toBe(false);
expect(vm.selectedModelId).not.toBe('custom');
expect(vm.models.length).toBeGreaterThan(0);
});
});