Files
HIPCTF2/tests/frontend/landing-modal.spec.ts
T
2026-07-21 18:34:42 +00:00

53 lines
2.0 KiB
TypeScript

import { buildLoginFailureMessage } from '../../frontend/src/app/features/landing/login-modal.service';
describe('buildLoginFailureMessage', () => {
it.each([
[
'INVALID_CREDENTIALS',
'Invalid credentials',
{ text: 'Invalid username or password.', retryAfterSeconds: undefined },
],
[
'USERNAME_TAKEN',
'Username already taken',
{ text: 'Username already exists.', retryAfterSeconds: undefined },
],
[
'REGISTRATIONS_DISABLED',
'Registrations are currently disabled',
{ text: 'Registrations are currently disabled.', retryAfterSeconds: undefined },
],
[
'CSRF_INVALID',
'CSRF token missing or invalid',
{ text: 'Session expired. Please reload the page and try again.', retryAfterSeconds: undefined },
],
[
'WEAK_PASSWORD',
'Password must be at least 12 characters',
{ text: 'Password does not meet the security policy.', retryAfterSeconds: undefined },
],
[
'VALIDATION_FAILED',
'passwordConfirm: must match',
{ text: 'Please check the form fields and try again.', retryAfterSeconds: undefined },
],
[
'RATE_LIMITED',
'Too many failed attempts. Try again in 7s.',
{ text: 'Please wait 7 seconds before trying again.', retryAfterSeconds: 7 },
],
[
'RATE_LIMITED',
'Too many registration attempts; please wait a minute before trying again.',
{ text: 'Too many attempts. Please wait a moment before trying again.', retryAfterSeconds: undefined },
],
])('maps code=%s to expected message', (code, message, expected) => {
expect(buildLoginFailureMessage({ code, message })).toEqual(expected);
});
it('falls back to raw message for unknown codes', () => {
expect(buildLoginFailureMessage({ code: 'EXOTIC', message: 'Quux' }).text).toBe('Quux');
expect(buildLoginFailureMessage({ code: 'EXOTIC', message: '' }).text).toBe('Something went wrong. Please try again.');
});
});