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
183 lines
4.3 KiB
TypeScript
183 lines
4.3 KiB
TypeScript
/**
|
|
* Shared test fixtures — the planning engine (`POST /api/plan/propose`,
|
|
* `POST /api/plan/apply`) and its nested shapes.
|
|
*/
|
|
|
|
import type {
|
|
CostBreakdown,
|
|
DayCollision,
|
|
PlanAge4Projection,
|
|
PlanApplyResponse,
|
|
PlanProposal,
|
|
PlanWarning,
|
|
PoolBalance,
|
|
ProposedDay,
|
|
ProposedDayApplyItem,
|
|
Rejection,
|
|
ShortfallRemedy,
|
|
SurplusAdvice,
|
|
VacationBalance,
|
|
WindowOutcome,
|
|
} from '@/types'
|
|
|
|
export function makeCostBreakdown(overrides: Partial<CostBreakdown> = {}): CostBreakdown {
|
|
return { free: 0, vacation: 0, sjukpenning: 0, lagsta: 0, ...overrides }
|
|
}
|
|
|
|
export function makeShortfallRemedy(overrides: Partial<ShortfallRemedy> = {}): ShortfallRemedy {
|
|
return {
|
|
kind: 'dubbeldag',
|
|
messageKey: 'planRemedies.example',
|
|
data: {},
|
|
daysFreed: 0,
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
export function makeProposedDay(overrides: Partial<ProposedDay> = {}): ProposedDay {
|
|
return {
|
|
date: '2026-06-15',
|
|
parentPersonalDataUuid: 'pd-a',
|
|
childId: 'child-1',
|
|
dayType: 'sjukpenning',
|
|
isDubbeldag: false,
|
|
wishId: 'lw-1',
|
|
reason: 'Sommar',
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
/** The `/api/plan/apply` request-side counterpart of `ProposedDay` — no
|
|
* `wishId`/`reason`, and `dayType` additionally allows `'free'`. */
|
|
export function makeProposedDayApplyItem(
|
|
overrides: Partial<ProposedDayApplyItem> = {},
|
|
): ProposedDayApplyItem {
|
|
return {
|
|
date: '2026-06-15',
|
|
parentPersonalDataUuid: 'pd-a',
|
|
childId: 'child-1',
|
|
dayType: 'sjukpenning',
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
export function makeWindowOutcome(overrides: Partial<WindowOutcome> = {}): WindowOutcome {
|
|
return {
|
|
wishId: 'lw-1',
|
|
wishName: 'Sommar',
|
|
wishNameMessageKey: null,
|
|
year: 2026,
|
|
startDate: '2026-06-15',
|
|
endDate: '2026-07-26',
|
|
weeksWished: 6,
|
|
weeksFunded: 6,
|
|
shortfallDays: 0,
|
|
strategy: 'parent_swap',
|
|
messageKey: 'planOutcomes.windowExplanation',
|
|
data: {},
|
|
costBreakdown: makeCostBreakdown({ free: 12, vacation: 19, sjukpenning: 11 }),
|
|
remedies: [],
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
export function makePlanWarning(overrides: Partial<PlanWarning> = {}): PlanWarning {
|
|
return {
|
|
kind: 'days_lost_at_age_4',
|
|
messageKey: 'planWarnings.days_lost_at_age_4',
|
|
data: {},
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
export function makePoolBalance(overrides: Partial<PoolBalance> = {}): PoolBalance {
|
|
return {
|
|
parentPersonalDataUuid: 'pd-a',
|
|
childId: 'child-1',
|
|
sjukpenningLeft: 310,
|
|
lagstaLeft: 90,
|
|
dubbeldagarLeft: 55,
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
export function makeVacationBalance(overrides: Partial<VacationBalance> = {}): VacationBalance {
|
|
return {
|
|
parentPersonalDataUuid: 'pd-a',
|
|
year: 2026,
|
|
totalDays: 25,
|
|
savedDaysIn: 0,
|
|
alreadyUsed: 0,
|
|
isAssumed: false,
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
export function makeSurplusAdvice(overrides: Partial<SurplusAdvice> = {}): SurplusAdvice {
|
|
return {
|
|
kind: 'wish_more_leave',
|
|
messageKey: 'planSurplus.wish_more_leave',
|
|
daysInvolved: 0,
|
|
data: {},
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
export function makePlanAge4Projection(overrides: Partial<PlanAge4Projection> = {}): PlanAge4Projection {
|
|
return {
|
|
parentPersonalDataUuid: 'pd-a',
|
|
childId: 'child-1',
|
|
fourthBirthday: '2029-06-01',
|
|
projectedLeftAtB4: 0,
|
|
savableAfterB4: 96,
|
|
expiringAtB4: 0,
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
export function makePlanProposal(overrides: Partial<PlanProposal> = {}): PlanProposal {
|
|
return {
|
|
days: [makeProposedDay()],
|
|
outcomes: [makeWindowOutcome()],
|
|
warnings: [],
|
|
poolBalances: [],
|
|
vacationBalances: [],
|
|
surplusAdvice: [],
|
|
age4Projections: [],
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
export function makeDayCollision(overrides: Partial<DayCollision> = {}): DayCollision {
|
|
return {
|
|
date: '2026-06-15',
|
|
parentPersonalDataUuid: 'pd-a',
|
|
childId: 'child-1',
|
|
existingDayType: 'vacation',
|
|
proposedDayType: 'sjukpenning',
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
export function makeRejection(overrides: Partial<Rejection> = {}): Rejection {
|
|
return {
|
|
messageKey: 'planApply.rejection.insufficientBalance',
|
|
data: {},
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
export function makePlanApplyResponse(overrides: Partial<PlanApplyResponse> = {}): PlanApplyResponse {
|
|
return {
|
|
accepted: true,
|
|
createdCount: 0,
|
|
skippedIdenticalCount: 0,
|
|
skippedFreeCount: 0,
|
|
replacedCount: 0,
|
|
collisions: [],
|
|
rejections: [],
|
|
createdDays: [],
|
|
...overrides,
|
|
}
|
|
}
|