- Replace mock Nitro routes with server-side proxies to the Go API - /plan reads Go /api/staffing; local assumption edits are a labeled preview - /simulate reads base and scenario staffing from Go instead of local multipliers - Route train upload and scenario POST through Nitro with server-only credentials - Keep NUXT_PUBLIC_USE_MOCK=1 as an explicit dev fallback only - Match Go's global-peak flat schedule and add a captured Go parity fixture - Run the web runtime as numeric UID/GID 10001:10001 - Add make check, Gitea CI workflow and a proxy smoke script
106 lines
3.6 KiB
TypeScript
106 lines
3.6 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { buildStaffing, planWeekStart, applyScenario } from '../shared/staffing'
|
|
import type { Point } from '../shared/types'
|
|
|
|
const now = '2026-11-14T08:12:00Z'
|
|
|
|
function mondayPoints(value = 100): Point[] {
|
|
return Array.from({ length: 24 }, (_, hour) => ({
|
|
t: new Date(Date.UTC(2026, 10, 15, 23 + hour)).toISOString().replace('.000Z', 'Z'),
|
|
v: value,
|
|
}))
|
|
}
|
|
|
|
describe('planWeekStart', () => {
|
|
it('returns the Monday after the demo Saturday', () => {
|
|
expect(planWeekStart(now)).toBe('2026-11-16')
|
|
})
|
|
})
|
|
|
|
describe('buildStaffing', () => {
|
|
it('applies the contract heuristic to a flat 10:00-20:00 day', () => {
|
|
const build = buildStaffing({
|
|
sensor: 'hn-stadtgalerie-01',
|
|
scenario: 'base',
|
|
standard: 'standard',
|
|
points: mondayPoints(100),
|
|
weekStart: '2026-11-16',
|
|
data_version: 'data',
|
|
model_version: 'model',
|
|
context_version: 'context',
|
|
})
|
|
|
|
expect(build.byDate['2026-11-16']).toHaveLength(10)
|
|
expect(build.response.shifts).toEqual([
|
|
{ date: '2026-11-16', start: '10:00', end: '14:00', staff: 5 },
|
|
{ date: '2026-11-16', start: '14:00', end: '18:00', staff: 5 },
|
|
{ date: '2026-11-16', start: '18:00', end: '20:00', staff: 5 },
|
|
])
|
|
expect(build.response.summary.coverage_pct).toBe(100)
|
|
expect(build.response.summary.cost_eur).toBe(800)
|
|
expect(build.response.summary.flat_schedule_cost_eur).toBe(800)
|
|
expect(build.response.summary.understaffed_hours).toBe(0)
|
|
})
|
|
|
|
it('uses the block peak so low hours become overstaffed, not understaffed', () => {
|
|
const points = mondayPoints(60).map((point, index) =>
|
|
index === 11 ? { ...point, v: 200 } : point,
|
|
)
|
|
const build = buildStaffing({
|
|
sensor: 'hn-stadtgalerie-01',
|
|
scenario: 'base',
|
|
standard: 'standard',
|
|
points,
|
|
weekStart: '2026-11-16',
|
|
data_version: 'data',
|
|
model_version: 'model',
|
|
context_version: 'context',
|
|
})
|
|
const firstHour = build.byDate['2026-11-16']?.[0]
|
|
expect(firstHour?.required_staff).toBe(3)
|
|
expect(firstHour?.scheduled_staff).toBe(10)
|
|
expect(build.response.summary.overstaffed_hours).toBeGreaterThan(0)
|
|
expect(build.response.summary.understaffed_hours).toBe(0)
|
|
})
|
|
|
|
it('compares the flat schedule against the global peak, matching the Go API', () => {
|
|
// Monday needs 5, Tuesday needs 10. CONTRACT §5 applies max(required) to
|
|
// every hour: 10 * 20 h * €16 = €3200, not a per-day peak sum.
|
|
const points = [
|
|
...mondayPoints(100).map((point, index) => ({
|
|
...point,
|
|
t: new Date(Date.UTC(2026, 10, 15, 23 + index)).toISOString().replace('.000Z', 'Z'),
|
|
})),
|
|
...mondayPoints(200).map((point, index) => ({
|
|
...point,
|
|
t: new Date(Date.UTC(2026, 10, 16, 23 + index)).toISOString().replace('.000Z', 'Z'),
|
|
})),
|
|
]
|
|
const build = buildStaffing({
|
|
sensor: 'hn-stadtgalerie-01',
|
|
scenario: 'base',
|
|
standard: 'standard',
|
|
points,
|
|
weekStart: '2026-11-16',
|
|
data_version: 'data',
|
|
model_version: 'model',
|
|
context_version: 'context',
|
|
})
|
|
|
|
expect(build.response.summary.flat_schedule_cost_eur).toBe(3200)
|
|
expect(build.response.summary.cost_eur).toBe(2400)
|
|
})
|
|
})
|
|
|
|
describe('applyScenario', () => {
|
|
const saturday: Point = { t: '2026-11-21T12:00:00Z', v: 100, lo: 80, hi: 120 }
|
|
|
|
it('raises Saturday for the sunny market scenario', () => {
|
|
expect(applyScenario([saturday], 'sunny-saturday-market')[0]?.v).toBe(120)
|
|
})
|
|
|
|
it('lowers Saturday for the rainy scenario', () => {
|
|
expect(applyScenario([saturday], 'rainy-saturday')[0]?.v).toBe(82)
|
|
})
|
|
})
|