diff --git a/src/reservations/entity.ts b/src/reservations/entity.ts index fff32fc..5c06821 100644 --- a/src/reservations/entity.ts +++ b/src/reservations/entity.ts @@ -80,7 +80,11 @@ export class Reservation { */ @Exclude() public isAvailableForReservation(): boolean { - return this.dateRangeStart.diff(dayjs(), 'hour') <= 7 * 24 + const maxDateToReserve = dayjs() + .add(7, 'day') + .set('hour', 23) + .set('minute', 59) + return this.dateRangeStart.isBefore(maxDateToReserve) } /** diff --git a/test/unit/reservations/entity.spec.ts b/test/unit/reservations/entity.spec.ts new file mode 100644 index 0000000..ac38d6c --- /dev/null +++ b/test/unit/reservations/entity.spec.ts @@ -0,0 +1,19 @@ +import dayjs from '../../../src/common/dayjs' +import { Reservation } from '../../../src/reservations/entity' + +describe('reservations.entity', () => { + describe('isAvailableForReservation', () => { + it.each([ + { dateRangeStart: dayjs().add(7, 'day').set('hour', 23), result: true }, + { dateRangeStart: dayjs().subtract(1, 'day'), result: true }, + { dateRangeStart: dayjs(), result: true }, + { dateRangeStart: dayjs().add(8, 'day'), result: false }, + ])( + 'should handle reservation starting at $dateRangeStart and return $result', + ({ dateRangeStart, result }) => { + const r = new Reservation({ dateRangeStart }) + expect(r.isAvailableForReservation()).toBe(result) + }, + ) + }) +})