test(persons): extract validatePersonFields and cover validation branches
- New src/lib/person-validation.ts exports validatePersonFields (pure function) - 8 unit tests covering: valid PERSON, lastName missing/undefined, firstName missing/undefined for PERSON, non-PERSON types without firstName - Both edit and new-person server actions now call the shared helper instead of inline if-chains, making the logic testable and non-duplicated Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
9
frontend/src/lib/person-validation.ts
Normal file
9
frontend/src/lib/person-validation.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
export function validatePersonFields(
|
||||
personType: string,
|
||||
firstName: string | undefined | null,
|
||||
lastName: string | undefined | null
|
||||
): string | null {
|
||||
if (!lastName) return 'Nachname ist Pflichtfeld.';
|
||||
if (personType === 'PERSON' && !firstName) return 'Vorname ist Pflichtfeld.';
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user