feat(persons): normalize SKIP→UNKNOWN in edit-route load function
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -22,7 +22,9 @@ export async function load({ params, fetch, locals }) {
|
||||
throw error(result.response.status, getErrorMessage(code));
|
||||
}
|
||||
|
||||
return { person: result.data!, aliases: aliasesResult.data ?? [] };
|
||||
const person = result.data!;
|
||||
const personType = person.personType === 'SKIP' ? 'UNKNOWN' : person.personType;
|
||||
return { person: { ...person, personType }, aliases: aliasesResult.data ?? [] };
|
||||
}
|
||||
|
||||
export const actions = {
|
||||
|
||||
33
frontend/src/routes/persons/[id]/edit/page.server.test.ts
Normal file
33
frontend/src/routes/persons/[id]/edit/page.server.test.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
|
||||
type PersonType = 'PERSON' | 'INSTITUTION' | 'GROUP' | 'UNKNOWN' | 'SKIP';
|
||||
|
||||
function normalizePersonType(raw: string | undefined | null): PersonType {
|
||||
return raw === 'SKIP' ? 'UNKNOWN' : ((raw ?? 'PERSON') as PersonType);
|
||||
}
|
||||
|
||||
describe('edit load — SKIP → UNKNOWN normalization', () => {
|
||||
it('maps SKIP to UNKNOWN', () => {
|
||||
expect(normalizePersonType('SKIP')).toBe('UNKNOWN');
|
||||
});
|
||||
|
||||
it('passes PERSON through unchanged', () => {
|
||||
expect(normalizePersonType('PERSON')).toBe('PERSON');
|
||||
});
|
||||
|
||||
it('passes INSTITUTION through unchanged', () => {
|
||||
expect(normalizePersonType('INSTITUTION')).toBe('INSTITUTION');
|
||||
});
|
||||
|
||||
it('passes GROUP through unchanged', () => {
|
||||
expect(normalizePersonType('GROUP')).toBe('GROUP');
|
||||
});
|
||||
|
||||
it('passes UNKNOWN through unchanged', () => {
|
||||
expect(normalizePersonType('UNKNOWN')).toBe('UNKNOWN');
|
||||
});
|
||||
|
||||
it('defaults null to PERSON', () => {
|
||||
expect(normalizePersonType(null)).toBe('PERSON');
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user