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 { createApiClient } from '$lib/api.server';
|
||||||
import { getErrorMessage } from '$lib/errors';
|
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 }) {
|
export async function load({ params, fetch, locals }) {
|
||||||
const canWrite =
|
const canWrite =
|
||||||
(locals.user as { groups?: { permissions: string[] }[] } | undefined)?.groups?.some((g) =>
|
(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 person = result.data!;
|
||||||
const personType = person.personType === 'SKIP' ? 'UNKNOWN' : person.personType;
|
const personType = normalizePersonType(person.personType);
|
||||||
return { person: { ...person, personType }, aliases: aliasesResult.data ?? [] };
|
return { person: { ...person, personType }, aliases: aliasesResult.data ?? [] };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,5 @@
|
|||||||
import { describe, it, expect } from 'vitest';
|
import { describe, it, expect } from 'vitest';
|
||||||
|
import { normalizePersonType } from './+page.server';
|
||||||
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', () => {
|
describe('edit load — SKIP → UNKNOWN normalization', () => {
|
||||||
it('maps SKIP to UNKNOWN', () => {
|
it('maps SKIP to UNKNOWN', () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user