process.env.DATABASE_PATH = ':memory:'; process.env.FRONTEND_DIST = './frontend/dist'; process.env.NODE_ENV = 'test'; import { AdminGeneralService } from '../../backend/src/modules/admin/general.service'; import { THEME_IDS } from '../../backend/src/common/types/theme-ids'; function makeFakeThemeLoader() { return THEME_IDS.map((id) => ({ id, name: id.charAt(0).toUpperCase() + id.slice(1), tokens: {} as any, })); } describe('AdminGeneralService.listThemes - default THEMES_DIR resolution (Job 894)', () => { const fakeSettings = { get: jest.fn(), set: jest.fn() } as any; const fakeHub = { emitEvent: jest.fn() } as any; const fakeThemes = { listThemes: () => makeFakeThemeLoader() } as any; const fakeConfig = { get: jest.fn().mockImplementation((key: string, fallback?: any) => fallback), } as any; it('returns all canonical themes when THEMES_DIR is left at its default', () => { const svc = new AdminGeneralService(fakeSettings, fakeThemes, fakeHub, fakeConfig); const themes = svc.listThemes(); expect(themes.length).toBe(THEME_IDS.length); const ids = themes.map((t) => t.id).sort(); expect(ids).toEqual([...THEME_IDS].sort()); }); it('maps every entry to { id, key, name } with id === key and a non-empty name', () => { const svc = new AdminGeneralService(fakeSettings, fakeThemes, fakeHub, fakeConfig); const themes = svc.listThemes(); for (const t of themes) { expect(t.id).toBe(t.key); expect(typeof t.name).toBe('string'); expect(t.name.length).toBeGreaterThan(0); } }); it('produces the same canonical entry list on repeated calls', () => { const svc = new AdminGeneralService(fakeSettings, fakeThemes, fakeHub, fakeConfig); const a = svc.listThemes().map((t) => t.id).sort(); const b = svc.listThemes().map((t) => t.id).sort(); expect(b).toEqual(a); expect(a.length).toBe(THEME_IDS.length); }); });