refactor(persons): export normalizePersonType from edit server module
Tests now import from production code instead of a local copy, giving real regression protection if the inline logic is changed. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,6 +2,12 @@ import { error, fail, redirect } from '@sveltejs/kit';
|
||||
import { createApiClient } from '$lib/api.server';
|
||||
import { getErrorMessage } from '$lib/errors';
|
||||
|
||||
type PersonType = 'PERSON' | 'INSTITUTION' | 'GROUP' | 'UNKNOWN' | 'SKIP';
|
||||
|
||||
export function normalizePersonType(raw: string | undefined | null): Exclude<PersonType, 'SKIP'> {
|
||||
return raw === 'SKIP' ? 'UNKNOWN' : ((raw ?? 'PERSON') as Exclude<PersonType, 'SKIP'>);
|
||||
}
|
||||
|
||||
export async function load({ params, fetch, locals }) {
|
||||
const canWrite =
|
||||
(locals.user as { groups?: { permissions: string[] }[] } | undefined)?.groups?.some((g) =>
|
||||
@@ -23,7 +29,7 @@ export async function load({ params, fetch, locals }) {
|
||||
}
|
||||
|
||||
const person = result.data!;
|
||||
const personType = person.personType === 'SKIP' ? 'UNKNOWN' : person.personType;
|
||||
const personType = normalizePersonType(person.personType);
|
||||
return { person: { ...person, personType }, aliases: aliasesResult.data ?? [] };
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,5 @@
|
||||
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);
|
||||
}
|
||||
import { normalizePersonType } from './+page.server';
|
||||
|
||||
describe('edit load — SKIP → UNKNOWN normalization', () => {
|
||||
it('maps SKIP to UNKNOWN', () => {
|
||||
|
||||
Reference in New Issue
Block a user