6d91f153d7
Vacation rescue/wrap in allocation_service, new plan models/endpoints, VacationRescueTip, useRescueDayActions, vacationSwaps util, sv+en i18n, Dashboard/Calendar wiring. Conflicts came from main's "day assertions" restructure and the earlier merges; both intents kept: - plan.py: both import sets; main's sync-with-wish handler kept next to the branch's new /rescue-days/dismiss endpoint; HTTP_422_UNPROCESSABLE_CONTENT applied to the branch's code (and a survivor in auth.py). - Accepting a rescue day now goes through POST /api/day-assertions (an ad-hoc 'vacation' assertion, no wish) instead of /plan/apply with an `is_pinned` flag that no longer exists: on main a pin IS a day assertion (see PlanningService.add_planned_day's docstring), and an assertion is what keeps a later sync from retyping the day. useRescueDayActions, its tests, VacationRescueTip's tests and the backend integration flow follow that contract; applyPlan stays as a client for the live endpoint minus the dropped field. The hook also gets the security branch's useLatestRequest guard with an unconditionally cleared busy flag. - Calendar.tsx: `locale` threaded into main's applyWishSyncResult call of buildSyncToastMessage (the branch's new parameter); the branch's swap-visibility toast tests drive the preset path through syncWithWish, which is how main saves a wish now. - types/api.ts: ProposedDayApplyItem kept (used by applyPlan) without isPinned; the Add/UpdatePlannedDayRequest types stay removed as on main. - fixtures/plan.ts: ResourceShortage import dropped (type removed on main). Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01T4wjgbVL4HAC5Rdaw75VbV
233 lines
5.8 KiB
TypeScript
233 lines
5.8 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,
|
|
PlanSyncWithWishResponse,
|
|
PlanWarning,
|
|
PoolBalance,
|
|
ProposedDay,
|
|
Rejection,
|
|
RescueDay,
|
|
ShortfallRemedy,
|
|
SurplusAdvice,
|
|
VacationBalance,
|
|
WindowOutcome,
|
|
} from '@/types'
|
|
import { makeLeaveWish } from './mockData'
|
|
|
|
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,
|
|
}
|
|
}
|
|
|
|
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,
|
|
seriesId: null,
|
|
...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,
|
|
}
|
|
}
|
|
|
|
/** §vacation-rescue — one suggest-only concrete date (see `RescueDay` in
|
|
* src/types/entities.ts). Defaults to a date within `makePlanProposal`'s
|
|
* implicit current-year assumption for tests that don't care about the
|
|
* exact date. */
|
|
export function makeRescueDay(overrides: Partial<RescueDay> = {}): RescueDay {
|
|
return {
|
|
date: '2026-12-28',
|
|
parentPersonalDataUuid: 'pd-a',
|
|
childId: 'child-1',
|
|
year: 2026,
|
|
reason: 'vacation_rescue',
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
export function makePlanProposal(overrides: Partial<PlanProposal> = {}): PlanProposal {
|
|
return {
|
|
days: [makeProposedDay()],
|
|
outcomes: [makeWindowOutcome()],
|
|
warnings: [],
|
|
poolBalances: [],
|
|
vacationBalances: [],
|
|
surplusAdvice: [],
|
|
age4Projections: [],
|
|
rescueDays: [],
|
|
...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',
|
|
evicted: false,
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
export function makePlanSyncResponse(overrides: Partial<PlanSyncResponse> = {}): PlanSyncResponse {
|
|
return {
|
|
proposal: makePlanProposal(),
|
|
applyResult: makePlanApplyResponse(),
|
|
changes: [],
|
|
...overrides,
|
|
}
|
|
}
|
|
|
|
/** `POST /api/plan/sync-with-wish`'s response — the wish as created/updated
|
|
* plus the same `PlanSyncResponse` shape `syncPlan()` returns. See
|
|
* `PlanSyncWithWishResponse`'s doc comment (src/types/api.ts): `wish` is
|
|
* present even when `sync.applyResult.accepted` is `false`. */
|
|
export function makePlanSyncWithWishResponse(
|
|
overrides: Partial<PlanSyncWithWishResponse> = {},
|
|
): PlanSyncWithWishResponse {
|
|
return {
|
|
wish: makeLeaveWish(),
|
|
sync: makePlanSyncResponse(),
|
|
...overrides,
|
|
}
|
|
}
|