Skip to content

Commit

Permalink
Added deadline for overnight same day reservations
Browse files Browse the repository at this point in the history
Normal users can't reserver same day after overnight start time. Admins can bypass this deadline.
  • Loading branch information
SanttuA committed May 21, 2024
1 parent e3439f7 commit 154703b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 6 deletions.
2 changes: 2 additions & 0 deletions app/shared/overnight-calendar/OvernightCalendar.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ function OvernightCalendar({
reservations: filteredReservations,
minPeriod,
hasAdminBypass: isUnitManagerOrHigher,
overnightStartTime,
});

if (!reservingIsAllowed) {
Expand Down Expand Up @@ -222,6 +223,7 @@ function OvernightCalendar({
reservations: filteredReservations,
minPeriod,
hasAdminBypass: isUnitManagerOrHigher,
overnightStartTime,
})}
enableOutsideDays
firstDayOfWeek={1}
Expand Down
6 changes: 4 additions & 2 deletions app/shared/overnight-calendar/overnightUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,15 @@ export function handleDateSelect({
* @param {Object[]} params.openingHours
* @param {Object[]} params.reservations
* @param {boolean} params.hasAdminBypass
* @param {string} params.overnightStartTime
* @returns {boolean} is day disabled
*/
export function handleDisableDays({
day, now, reservable, reservableAfter, reservableBefore,
openingHours, reservations, hasAdminBypass
openingHours, reservations, hasAdminBypass, overnightStartTime
}) {
const isAfterToday = now.isAfter(day, 'day');
const startTimedDay = setDatesTime(day, overnightStartTime).toDate();
const isAfterToday = hasAdminBypass ? now.isAfter(day, 'day') : now.isAfter(startTimedDay);
const beforeDate = reservableAfter || moment();
const isBeforeDate = moment(day).isBefore(beforeDate, 'day');
const afterDate = reservableBefore || moment().add(1, 'year');
Expand Down
42 changes: 38 additions & 4 deletions app/shared/overnight-calendar/tests/overnightUtils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ describe('app/shared/overnight-calendar/overnightUtils', () => {
});

describe('handleDisableDays', () => {
const now = moment('2024-04-20');
const now = moment('2024-04-20T05:00:00+03:00');
const day = now.toDate();
const reservable = true;
const reservableAfter = '2024-04-19T00:00:00+03:00';
Expand All @@ -151,6 +151,7 @@ describe('app/shared/overnight-calendar/overnightUtils', () => {
const reservations = [
Reservation.build({ begin: '2024-04-22T13:00:00+03:00', end: '2024-04-24T09:00:00+03:00' })
];
const overnightStartTime = '09:00:00';

const hasAdminBypass = false;
const params = {
Expand All @@ -161,11 +162,34 @@ describe('app/shared/overnight-calendar/overnightUtils', () => {
reservableBefore,
openingHours,
reservations,
hasAdminBypass
hasAdminBypass,
overnightStartTime
};

test('returns false with correct params', () => {
expect(handleDisableDays(params)).toBe(false);
describe('returns false when', () => {
test('using with correct params', () => {
expect(handleDisableDays(params)).toBe(false);
});

test('non admin tries to reserve same day before overnight start time', () => {
expect(handleDisableDays(
{
...params,
hasAdminBypass: false,
overnightStartTime: '10:00:00'
}
)).toBe(false);
});

test('admin tries to reserve same day after overnight start time', () => {
expect(handleDisableDays(
{
...params,
hasAdminBypass: true,
overnightStartTime: '01:00:00'
}
)).toBe(false);
});
});

describe('returns true when', () => {
Expand All @@ -184,6 +208,16 @@ describe('app/shared/overnight-calendar/overnightUtils', () => {
)).toBe(true);
});

test('non admin tries to reserve same day after overnight start time', () => {
expect(handleDisableDays(
{
...params,
hasAdminBypass: false,
overnightStartTime: '01:00:00'
}
)).toBe(true);
});

test('day is before reservable after limit', () => {
expect(handleDisableDays(
{
Expand Down

0 comments on commit 154703b

Please sign in to comment.