mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-22 13:10:29 +00:00
5fcb307270
contractHandler() parses the request body against the shared request schema, answering 400 like the server's Zod pipe on a body it would refuse, and the mock's answer against the response schema, failing on a factory that drifted. The trips, budget, places, todo, tags and categories, day notes, packing, reservations and assignments handlers and the vacay plan and colour updates use it wherever shared has a schema; the offline bundle and the other vacay routes have none yet and stay plain. The typed bodies showed where the old handlers echoed request shapes back as stored rows: payers and members are no longer echoed into a budget item, and checked and is_private come back as 0/1 the way the server stores them.
180 lines
5.5 KiB
TypeScript
180 lines
5.5 KiB
TypeScript
import { vacaySetColorRequestSchema, vacayUpdatePlanRequestSchema } from '@trek/shared';
|
|
import { http, HttpResponse } from 'msw';
|
|
import { contractHandler } from '../contract';
|
|
|
|
export const vacayHandlers = [
|
|
http.get('/api/school-holiday-catalog', () => HttpResponse.json({ countries: [], regions: [] })),
|
|
http.get('/api/addons/vacay/plan', () => {
|
|
return HttpResponse.json({
|
|
plan: {
|
|
id: 1,
|
|
holidays_enabled: false,
|
|
holidays_region: null,
|
|
holiday_calendars: [],
|
|
block_weekends: true,
|
|
carry_over_enabled: false,
|
|
company_holidays_enabled: false,
|
|
},
|
|
users: [{ id: 1, username: 'user1', color: '#3b82f6' }],
|
|
pendingInvites: [],
|
|
incomingInvites: [],
|
|
isOwner: true,
|
|
isFused: false,
|
|
});
|
|
}),
|
|
|
|
// Only the request has a schema: the plan answer is open in @trek/shared.
|
|
contractHandler('put', '/api/addons/vacay/plan', { request: vacayUpdatePlanRequestSchema }, () => {
|
|
return HttpResponse.json({
|
|
plan: {
|
|
id: 1,
|
|
holidays_enabled: true,
|
|
holidays_region: null,
|
|
holiday_calendars: [],
|
|
block_weekends: true,
|
|
carry_over_enabled: false,
|
|
company_holidays_enabled: false,
|
|
},
|
|
});
|
|
}),
|
|
|
|
http.get('/api/addons/vacay/year-settings', () => {
|
|
return HttpResponse.json({
|
|
settings: { year_type: 'calendar', year_start_month: 1, year_start_day: 1, hire_date: null },
|
|
});
|
|
}),
|
|
|
|
http.put('/api/addons/vacay/year-settings', async ({ request }) => {
|
|
const body = (await request.json()) as Record<string, unknown>;
|
|
return HttpResponse.json({
|
|
settings: { year_type: 'calendar', year_start_month: 1, year_start_day: 1, hire_date: null, ...body },
|
|
});
|
|
}),
|
|
|
|
http.get('/api/addons/vacay/years', () => {
|
|
return HttpResponse.json({ years: [2025, 2026] });
|
|
}),
|
|
|
|
http.post('/api/addons/vacay/years', () => {
|
|
return HttpResponse.json({ years: [2025, 2026, 2027] });
|
|
}),
|
|
|
|
http.delete('/api/addons/vacay/years/:year', () => {
|
|
return HttpResponse.json({ years: [2025] });
|
|
}),
|
|
|
|
http.get('/api/addons/vacay/entries/:year', () => {
|
|
return HttpResponse.json({
|
|
entries: [
|
|
{ date: '2025-06-15', user_id: 1 },
|
|
{ date: '2025-06-16', user_id: 1 },
|
|
],
|
|
companyHolidays: [],
|
|
});
|
|
}),
|
|
|
|
http.post('/api/addons/vacay/entries/toggle', () => {
|
|
return HttpResponse.json({ success: true });
|
|
}),
|
|
|
|
http.post('/api/addons/vacay/entries/company-holiday', () => {
|
|
return HttpResponse.json({ success: true });
|
|
}),
|
|
|
|
http.get('/api/addons/vacay/stats/:year', () => {
|
|
return HttpResponse.json({
|
|
stats: [{ user_id: 1, vacation_days: 30, used: 2 }],
|
|
});
|
|
}),
|
|
|
|
http.put('/api/addons/vacay/stats/:year', () => {
|
|
return HttpResponse.json({ success: true });
|
|
}),
|
|
|
|
http.get('/api/addons/vacay/holidays/countries', () => {
|
|
return HttpResponse.json({ countries: ['DE', 'US', 'FR'] });
|
|
}),
|
|
|
|
http.get('/api/addons/vacay/holidays/:year/:country', () => {
|
|
return HttpResponse.json([
|
|
{ date: '2025-12-25', name: 'Christmas', localName: 'Weihnachten', global: true, counties: null },
|
|
{ date: '2025-01-01', name: 'New Year', localName: 'Neujahr', global: true, counties: null },
|
|
]);
|
|
}),
|
|
|
|
http.get('/api/addons/vacay/school-holidays/regions/:country', () => {
|
|
return HttpResponse.json({
|
|
groups: [
|
|
{ code: 'NL-NO', shortName: 'NO', name: [{ language: 'EN', text: 'Northern Region' }] },
|
|
{ code: 'NL-MI', shortName: 'MI', name: [{ language: 'EN', text: 'Central Region' }] },
|
|
{ code: 'NL-ZU', shortName: 'ZU', name: [{ language: 'EN', text: 'Southern Region' }] },
|
|
],
|
|
subdivisions: [],
|
|
});
|
|
}),
|
|
|
|
contractHandler('put', '/api/addons/vacay/color', { request: vacaySetColorRequestSchema }, () =>
|
|
HttpResponse.json({ success: true })
|
|
),
|
|
|
|
http.post('/api/addons/vacay/invite', () => {
|
|
return HttpResponse.json({ success: true });
|
|
}),
|
|
|
|
http.post('/api/addons/vacay/invite/accept', () => {
|
|
return HttpResponse.json({ success: true });
|
|
}),
|
|
|
|
http.post('/api/addons/vacay/invite/decline', () => {
|
|
return HttpResponse.json({ success: true });
|
|
}),
|
|
|
|
http.post('/api/addons/vacay/invite/cancel', () => {
|
|
return HttpResponse.json({ success: true });
|
|
}),
|
|
|
|
http.post('/api/addons/vacay/dissolve', () => {
|
|
return HttpResponse.json({ success: true });
|
|
}),
|
|
|
|
http.post('/api/addons/vacay/plan/holiday-calendars', () => {
|
|
return HttpResponse.json({
|
|
calendar: { id: 1, plan_id: 1, region: 'DE', label: null, color: '#ef4444', sort_order: 0 },
|
|
});
|
|
}),
|
|
|
|
http.put('/api/addons/vacay/plan/holiday-calendars/:id', () => {
|
|
return HttpResponse.json({
|
|
calendar: { id: 1, plan_id: 1, region: 'US', label: 'US Holidays', color: '#3b82f6', sort_order: 0 },
|
|
});
|
|
}),
|
|
|
|
http.delete('/api/addons/vacay/plan/holiday-calendars/:id', () => {
|
|
return HttpResponse.json({ success: true });
|
|
}),
|
|
|
|
http.get('/api/addons/vacay/shares', () => {
|
|
return HttpResponse.json({ outgoing: [], incoming: [] });
|
|
}),
|
|
|
|
http.post('/api/addons/vacay/shares', () => {
|
|
return HttpResponse.json({ success: true });
|
|
}),
|
|
|
|
http.get('/api/addons/vacay/shares/available-users', () => {
|
|
return HttpResponse.json({ users: [] });
|
|
}),
|
|
|
|
http.get('/api/addons/vacay/shares/calendars/:year', () => {
|
|
return HttpResponse.json({ calendars: [] });
|
|
}),
|
|
|
|
http.put('/api/addons/vacay/shares/:id', () => {
|
|
return HttpResponse.json({ success: true });
|
|
}),
|
|
|
|
http.delete('/api/addons/vacay/shares/:id', () => {
|
|
return HttpResponse.json({ success: true });
|
|
}),
|
|
];
|