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
26 lines
901 B
TypeScript
26 lines
901 B
TypeScript
/**
|
|
* Shared test fixtures — small ad hoc API response shapes that aren't a
|
|
* named type in `src/types/` (they're inline return-type object literals in
|
|
* `src/services/api.ts`). Derived via `Awaited<ReturnType<typeof fn>>`
|
|
* instead of redeclaring the shape, so a change to the real signature fails
|
|
* the fixture at compile time rather than drifting silently.
|
|
*/
|
|
|
|
import type { addPartner } from '@/services/api'
|
|
|
|
/** Shared by `addPartner` and `updateParentSettings` — both return the same
|
|
* `{ uuid, name, salary_type, employment_status }` wire shape. */
|
|
export type PartnerMemberResponse = Awaited<ReturnType<typeof addPartner>>
|
|
|
|
export function makePartnerMemberResponse(
|
|
overrides: Partial<PartnerMemberResponse> = {},
|
|
): PartnerMemberResponse {
|
|
return {
|
|
uuid: 'pd-b',
|
|
name: 'Partner',
|
|
salary_type: 'monthly',
|
|
employment_status: 'employed',
|
|
...overrides,
|
|
}
|
|
}
|