mirror of
https://github.com/FJurmanovic/sugarr.git
synced 2026-11-11 15:51:09 +00:00
Add app config schema and shared models
This commit is contained in:
45
test/app/config/AppConfig.test.ts
Normal file
45
test/app/config/AppConfig.test.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { loadAppConfig } from '../../../src/app/config/AppConfig';
|
||||
|
||||
const REQUIRED_ENV = {
|
||||
JELLYFIN_URL: 'http://jellyfin',
|
||||
JELLYFIN_API_KEY: 'jf-key',
|
||||
JELLYFIN_USER_ID: 'user-1',
|
||||
TMDB_API_KEY: 'tmdb-key',
|
||||
LANGFUSE_PUBLIC_KEY: 'lf-pub',
|
||||
LANGFUSE_SECRET_KEY: 'lf-secret',
|
||||
LANGFUSE_BASE_URL: 'http://langfuse',
|
||||
};
|
||||
|
||||
describe('loadAppConfig', () => {
|
||||
it('applies defaults for optional settings', () => {
|
||||
const config = loadAppConfig(REQUIRED_ENV);
|
||||
expect(config.LLM_ENABLED).toBe(false);
|
||||
expect(config.RADARR_ENABLED).toBe(false);
|
||||
expect(config.API_PORT).toBe(8080);
|
||||
expect(config.RECOMMEND_COUNT).toBe(10);
|
||||
expect(config.MIN_RATED_MOVIES).toBe(5);
|
||||
expect(config.LANGFUSE_PROMPT_CACHE_ENABLED).toBe(true);
|
||||
});
|
||||
|
||||
it('parses boolean and numeric overrides from env strings', () => {
|
||||
const config = loadAppConfig({
|
||||
...REQUIRED_ENV,
|
||||
LLM_ENABLED: 'true',
|
||||
RADARR_ENABLED: 'true',
|
||||
API_PORT: '9090',
|
||||
RECOMMEND_COUNT: '20',
|
||||
LANGFUSE_PROMPT_CACHE_ENABLED: 'false',
|
||||
});
|
||||
expect(config.LLM_ENABLED).toBe(true);
|
||||
expect(config.RADARR_ENABLED).toBe(true);
|
||||
expect(config.API_PORT).toBe(9090);
|
||||
expect(config.RECOMMEND_COUNT).toBe(20);
|
||||
expect(config.LANGFUSE_PROMPT_CACHE_ENABLED).toBe(false);
|
||||
});
|
||||
|
||||
it('throws when a required var is missing', () => {
|
||||
const { JELLYFIN_URL, ...rest } = REQUIRED_ENV;
|
||||
expect(() => loadAppConfig(rest)).toThrow(/Invalid environment configuration/);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user