54 lines
2.2 KiB
TypeScript
54 lines
2.2 KiB
TypeScript
process.env.DATABASE_PATH = ':memory:';
|
|
process.env.FRONTEND_DIST = './frontend/dist';
|
|
process.env.NODE_ENV = 'test';
|
|
// Intentionally do NOT set process.env.THEMES_DIR — this spec exercises the
|
|
// default path-resolution behaviour so the test fails if the default ever
|
|
// regresses to a CWD-relative path.
|
|
|
|
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;
|
|
// Mimic the production Nest ConfigService: .get('THEMES_DIR', './themes')
|
|
// returns the literal default string when no env override is present.
|
|
const fakeConfig = {
|
|
get: jest.fn().mockImplementation((key: string, fallback?: any) => fallback),
|
|
} as any;
|
|
|
|
it('returns all 10 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(10);
|
|
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 10-entry list on repeated calls (no I/O ordering surprises)', () => {
|
|
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(10);
|
|
});
|
|
}); |