refactor(test): drop double-cast on Person fixtures
Drops the `as unknown as Person` double-cast in makePerson and on AUGUSTE/ANNA in favor of plain return-typed object literals; this restores the type-system safety net Felix flagged on PR #629 — a future required field on Person now fails compilation in the fixture instead of silently slipping through. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -10,18 +10,18 @@ type Person = components['schemas']['Person'];
|
|||||||
|
|
||||||
afterEach(cleanup);
|
afterEach(cleanup);
|
||||||
|
|
||||||
const makePerson = (id: string, name: string, overrides: Partial<Person> = {}): Person =>
|
const makePerson = (id: string, name: string, overrides: Partial<Person> = {}): Person => {
|
||||||
({
|
const parts = name.split(' ');
|
||||||
|
return {
|
||||||
id,
|
id,
|
||||||
firstName: name.split(' ')[0] ?? null,
|
firstName: parts[0],
|
||||||
lastName: name.split(' ').slice(1).join(' ') || name,
|
lastName: parts.slice(1).join(' ') || name,
|
||||||
displayName: name,
|
displayName: name,
|
||||||
personType: 'PERSON',
|
personType: 'PERSON',
|
||||||
familyMember: false,
|
familyMember: false,
|
||||||
birthYear: null,
|
|
||||||
deathYear: null,
|
|
||||||
...overrides
|
...overrides
|
||||||
}) as unknown as Person;
|
};
|
||||||
|
};
|
||||||
|
|
||||||
type DropdownState = {
|
type DropdownState = {
|
||||||
items: Person[];
|
items: Person[];
|
||||||
|
|||||||
@@ -26,17 +26,21 @@ const AUGUSTE: Person = {
|
|||||||
firstName: 'Auguste',
|
firstName: 'Auguste',
|
||||||
lastName: 'Raddatz',
|
lastName: 'Raddatz',
|
||||||
displayName: 'Auguste Raddatz',
|
displayName: 'Auguste Raddatz',
|
||||||
|
personType: 'PERSON',
|
||||||
|
familyMember: false,
|
||||||
birthYear: 1882,
|
birthYear: 1882,
|
||||||
deathYear: 1944
|
deathYear: 1944
|
||||||
} as unknown as Person;
|
};
|
||||||
|
|
||||||
const ANNA: Person = {
|
const ANNA: Person = {
|
||||||
id: 'p-anna',
|
id: 'p-anna',
|
||||||
firstName: 'Anna',
|
firstName: 'Anna',
|
||||||
lastName: 'Schmidt',
|
lastName: 'Schmidt',
|
||||||
displayName: 'Anna Schmidt',
|
displayName: 'Anna Schmidt',
|
||||||
|
personType: 'PERSON',
|
||||||
|
familyMember: false,
|
||||||
birthYear: 1860
|
birthYear: 1860
|
||||||
} as unknown as Person;
|
};
|
||||||
|
|
||||||
function mockFetchWithPersons(persons: Person[] = [AUGUSTE, ANNA]) {
|
function mockFetchWithPersons(persons: Person[] = [AUGUSTE, ANNA]) {
|
||||||
vi.stubGlobal(
|
vi.stubGlobal(
|
||||||
|
|||||||
Reference in New Issue
Block a user