feat: Admin Area General Settings and Categories 1.09
This commit is contained in:
@@ -161,6 +161,65 @@ describe('GeneralSettingsSchema - validation rules', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('GeneralSettingsSchema - defaultChallengeIp (Job 891)', () => {
|
||||
const base = {
|
||||
pageTitle: 'T',
|
||||
logo: '',
|
||||
welcomeMarkdown: '',
|
||||
themeKey: 'classic',
|
||||
eventStartUtc: '2026-01-01T00:00:00Z',
|
||||
eventEndUtc: '2026-02-01T00:00:00Z',
|
||||
registrationsEnabled: false,
|
||||
};
|
||||
|
||||
it('accepts a valid IPv4 address', () => {
|
||||
const r = GeneralSettingsSchema.safeParse({ ...base, defaultChallengeIp: '10.66.77.88' });
|
||||
expect(r.success).toBe(true);
|
||||
if (r.success) expect(r.data.defaultChallengeIp).toBe('10.66.77.88');
|
||||
});
|
||||
|
||||
it('accepts a valid hostname', () => {
|
||||
const r = GeneralSettingsSchema.safeParse({ ...base, defaultChallengeIp: 'challenge.example.com' });
|
||||
expect(r.success).toBe(true);
|
||||
if (r.success) expect(r.data.defaultChallengeIp).toBe('challenge.example.com');
|
||||
});
|
||||
|
||||
it('trims surrounding whitespace from a valid value', () => {
|
||||
const r = GeneralSettingsSchema.safeParse({ ...base, defaultChallengeIp: ' 10.20.30.40 ' });
|
||||
expect(r.success).toBe(true);
|
||||
if (r.success) expect(r.data.defaultChallengeIp).toBe('10.20.30.40');
|
||||
});
|
||||
|
||||
it('rejects an empty string', () => {
|
||||
const r = GeneralSettingsSchema.safeParse({ ...base, defaultChallengeIp: '' });
|
||||
expect(r.success).toBe(false);
|
||||
if (r.success) return;
|
||||
expect(r.error.issues.some((i) => i.path.join('.') === 'defaultChallengeIp')).toBe(true);
|
||||
expect(r.error.issues.some((i) => /required/i.test(i.message))).toBe(true);
|
||||
});
|
||||
|
||||
it('rejects a whitespace-only value', () => {
|
||||
const r = GeneralSettingsSchema.safeParse({ ...base, defaultChallengeIp: ' ' });
|
||||
expect(r.success).toBe(false);
|
||||
if (r.success) return;
|
||||
expect(r.error.issues.some((i) => i.path.join('.') === 'defaultChallengeIp')).toBe(true);
|
||||
});
|
||||
|
||||
it('rejects incomplete IPv4 forms', () => {
|
||||
const r1 = GeneralSettingsSchema.safeParse({ ...base, defaultChallengeIp: '10.0.0.' });
|
||||
const r2 = GeneralSettingsSchema.safeParse({ ...base, defaultChallengeIp: '10.0.0' });
|
||||
expect(r1.success).toBe(false);
|
||||
expect(r2.success).toBe(false);
|
||||
});
|
||||
|
||||
it('rejects malformed addresses with the format message', () => {
|
||||
const r = GeneralSettingsSchema.safeParse({ ...base, defaultChallengeIp: '999.1.1.1' });
|
||||
expect(r.success).toBe(false);
|
||||
if (r.success) return;
|
||||
expect(r.error.issues.some((i) => /IPv4/.test(i.message) || /hostname/.test(i.message))).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('AdminGeneralService.updateSettings - happy path', () => {
|
||||
it('persists all keys and emits a settings event', async () => {
|
||||
const stored: Record<string, string> = {};
|
||||
|
||||
Reference in New Issue
Block a user