Files
TREK/server/tests/unit/nest/common/kernel-settings-helpers.test.ts
T
Maurice 806f3c8e62 refactor(addons): the transit-provider setting and photo-provider routes move into the shared kernel
AddonsService read the transit backend through transit/transit-provider.ts
and built photo-provider endpoint paths with memories.helpers, so the addons
domain, which nearly every domain imports for its gates, depended on
transit and memories. Both are free functions over a repository or plain
strings; they move unchanged to common/, where the transit and admin sides
read them too.
2026-10-10 20:15:59 +02:00

44 lines
1.9 KiB
TypeScript

import { describe, expect, it, vi } from 'vitest';
import type { AppSettingsRepository } from '../../../../src/db/repositories/AppSettings.repository';
import {
DEFAULT_TRANSIT_PROVIDER,
readTransitProvider,
TRANSIT_PROVIDER_SETTING,
writeTransitProvider,
} from '../../../../src/nest/common/transit-provider';
import { getPhotoProviderConfig } from '../../../../src/nest/common/photo-provider-config';
function settings(value: string | null) {
return { getValue: vi.fn(async () => value), setValue: vi.fn(async () => undefined) };
}
describe('transit provider setting', () => {
it('reads a known backend as stored', async () => {
const repo = settings('google');
expect(await readTransitProvider(repo as unknown as AppSettingsRepository)).toBe('google');
expect(repo.getValue).toHaveBeenCalledWith(TRANSIT_PROVIDER_SETTING);
});
it('falls back to Transitous for a missing row or a name this version does not know', async () => {
expect(await readTransitProvider(settings(null) as unknown as AppSettingsRepository)).toBe(DEFAULT_TRANSIT_PROVIDER);
expect(await readTransitProvider(settings('rail-x') as unknown as AppSettingsRepository)).toBe(DEFAULT_TRANSIT_PROVIDER);
});
it('writes the name under its one key and hands it back', async () => {
const repo = settings(null);
expect(await writeTransitProvider(repo as unknown as AppSettingsRepository, 'google')).toBe('google');
expect(repo.setValue).toHaveBeenCalledWith(TRANSIT_PROVIDER_SETTING, 'google');
});
});
describe('photo provider config', () => {
it('points every endpoint under the provider prefix', () => {
expect(getPhotoProviderConfig('immich')).toEqual({
settings_get: '/integrations/memories/immich/settings',
settings_put: '/integrations/memories/immich/settings',
status_get: '/integrations/memories/immich/status',
test_post: '/integrations/memories/immich/test',
});
});
});