Add tests for sessions, guards, API error details and the app layout load

This commit is contained in:
2026-09-24 14:03:35 +02:00
parent ba0a2373b5
commit b5c9658d65
4 changed files with 210 additions and 0 deletions
+31
View File
@@ -0,0 +1,31 @@
import { describe, expect, it } from 'vitest';
import { apiErrorDetail } from './api';
describe('apiErrorDetail', () => {
it('joins the validation messages from errors', () => {
expect(
apiErrorDetail({ errors: { Name: ['Too short.', 'Required.'], Genre: ['Invalid.'] } })
).toBe('Too short. Required. Invalid.');
});
it('flattens arrays and ignores non-string entries', () => {
expect(apiErrorDetail({ errors: { A: ['one', 2, null], B: 'two' } })).toBe('one two');
});
it('falls back to detail when errors has no text', () => {
expect(apiErrorDetail({ errors: {}, detail: 'Bad request.' })).toBe('Bad request.');
});
it('falls back to title after detail', () => {
expect(apiErrorDetail({ detail: '', title: 'Conflict' })).toBe('Conflict');
expect(apiErrorDetail({ title: 'Conflict' })).toBe('Conflict');
});
it('returns undefined for non-objects and empty objects', () => {
expect(apiErrorDetail(undefined)).toBeUndefined();
expect(apiErrorDetail(null)).toBeUndefined();
expect(apiErrorDetail('boom')).toBeUndefined();
expect(apiErrorDetail({})).toBeUndefined();
expect(apiErrorDetail({ detail: 3, title: '' })).toBeUndefined();
});
});