fix(trips): count trip dates in calendar days, the same on REST and MCP

Filling in a missing end date and keeping a trip's length when its start
moved both shifted a local-time Date, so a trip crossing a DST change
lost or gained a day. Both now use addIsoDays. The one-date-makes-a-week
default moves from the REST controller into TripsService.create, so the
MCP create_trip tool no longer stores a half-dated trip, and the trip and
its days are written in one transaction.
This commit is contained in:
Maurice
2026-10-07 16:11:41 +02:00
parent bfa512589c
commit e0aedbb2c6
6 changed files with 65 additions and 29 deletions
@@ -161,10 +161,10 @@ describe('TripsController (parity with the legacy /api/trips route)', async () =
expect(tripCreateRequestSchema.safeParse({ title: '' }).success).toBe(false);
});
it('infers end_date from start_date (+6 days) and creates', async () => {
it('passes a single start date on as it is; the service fills in the week', async () => {
const create = vi.fn().mockReturnValue({ trip: { id: 9 }, tripId: 9, reminderDays: 0 });
await tc(svc({ create } as Partial<TripsService>)).create(user, { title: 'T', start_date: '2026-07-01' }, req);
expect(create).toHaveBeenCalledWith(1, expect.objectContaining({ start_date: '2026-07-01', end_date: '2026-07-07' }));
expect(create).toHaveBeenCalledWith(1, expect.objectContaining({ start_date: '2026-07-01', end_date: null }));
});
it('400 when end_date precedes start_date', async () => {
@@ -173,10 +173,10 @@ describe('TripsController (parity with the legacy /api/trips route)', async () =
});
});
it('infers start_date from end_date (-6 days) and parses day_count', async () => {
it('passes a single end date on as it is and parses day_count', async () => {
const create = vi.fn().mockReturnValue({ trip: { id: 9 }, tripId: 9, reminderDays: 0 });
await tc(svc({ create } as Partial<TripsService>)).create(user, prePipeCreateBody({ title: 'T', end_date: '2026-07-07', day_count: '40' }), req);
expect(create).toHaveBeenCalledWith(1, expect.objectContaining({ start_date: '2026-07-01', end_date: '2026-07-07', day_count: 40 }));
expect(create).toHaveBeenCalledWith(1, expect.objectContaining({ start_date: null, end_date: '2026-07-07', day_count: 40 }));
});
it('clamps a non-numeric day_count to the default of 7', async () => {