fix(db): find no nearest day for a date the calendar does not have

The nearest-day fallback of a booking's time cast the bound date to a
timestamp on Postgres, which refuses 2024-02-30 with a 500, while SQLite's
JULIANDAY rolled it over into March and placed the booking there.
dayDistance now refuses anything but a calendar date on both engines
(isCalendarDate), so a caller that forgets the check fails on SQLite too,
and findNearestDayId answers no day for such a date. The size baseline of
Reservations.repository.ts drops by one line.
This commit is contained in:
Maurice
2026-11-17 21:23:31 +01:00
parent 1b216d8f48
commit 143e2ae447
5 changed files with 63 additions and 6 deletions
@@ -226,6 +226,20 @@ describe('Update reservation', () => {
expect(res.body.reservation.end_day_id).toBe(day3.id);
});
it('RESV-004d — a reservation_time on a date the calendar does not have lands on no day, on every engine', async () => {
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);
await makeDay(orm, trip.id, { date: '2024-03-01' });
// SQLite's JULIANDAY rolls 2024-02-30 over into March; Postgres refuses to cast it.
const res = await request(app)
.post(`/api/trips/${trip.id}/reservations`)
.set('Cookie', authCookie(user.id))
.send({ title: 'Event', type: 'event', reservation_time: '2024-02-30T10:00' });
expect(res.status).toBe(201);
expect(res.body.reservation.day_id).toBeNull();
});
it('RESV-004 — PUT on non-existent reservation returns 404', async () => {
const { user } = await makeUser(orm);
const trip = await makeTrip(orm, user.id);