ad0e3c0b33
A yearly-repeating period kept the same calendar date instead of the same
weekday: 2026-10-05..10-11 (Mon-Sun) recurred as 2027-10-05..10-11 (Tue-Mon)
rather than 2027-10-04..10-10. The snap added in 224fe7a only ever covered
window_mode == 'fixed'; 'flexible' wishes were unaligned at both stages.
project_window now snaps both modes. A flexible bound is still a bounding
range, but it keeps its weekday alignment year over year with its span held
fixed, so the search space never shrinks and a bound that is exactly as long
as the target (its only candidate) repeats week-shaped.
_rank_candidate gains a Monday-start term between cost and start, so equal-cost
candidates break on week alignment instead of "earliest". It sits after cost
deliberately: a cheaper non-Monday start still wins, because red days outrank
alignment.
_reuse_already_funded_window would otherwise freeze a pre-existing misaligned
placement forever, so it now releases a year whose reuse winner is misaligned
when a fresh search ranks strictly better -- never when one of its days is
pinned or excluded, so a deliberate per-day override always survives.
Migration 008 realigns flexible series already materialised under the old rule;
projection runs once, at create/update, so nothing repairs them on read.
Alongside this, the planner now says when it moved a period to catch red days.
WindowOutcome carries shift_gain_days (the saving over the naive bound-start
placement) and the calendar toasts it, once, on the sync that decided it.
A fixed window is never auto-moved -- its "exact requested placement,
unconditionally" guarantee stands -- but its shift suggestion is no longer
hidden behind a shortfall, so a fully-funded one can surface a cheaper week too.
Editing a period in the popover now also sends window_mode: 'fixed' with a
matching target. Preset chips create flexible wishes; dragging one down to an
exact week left it flexible with a week-long bound, which is the degenerate
single-candidate case that produced the reported dates.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DXPBfr1v7F71t6QcbHCaaT
213 lines
5.1 KiB
TypeScript
213 lines
5.1 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,
|
|
PlanChange,
|
|
PlanProposal,
|
|
PlanSyncResponse,
|
|
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: [],
|
|
shiftGainDays: 0,
|
|
...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,
|
|
}
|
|
}
|
|
|
|
/** `POST /api/plan/sync` — one (child, parent, date) slot's delta. See
|
|
* `PlanChange`'s docstring (src/types/entities.ts) for the `kind` vocabulary. */
|
|
export function makePlanChange(overrides: Partial<PlanChange> = {}): PlanChange {
|
|
return {
|
|
kind: 'added',
|
|
date: '2028-06-20',
|
|
parentPersonalDataUuid: 'pd-a',
|
|
childId: 'child-1',
|
|
oldDayType: null,
|
|
newDayType: 'vacation',
|
|
oldIsDubbeldag: null,
|
|
newIsDubbeldag: false,
|
|
oldWishId: null,
|
|
newWishId: 'lw-1',
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
export function makePlanSyncResponse(overrides: Partial<PlanSyncResponse> = {}): PlanSyncResponse {
|
|
return {
|
|
proposal: makePlanProposal(),
|
|
applyResult: makePlanApplyResponse(),
|
|
changes: [],
|
|
...overrides,
|
|
}
|
|
}
|