Files
F-r-ldraledigplannerare/frontend/tests/fixtures/mockData.ts
T
jacobh2 97a7200c1a Parse transferable days from FK instead of deriving them
The scraper never read "överlåtbara dagar" from Försäkringskassan. It only
visited ansok-och-planera-foraldrapenning#/valjdagar and derived the
reserved/transferable split in build_snapshot, assuming transferable days
are spent before reserved ones. On real data that gave 49 for the user and
0 for the partner where FK states 129 and 71.

The assumption cannot be repaired: reserved-first, transferable-first,
proportional and cap-based models were all checked against real figures and
none reproduces FK's accounting (reserved-first fits the partner but is 10
days off for the user). FK publishes the real numbers per parent per tier on
the min-foraldrapenning page, which the scraper had never visited.

- Scrape the "Dagar ni kan föra över" panel after the valjdagar extraction,
  summing sjukpenningnivå + lägstanivå per parent. The totals are not
  literals on the page. Parse only direct-child <p> elements: the first
  group embeds a tooltip with decoy "45 dagar"/"90 dagar" text.
- build_snapshot accepts the reported value and derives reserved days from
  it; the old arithmetic remains only as a fallback. An implausible FK value
  degrades to that fallback rather than failing the fetch.
- Record provenance in transferable_days_reported (migration 006) and badge
  derived values as estimates in the dashboard breakdown. Drop the footnote's
  claim that at most 150 days are transferable — real data contradicts it as
  a per-family figure.
- Select the child's section by name when FK lists several; never guess.

Verified against a live BankID scrape: scraped 240/101/139 with 129
transferable, deduced partner 240/169/71 with 71, both flagged as reported.

Incidental fixes found along the way:

- The fetch router never forwarded the partner's transferable figure to
  persist_partner_deduction, so the partner's stored snapshot would have kept
  the flawed split even once the parse landed.
- 'deduced' snapshots were labelled "Manually entered" by a two-way ternary
  over a three-value union. Replaced with a compiler-checked exhaustive map.
- Alembic resolved its database from alembic.ini alone, ignoring
  APP_SQLITE_PATH, so migrations silently targeted the developer's real
  database even when pointed elsewhere. env.py now resolves it, preferring
  -x sqlalchemy.url, then a real APP_SQLITE_PATH, then the ini value.
- backend/captures/ was not ignored: the root pattern was anchored as
  /captures/ despite a comment saying scraper dumps must never be tracked.
- CLAUDE.md quoted test counts and coverage percentages that had gone stale,
  which made a correct verification report look suspect. Gate thresholds kept.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DXPBfr1v7F71t6QcbHCaaT
2026-09-20 09:11:53 +02:00

230 lines
6.2 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,
PlannedDayExclusion,
} from '@/types'
// ---------------------------------------------------------------------------
// Workspace
// ---------------------------------------------------------------------------
export function makeWorkspace(overrides: Partial<Workspace> = {}): Workspace {
return {
id: 'ws-1',
name: 'Familjen Testsson',
createdAt: '2026-01-01T00:00:00',
takePlOnRedDays: false,
...overrides,
}
}
// ---------------------------------------------------------------------------
// 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,
}
}
// ---------------------------------------------------------------------------
// 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,
}
}
// ---------------------------------------------------------------------------
// 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,
}
}
// ---------------------------------------------------------------------------
// 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,
transferableDaysReported: true,
dubbeldagarLeft: 55,
tierData: makeTierData(),
createdAt: '2026-05-01T10:00:00',
updatedAt: '2026-05-01T10:00:00',
...overrides,
}
}
// ---------------------------------------------------------------------------
// 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,
targetDays: null,
firstYear: 2026,
// A standalone (non-repeating) occurrence by default — override
// `seriesId` (and `lastYear`) to build one year of a repeating wish.
seriesId: null,
lastYear: null,
priority: 1,
parentMode: 'either',
parentPersonalDataUuid: null,
windowMode: 'fixed',
wantsDubbeldag: false,
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,
wishId: null,
isPinned: 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,
}
}
export function makePlannedDayExclusion(
overrides: Partial<PlannedDayExclusion> = {},
): PlannedDayExclusion {
return {
id: 'ex-1',
workspaceId: 'ws-1',
childId: 'child-1',
parentPersonalDataUuid: 'parent-1',
date: '2027-02-03',
createdAt: '2027-01-01T00:00:00',
updatedAt: '2027-01-01T00:00:00',
...overrides,
}
}
// ---------------------------------------------------------------------------
// Tips
// ---------------------------------------------------------------------------
export function makeTip(overrides: Partial<Tip> = {}): Tip {
return {
id: 'tip-1',
severity: 'info',
messageKey: 'tips.example',
data: {},
anchorDate: null,
anchorRange: null,
...overrides,
}
}