71 lines
2.4 KiB
TypeScript
71 lines
2.4 KiB
TypeScript
process.env.DATABASE_PATH = ':memory:';
|
|
process.env.THEMES_DIR = './themes';
|
|
process.env.FRONTEND_DIST = './frontend/dist';
|
|
process.env.NODE_ENV = 'test';
|
|
|
|
import { AdminGeneralService } from '../../backend/src/modules/admin/general.service';
|
|
|
|
function makeFakeThemeLoader() {
|
|
return [
|
|
{ id: 'classic', name: 'Classic', tokens: {} as any },
|
|
{ id: 'midnight', name: 'Midnight', tokens: {} as any },
|
|
];
|
|
}
|
|
|
|
function makeService() {
|
|
const stored: Record<string, string> = {};
|
|
const fakeSettings = {
|
|
get: jest.fn().mockImplementation(async (k: string, d: string) => (k in stored ? stored[k] : d)),
|
|
set: jest.fn().mockImplementation(async (k: string, v: string) => { stored[k] = v; }),
|
|
} as any;
|
|
const fakeHub = { emitEvent: jest.fn() } as any;
|
|
const fakeThemes: any = { listThemes: () => makeFakeThemeLoader() };
|
|
const fakeConfig: any = { get: jest.fn().mockReturnValue('./themes') };
|
|
const svc = new AdminGeneralService(fakeSettings, fakeThemes, fakeHub, fakeConfig);
|
|
return { svc, fakeHub, fakeSettings };
|
|
}
|
|
|
|
describe('AdminGeneralService.updateSettings - general SSE payload (Job 892)', () => {
|
|
it('emits a general hub event carrying both themeKey and registrationsEnabled when registrations are enabled', async () => {
|
|
const { svc, fakeHub } = makeService();
|
|
await svc.updateSettings({
|
|
pageTitle: 'Hello',
|
|
logo: '',
|
|
welcomeMarkdown: '',
|
|
themeKey: 'midnight',
|
|
eventStartUtc: '2026-01-01T00:00:00Z',
|
|
eventEndUtc: '2026-02-01T00:00:00Z',
|
|
defaultChallengeIp: '127.0.0.1',
|
|
registrationsEnabled: true,
|
|
});
|
|
expect(fakeHub.emitEvent).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
topic: 'general',
|
|
themeKey: 'midnight',
|
|
registrationsEnabled: true,
|
|
}),
|
|
);
|
|
});
|
|
|
|
it('emits a general hub event with registrationsEnabled=false when the admin disables registrations', async () => {
|
|
const { svc, fakeHub } = makeService();
|
|
await svc.updateSettings({
|
|
pageTitle: 'Hello',
|
|
logo: '',
|
|
welcomeMarkdown: '',
|
|
themeKey: 'classic',
|
|
eventStartUtc: '2026-01-01T00:00:00Z',
|
|
eventEndUtc: '2026-02-01T00:00:00Z',
|
|
defaultChallengeIp: '127.0.0.1',
|
|
registrationsEnabled: false,
|
|
});
|
|
expect(fakeHub.emitEvent).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
topic: 'general',
|
|
themeKey: 'classic',
|
|
registrationsEnabled: false,
|
|
}),
|
|
);
|
|
});
|
|
});
|