forked from calcom/cal.com
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: event api accepts invalid start & end values (calcom#13203)
* fix: event api accepts invalid start & end values * fix: unit tests * test: added 'event length check during booking' * test: fix unit test --------- Co-authored-by: Keith Williams <[email protected]>
- Loading branch information
1 parent
da026d9
commit 95e037c
Showing
6 changed files
with
288 additions
and
207 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,8 +120,8 @@ describe("handleNewBooking", () => { | |
eventTypes: [ | ||
{ | ||
id: 1, | ||
slotInterval: 45, | ||
length: 45, | ||
slotInterval: 30, | ||
length: 30, | ||
users: [ | ||
{ | ||
id: 101, | ||
|
@@ -285,8 +285,8 @@ describe("handleNewBooking", () => { | |
eventTypes: [ | ||
{ | ||
id: 1, | ||
slotInterval: 45, | ||
length: 45, | ||
slotInterval: 30, | ||
length: 30, | ||
users: [ | ||
{ | ||
id: 101, | ||
|
@@ -448,8 +448,8 @@ describe("handleNewBooking", () => { | |
eventTypes: [ | ||
{ | ||
id: 1, | ||
slotInterval: 45, | ||
length: 45, | ||
slotInterval: 30, | ||
length: 30, | ||
users: [ | ||
{ | ||
id: 101, | ||
|
@@ -603,8 +603,8 @@ describe("handleNewBooking", () => { | |
eventTypes: [ | ||
{ | ||
id: 1, | ||
slotInterval: 45, | ||
length: 45, | ||
slotInterval: 30, | ||
length: 30, | ||
users: [ | ||
{ | ||
id: 101, | ||
|
@@ -724,8 +724,8 @@ describe("handleNewBooking", () => { | |
eventTypes: [ | ||
{ | ||
id: 1, | ||
slotInterval: 45, | ||
length: 45, | ||
slotInterval: 30, | ||
length: 30, | ||
users: [ | ||
{ | ||
id: 101, | ||
|
@@ -889,8 +889,8 @@ describe("handleNewBooking", () => { | |
eventTypes: [ | ||
{ | ||
id: 1, | ||
slotInterval: 45, | ||
length: 45, | ||
slotInterval: 30, | ||
length: 30, | ||
users: [ | ||
{ | ||
id: 101, | ||
|
@@ -1023,8 +1023,8 @@ describe("handleNewBooking", () => { | |
eventTypes: [ | ||
{ | ||
id: 1, | ||
slotInterval: 45, | ||
length: 45, | ||
slotInterval: 30, | ||
length: 30, | ||
users: [ | ||
{ | ||
id: 101, | ||
|
@@ -1111,8 +1111,8 @@ describe("handleNewBooking", () => { | |
eventTypes: [ | ||
{ | ||
id: 1, | ||
slotInterval: 45, | ||
length: 45, | ||
slotInterval: 30, | ||
length: 30, | ||
users: [ | ||
{ | ||
id: 101, | ||
|
@@ -1167,6 +1167,66 @@ describe("handleNewBooking", () => { | |
); | ||
}); | ||
|
||
describe("Event length check during booking", () => { | ||
test( | ||
`should fail if the time difference between a booking's start and end times is not equal to the event length.`, | ||
async () => { | ||
const handleNewBooking = (await import("@calcom/features/bookings/lib/handleNewBooking")).default; | ||
|
||
const booker = getBooker({ | ||
email: "[email protected]", | ||
name: "Booker", | ||
}); | ||
|
||
const organizer = getOrganizer({ | ||
name: "Organizer", | ||
email: "[email protected]", | ||
id: 101, | ||
schedules: [TestData.schedules.IstWorkHours], | ||
}); | ||
|
||
await createBookingScenario( | ||
getScenarioData({ | ||
eventTypes: [ | ||
{ | ||
id: 1, | ||
slotInterval: 30, | ||
length: 30, | ||
users: [ | ||
{ | ||
id: 101, | ||
}, | ||
], | ||
}, | ||
], | ||
organizer, | ||
}) | ||
); | ||
|
||
const mockBookingData = getMockRequestDataForBooking({ | ||
data: { | ||
start: `${getDate({ dateIncrement: 1 }).dateString}T05:00:00.000Z`, | ||
end: `${getDate({ dateIncrement: 1 }).dateString}T05:15:00.000Z`, | ||
eventTypeId: 1, | ||
responses: { | ||
email: booker.email, | ||
name: booker.name, | ||
location: { optionValue: "", value: "New York" }, | ||
}, | ||
}, | ||
}); | ||
|
||
const { req } = createMockNextJsRequest({ | ||
method: "POST", | ||
body: mockBookingData, | ||
}); | ||
|
||
await expect(async () => await handleNewBooking(req)).rejects.toThrowError("Invalid event length"); | ||
}, | ||
timeout | ||
); | ||
}); | ||
|
||
describe( | ||
"Availability Check during booking", | ||
() => { | ||
|
@@ -1196,8 +1256,8 @@ describe("handleNewBooking", () => { | |
eventTypes: [ | ||
{ | ||
id: 1, | ||
slotInterval: 45, | ||
length: 45, | ||
slotInterval: 30, | ||
length: 30, | ||
users: [ | ||
{ | ||
id: 101, | ||
|
@@ -1212,7 +1272,7 @@ describe("handleNewBooking", () => { | |
userId: 101, | ||
status: BookingStatus.ACCEPTED, | ||
startTime: `${plus1DateString}T05:00:00.000Z`, | ||
endTime: `${plus1DateString}T05:15:00.000Z`, | ||
endTime: `${plus1DateString}T05:30:00.000Z`, | ||
}, | ||
], | ||
organizer, | ||
|
@@ -1221,7 +1281,7 @@ describe("handleNewBooking", () => { | |
|
||
const mockBookingData = getMockRequestDataForBooking({ | ||
data: { | ||
start: `${getDate({ dateIncrement: 1 }).dateString}T04:00:00.000Z`, | ||
start: `${getDate({ dateIncrement: 1 }).dateString}T05:00:00.000Z`, | ||
end: `${getDate({ dateIncrement: 1 }).dateString}T05:30:00.000Z`, | ||
eventTypeId: 1, | ||
responses: { | ||
|
@@ -1279,8 +1339,8 @@ describe("handleNewBooking", () => { | |
eventTypes: [ | ||
{ | ||
id: 1, | ||
slotInterval: 45, | ||
length: 45, | ||
slotInterval: 30, | ||
length: 30, | ||
users: [ | ||
{ | ||
id: 101, | ||
|
@@ -1308,7 +1368,7 @@ describe("handleNewBooking", () => { | |
|
||
const mockBookingData = getMockRequestDataForBooking({ | ||
data: { | ||
start: `${getDate({ dateIncrement: 1 }).dateString}T04:00:00.000Z`, | ||
start: `${getDate({ dateIncrement: 1 }).dateString}T05:00:00.000Z`, | ||
end: `${getDate({ dateIncrement: 1 }).dateString}T05:30:00.000Z`, | ||
eventTypeId: 1, | ||
responses: { | ||
|
@@ -1380,9 +1440,9 @@ describe("handleNewBooking", () => { | |
eventTypes: [ | ||
{ | ||
id: 1, | ||
slotInterval: 45, | ||
slotInterval: 30, | ||
requiresConfirmation: true, | ||
length: 45, | ||
length: 30, | ||
users: [ | ||
{ | ||
id: 101, | ||
|
@@ -1506,9 +1566,9 @@ describe("handleNewBooking", () => { | |
eventTypes: [ | ||
{ | ||
id: 1, | ||
slotInterval: 45, | ||
slotInterval: 30, | ||
requiresConfirmation: true, | ||
length: 45, | ||
length: 30, | ||
users: [ | ||
{ | ||
id: 101, | ||
|
@@ -1630,15 +1690,15 @@ describe("handleNewBooking", () => { | |
eventTypes: [ | ||
{ | ||
id: 1, | ||
slotInterval: 45, | ||
slotInterval: 30, | ||
requiresConfirmation: true, | ||
metadata: { | ||
requiresConfirmationThreshold: { | ||
time: 30, | ||
unit: "minutes", | ||
}, | ||
}, | ||
length: 45, | ||
length: 30, | ||
users: [ | ||
{ | ||
id: 101, | ||
|
@@ -1762,15 +1822,15 @@ describe("handleNewBooking", () => { | |
eventTypes: [ | ||
{ | ||
id: 1, | ||
slotInterval: 45, | ||
slotInterval: 30, | ||
requiresConfirmation: true, | ||
metadata: { | ||
requiresConfirmationThreshold: { | ||
time: 120, | ||
unit: "hours", | ||
}, | ||
}, | ||
length: 45, | ||
length: 30, | ||
users: [ | ||
{ | ||
id: 101, | ||
|
@@ -1856,8 +1916,8 @@ describe("handleNewBooking", () => { | |
eventTypes: [ | ||
{ | ||
id: 1, | ||
slotInterval: 45, | ||
length: 45, | ||
slotInterval: 30, | ||
length: 30, | ||
users: [ | ||
{ | ||
id: 101, | ||
|
@@ -1968,8 +2028,8 @@ describe("handleNewBooking", () => { | |
eventTypes: [ | ||
{ | ||
id: 1, | ||
slotInterval: 45, | ||
length: 45, | ||
slotInterval: 30, | ||
length: 30, | ||
users: [ | ||
{ | ||
id: 101, | ||
|
@@ -2076,7 +2136,7 @@ describe("handleNewBooking", () => { | |
id: 1, | ||
title: "Paid Event", | ||
description: "It's a test Paid Event", | ||
slotInterval: 45, | ||
slotInterval: 30, | ||
requiresConfirmation: false, | ||
metadata: { | ||
apps: { | ||
|
@@ -2088,7 +2148,7 @@ describe("handleNewBooking", () => { | |
}, | ||
}, | ||
}, | ||
length: 45, | ||
length: 30, | ||
users: [ | ||
{ | ||
id: 101, | ||
|
@@ -2233,7 +2293,7 @@ describe("handleNewBooking", () => { | |
eventTypes: [ | ||
{ | ||
id: 1, | ||
slotInterval: 45, | ||
slotInterval: 30, | ||
requiresConfirmation: true, | ||
metadata: { | ||
apps: { | ||
|
@@ -2244,7 +2304,7 @@ describe("handleNewBooking", () => { | |
}, | ||
}, | ||
}, | ||
length: 45, | ||
length: 30, | ||
users: [ | ||
{ | ||
id: 101, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.