Skip to content

Commit

Permalink
fix: buffers in handleNewBooking (#17415)
Browse files Browse the repository at this point in the history
* send missing buffer params

* add tests

---------

Co-authored-by: CarinaWolli <wollencarina@gmail.com>
  • Loading branch information
CarinaWolli and CarinaWolli authored Oct 31, 2024
1 parent f649f8b commit a5806cb
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ export async function ensureAvailableUsers(
returnDateOverrides: false,
dateFrom: startDateTimeUtc.format(),
dateTo: endDateTimeUtc.format(),
beforeEventBuffer: eventType.beforeEventBuffer,
afterEventBuffer: eventType.afterEventBuffer,
},
initialData: {
eventType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ export const getEventTypesFromDB = async (eventTypeId: number) => {
rescheduleWithSameRoundRobinHost: true,
assignAllTeamMembers: true,
isRRWeightsEnabled: true,
beforeEventBuffer: true,
afterEventBuffer: true,
parentId: true,
parent: {
select: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,101 @@ describe("handleNewBooking", () => {
);

describe("Buffers", () => {
test("should throw error when booking is not respecting buffers with event types that have before and after buffer ", async ({}) => {
const handleNewBooking = (await import("@calcom/features/bookings/lib/handleNewBooking")).default;

const booker = getBooker({
email: "booker@example.com",
name: "Booker",
});

const organizer = getOrganizer({
name: "Organizer",
email: "organizer@example.com",
id: 101,
schedules: [TestData.schedules.IstWorkHours],
});

const { dateString: nextDayDateString } = getDate({ dateIncrement: 1 });

await createBookingScenario(
getScenarioData({
eventTypes: [
{
id: 1,
slotInterval: 15,
length: 15,
beforeEventBuffer: 60,
afterEventBuffer: 60,
users: [
{
id: 101,
},
],
},
],
bookings: [
{
eventTypeId: 1,
userId: 101,
status: BookingStatus.ACCEPTED,
startTime: `${nextDayDateString}T07:00:00.000Z`,
endTime: `${nextDayDateString}T07:15:00.000Z`,
},
],
organizer,
})
);

// 7:00 - 7:15 busy
// 6:00 - 7:00 before event buffer
// 5:00 - 6:00 after event buffer
const mockBookingBeforeData = getMockRequestDataForBooking({
data: {
start: `${nextDayDateString}T05:15:00.000Z`,
end: `${nextDayDateString}T05:30:00.000Z`,
eventTypeId: 1,
responses: {
email: booker.email,
name: booker.name,
location: { optionValue: "", value: "New York" },
},
},
});

const { req: reqBookingBefore } = createMockNextJsRequest({
method: "POST",
body: mockBookingBeforeData,
});
await expect(async () => await handleNewBooking(reqBookingBefore)).rejects.toThrowError(
"no_available_users_found_error"
);

// 7:00 - 7:15 busy
// 7:17 - 8:15 after event buffer
// 8:15 - 9:15 before event buffer
const mockBookingAfterData = getMockRequestDataForBooking({
data: {
start: `${nextDayDateString}T09:00:00.000Z`,
end: `${nextDayDateString}T09:15:00.000Z`,
eventTypeId: 1,
responses: {
email: booker.email,
name: booker.name,
location: { optionValue: "", value: "New York" },
},
},
});

const { req: reqBookingAfter } = createMockNextJsRequest({
method: "POST",
body: mockBookingAfterData,
});
await expect(async () => await handleNewBooking(reqBookingAfter)).rejects.toThrowError(
"no_available_users_found_error"
);
});

test(`should throw error when booking is within a before event buffer of an existing booking
`, async ({}) => {
const handleNewBooking = (await import("@calcom/features/bookings/lib/handleNewBooking")).default;
Expand Down

0 comments on commit a5806cb

Please sign in to comment.