Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed an issue where users could skip cooldown #324

Merged
merged 1 commit into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions app/utils/__tests__/timeUtils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -554,24 +554,28 @@ describe('Utils: timeUtils', () => {
{
begin: '2015-10-09T10:00:00+03:00',
end: '2015-10-09T11:00:00+03:00',
id: 111,
},
];
let twoReservations = [
{
begin: '2015-10-09T09:00:00+03:00',
end: '2015-10-09T10:00:00+03:00',
isOwn: false,
id: 112
},
{
begin: '2015-10-09T11:00:00+03:00',
end: '2015-10-09T12:00:00+03:00',
isOwn: true,
id: 113
}
];
const reservationsToEdit = [
{
begin: '2015-10-09T08:30:00+03:00',
end: '2015-10-09T09:30:00+03:00',
id: 123
},
];
test('is always false when cooldown is not set or it is 0', () => {
Expand Down Expand Up @@ -621,10 +625,10 @@ describe('Utils: timeUtils', () => {
expect(slots[1].onCooldown).toBe(false);
expect(slots[2].onCooldown).toBe(true);
expect(slots[3].onCooldown).toBe(false);
expect(slots[4].onCooldown).toBe(false);
expect(slots[4].onCooldown).toBe(true);
});

test('is true when editing with two reservations, !isOwn reservations cooldown remains', () => {
test('is true when editing with two reservations', () => {
const cooldown = '1:00:00';
twoReservations = [
{
Expand All @@ -649,7 +653,7 @@ describe('Utils: timeUtils', () => {
expect(slots[0].onCooldown).toBe(false);
expect(slots[1].onCooldown).toBe(true);
expect(slots[2].onCooldown).toBe(false);
expect(slots[3].onCooldown).toBe(false);
expect(slots[3].onCooldown).toBe(true);
expect(slots[4].onCooldown).toBe(false);
});

Expand Down
7 changes: 4 additions & 3 deletions app/utils/timeUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,8 @@ function getTimeSlots(
The cooldown slots get a reservation but are NOT set as reserved.

When editing a reservation,
the cooldown slots that ONLY have the users reservation are false.
If a cooldown slots reservation is NOT
the cooldown slots that ONLY have the users currently selected reservation
to edit are false. If a cooldown slots reservation is NOT
the users or its shared with another reservation it remains true.
*/
const isEditing = Boolean(reservationsToEdit.length);
Expand All @@ -181,7 +181,8 @@ function getTimeSlots(
reservation.push(reservations[index]);

if (isEditing) {
if (reservation.some(res => !res.isOwn)) {
const resToEditId = reservationsToEdit[0]?.id;
if (reservation.some(res => res.id !== resToEditId)) {
onCooldown = true;
} else {
onCooldown = false;
Expand Down
Loading