fe120ee222
ESLint turned `no-explicit-any` off for test files, and 219 casts had accumulated across 12 of them. Two shapes, very different risks: most were `(useWorkspace as any).mockReturnValue(...)`, mere laziness that `vi.mocked()` does properly; the rest cast partial fixtures onto API types, which erases the contract exactly where a test should enforce it. That second kind matters here specifically. This project's recurring bug is a field silently dropped between backend and frontend -- the hand-written mapping in models/plan.py has done it twice, and apiFetch mishandling structured errors was the same shape. A test that casts an incomplete fixture to `any` keeps passing through precisely that change. A typed fixture layer already existed at tests/fixtures/mockData.ts and was imported by exactly zero tests: the right tool was there and invisible, so everyone reached for a cast. It is now a set of `make*(overrides: Partial<T>) => T` factories returning complete, valid objects, split by domain with a barrel. When a type gains a field, one factory fails to compile instead of thirty tests silently passing. With the count at zero the ESLint exemption is deleted, so this cannot regrow. Removing it immediately caught two `}: any` prop stubs that a grep for "as any" had missed; those mocks now use the real components' exported prop types. `as unknown as T` survives in five places, each a test deliberately feeding invalid input (an undefined breakdown, missing tierData, a bogus leave type). CLAUDE.md now documents that as the only accepted escape, and points at the factories. interface PollResponse in useScraperFetch.ts is exported so its shape can be derived rather than duplicated -- pollScraperSession declares Promise<unknown>, so there was no other honest way to type it. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RXMhc9nT6sNz1SL4j8dznL
218 lines
6.0 KiB
TypeScript
218 lines
6.0 KiB
TypeScript
/**
|
|
* Shared test fixtures — domain entities.
|
|
*
|
|
* Prefer the `make*` factories over the `MOCK_*` constants in new tests: a
|
|
* factory returns a complete, correctly-typed object, so overriding one field
|
|
* can't silently leave the rest `undefined`/wrong the way a hand-rolled
|
|
* partial object cast with `as any` can. See `frontend/tests/fixtures/index.ts`
|
|
* for the full barrel of factories (plan, analytics, calendar, scraper, hooks).
|
|
*/
|
|
|
|
import type {
|
|
Child,
|
|
DayOverride,
|
|
LeaveWish,
|
|
ParentalLeaveFetch,
|
|
PersonalData,
|
|
PlannedLeaveDay,
|
|
TierData,
|
|
Tip,
|
|
VacationDays,
|
|
Workspace,
|
|
} from '@/types'
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Workspace
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export function makeWorkspace(overrides: Partial<Workspace> = {}): Workspace {
|
|
return {
|
|
id: 'ws-1',
|
|
name: 'Familjen Testsson',
|
|
planningGoal: 'balanced',
|
|
planningMode: 'solo',
|
|
createdAt: '2026-01-01T00:00:00',
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
export const MOCK_WORKSPACE: Workspace = makeWorkspace()
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Personal data (parents)
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export function makePersonalData(overrides: Partial<PersonalData> = {}): PersonalData {
|
|
return {
|
|
uuid: 'pd-a',
|
|
workspaceId: 'ws-1',
|
|
name: 'Förälder A',
|
|
salaryType: 'monthly',
|
|
employmentStatus: 'employed',
|
|
createdAt: '2026-01-01T00:00:00',
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
export const MOCK_PARENT_A: PersonalData = makePersonalData({ uuid: 'pd-a', name: 'Förälder A' })
|
|
export const MOCK_PARENT_B: PersonalData = makePersonalData({ uuid: 'pd-b', name: 'Förälder B' })
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Child
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export function makeChild(overrides: Partial<Child> = {}): Child {
|
|
return {
|
|
id: 'child-1',
|
|
workspaceId: 'ws-1',
|
|
name: 'Barnet',
|
|
birthDate: '2025-06-01',
|
|
preschoolStartDate: null,
|
|
preschoolPlanningDaysPerYear: 6,
|
|
createdAt: '2026-01-01T00:00:00',
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
export const MOCK_CHILD: Child = makeChild()
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Vacation days
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export function makeVacationDays(overrides: Partial<VacationDays> = {}): VacationDays {
|
|
return {
|
|
id: 'vd-1',
|
|
personalDataUuid: 'pd-a',
|
|
workspaceId: 'ws-1',
|
|
year: 2026,
|
|
totalDays: 25,
|
|
savedDaysIn: 0,
|
|
createdAt: '2026-01-01T00:00:00',
|
|
updatedAt: '2026-01-01T00:00:00',
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
export const MOCK_VACATION_DAYS: VacationDays = makeVacationDays()
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Parental leave fetch (+ tier data)
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export function makeTierData(overrides: Partial<TierData> = {}): TierData {
|
|
return {
|
|
sjukpenningTotal: 390,
|
|
sjukpenningUsed: 80,
|
|
sjukpenningLeft: 310,
|
|
lagstaNivaTotal: 90,
|
|
lagstaNivaUsed: 0,
|
|
lagstaNivaLeft: 90,
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
export function makeParentalLeaveFetch(overrides: Partial<ParentalLeaveFetch> = {}): ParentalLeaveFetch {
|
|
return {
|
|
id: 'plf-1',
|
|
personalDataUuid: 'pd-a',
|
|
workspaceId: 'ws-1',
|
|
childId: 'child-1',
|
|
source: 'manual',
|
|
fetchedAt: '2026-05-01T10:00:00',
|
|
totalDays: 240,
|
|
daysUsed: 80,
|
|
daysLeft: 160,
|
|
reservedDaysTotal: 90,
|
|
reservedDaysLeft: 70,
|
|
transferableDaysLeft: 50,
|
|
dubbeldagarLeft: 55,
|
|
tierData: makeTierData(),
|
|
createdAt: '2026-05-01T10:00:00',
|
|
updatedAt: '2026-05-01T10:00:00',
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
export const MOCK_PARENTAL_LEAVE: ParentalLeaveFetch = makeParentalLeaveFetch()
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Leave wishes
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export function makeLeaveWish(overrides: Partial<LeaveWish> = {}): LeaveWish {
|
|
return {
|
|
id: 'lw-1',
|
|
workspaceId: 'ws-1',
|
|
childId: null,
|
|
name: 'Sommar',
|
|
nameMessageKey: null,
|
|
windowStartMonth: 6,
|
|
windowStartDay: 15,
|
|
windowEndMonth: 7,
|
|
windowEndDay: 26,
|
|
targetWeeks: 6,
|
|
recurrence: 'yearly',
|
|
firstYear: 2026,
|
|
lastYear: null,
|
|
priority: 1,
|
|
parentMode: 'either',
|
|
parentPersonalDataUuid: null,
|
|
goalOverride: null,
|
|
windowMode: 'fixed',
|
|
createdAt: '2026-01-01T00:00:00',
|
|
updatedAt: '2026-01-01T00:00:00',
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Planned leave days
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export function makePlannedLeaveDay(overrides: Partial<PlannedLeaveDay> = {}): PlannedLeaveDay {
|
|
return {
|
|
id: 'pld-1',
|
|
workspaceId: 'ws-1',
|
|
childId: 'child-1',
|
|
parentPersonalDataUuid: 'pd-a',
|
|
date: '2026-06-15',
|
|
dayType: 'vacation',
|
|
isDubbeldag: false,
|
|
createdAt: '2026-01-01T00:00:00',
|
|
updatedAt: '2026-01-01T00:00:00',
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Day overrides (calendar exceptions)
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export function makeDayOverride(overrides: Partial<DayOverride> = {}): DayOverride {
|
|
return {
|
|
id: 'do-1',
|
|
workspaceId: 'ws-1',
|
|
date: '2026-12-24',
|
|
isWorkingDay: false,
|
|
note: null,
|
|
createdAt: '2026-01-01T00:00:00',
|
|
updatedAt: '2026-01-01T00:00:00',
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
// ---------------------------------------------------------------------------
|
|
// Tips
|
|
// ---------------------------------------------------------------------------
|
|
|
|
export function makeTip(overrides: Partial<Tip> = {}): Tip {
|
|
return {
|
|
id: 'tip-1',
|
|
severity: 'info',
|
|
messageKey: 'tips.example',
|
|
data: {},
|
|
...overrides,
|
|
}
|
|
}
|