One-time prettier --write so the new format:check CI gate starts green. .prettierignore excludes generated (api-client.ts, documentation.json), vendored (public/cibg-huisstijl), and backend (dotnet format owns it). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
31 lines
1.2 KiB
TypeScript
31 lines
1.2 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { problemDetail, problemFieldErrors } from './api-error';
|
|
|
|
describe('problemDetail', () => {
|
|
it('extracts the detail from an RFC-7807 ProblemDetails', () => {
|
|
expect(problemDetail({ detail: 'Afgewezen: 0 uren.', status: 422 }, 'fallback')).toBe(
|
|
'Afgewezen: 0 uren.',
|
|
);
|
|
});
|
|
|
|
it('falls back when there is no detail', () => {
|
|
expect(problemDetail(new Error('boom'), 'fallback')).toBe('fallback');
|
|
expect(problemDetail({ status: 500 }, 'fallback')).toBe('fallback');
|
|
expect(problemDetail(undefined, 'fallback')).toBe('fallback');
|
|
});
|
|
});
|
|
|
|
describe('problemFieldErrors (G4 seam)', () => {
|
|
it('maps a ValidationProblemDetails errors dict to first-message-per-field', () => {
|
|
expect(
|
|
problemFieldErrors({ errors: { straat: ['Verplicht.'], postcode: ['Ongeldig.', 'x'] } }),
|
|
).toEqual({ straat: 'Verplicht.', postcode: 'Ongeldig.' });
|
|
});
|
|
|
|
it('returns {} when there is no errors envelope (the current backend shape)', () => {
|
|
expect(problemFieldErrors({ detail: 'one banner' })).toEqual({});
|
|
expect(problemFieldErrors(new Error('boom'))).toEqual({});
|
|
expect(problemFieldErrors(undefined)).toEqual({});
|
|
});
|
|
});
|