Something went wrong. Try again.
A free, open-source, self-hosted place to write a novel.
Something went wrong. Try again.
12345678910111213141516171819202122232425import { describe, expect, it } from 'vitest';import { isDisabledAccount, messageFor } from './auth-errors.ts';
describe('authentication errors', () => { it('prefers the API error body and falls back to the error message', () => { expect(messageFor({ body: { message: 'Account disabled' }, message: 'Generic' })).toBe( 'Account disabled' ); expect(messageFor({ body: { message: '' }, message: 'Generic' })).toBe('Generic'); expect(messageFor(new Error('Failed'))).toBe('Failed'); });
it('uses the supplied fallback for unknown or malformed errors', () => { for (const error of [null, undefined, 'failed', {}, { body: { message: 5 } }]) { expect(messageFor(error, 'Try again')).toBe('Try again'); } });
it('recognises only the disabled account code', () => { expect(isDisabledAccount({ body: { code: 'BANNED_USER' } })).toBe(true); expect(isDisabledAccount({ body: { code: 'INVALID_PASSWORD' } })).toBe(false); expect(isDisabledAccount(null)).toBe(false); });});