AI Implementation feature(894): Admin Area General Settings and Categories 1.12 (#34)

This commit was merged in pull request #34.
This commit is contained in:
2026-07-22 17:34:55 +00:00
parent 56555d272f
commit 7bd0009b93
4 changed files with 143 additions and 38 deletions
@@ -0,0 +1,54 @@
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);
});
});