Skip to content

Commit

Permalink
fix: calcom#16150 update to fix seated event reschedule (calcom#16163)
Browse files Browse the repository at this point in the history
* update to fix seated event reschedule

* updated handleseats tests

* updated handleSeats timeslot

* updated test to expect error

* update to remove uid in where clause (isFirstSeat)
  • Loading branch information
vijayraghav-io authored Aug 19, 2024
1 parent d73b841 commit 591d42f
Show file tree
Hide file tree
Showing 2 changed files with 147 additions and 9 deletions.
11 changes: 2 additions & 9 deletions packages/features/bookings/lib/handleNewBooking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -483,15 +483,8 @@ async function handler(
if (eventType.seatsPerTimeSlot) {
const booking = await prisma.booking.findFirst({
where: {
OR: [
{
uid: rescheduleUid || reqBody.bookingUid,
},
{
eventTypeId: eventType.id,
startTime: new Date(dayjs(reqBody.start).utc().format()),
},
],
eventTypeId: eventType.id,
startTime: new Date(dayjs(reqBody.start).utc().format()),
status: BookingStatus.ACCEPTED,
},
});
Expand Down
145 changes: 145 additions & 0 deletions packages/features/bookings/lib/handleSeats/test/handleSeats.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2413,6 +2413,151 @@ describe("handleSeats", () => {
// const rescheduledBooking = await handleNewBooking(req);
await expect(() => handleNewBooking(req)).rejects.toThrowError(ErrorCode.NotEnoughAvailableSeats);
});

test("When trying to reschedule in a non-available slot, throw an error", 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],
});

const firstBookingId = 1;
const firstBookingUid = "abc123";
const { dateString: plus1DateString } = getDate({ dateIncrement: 1 });
const firstBookingStartTime = `${plus1DateString}T04:00:00Z`;
const firstBookingEndTime = `${plus1DateString}T04:30:00Z`;

const { dateString: plus2DateString } = getDate({ dateIncrement: 2 });
// Non-available time slot choosen (7:30PM - 8:00PM IST) while rescheduling
const secondBookingStartTime = `${plus2DateString}T14:00:00Z`;
const secondBookingEndTime = `${plus2DateString}T14:30:00Z`;

await createBookingScenario(
getScenarioData({
eventTypes: [
{
id: 1,
slug: "seated-event",
slotInterval: 30,
length: 30,
users: [
{
id: 101,
},
],
seatsPerTimeSlot: 3,
seatsShowAttendees: false,
},
],
bookings: [
{
id: firstBookingId,
uid: firstBookingUid,
eventTypeId: 1,
userId: organizer.id,
status: BookingStatus.ACCEPTED,
startTime: firstBookingStartTime,
endTime: firstBookingEndTime,
metadata: {
videoCallUrl: "https://existing-daily-video-call-url.example.com",
},
references: [
{
type: appStoreMetadata.dailyvideo.type,
uid: "MOCK_ID",
meetingId: "MOCK_ID",
meetingPassword: "MOCK_PASS",
meetingUrl: "http://mock-dailyvideo.example.com",
credentialId: null,
},
],
attendees: [
getMockBookingAttendee({
id: 1,
name: "Seat 1",
email: "[email protected]",
locale: "en",
timeZone: "America/Toronto",
bookingSeat: {
referenceUid: "booking-seat-1",
data: {},
},
noShow: false,
}),
getMockBookingAttendee({
id: 2,
name: "Seat 2",
email: "[email protected]",
locale: "en",
timeZone: "America/Toronto",
bookingSeat: {
referenceUid: "booking-seat-2",
data: {},
},
noShow: false,
}),
getMockBookingAttendee({
id: 3,
name: "Seat 3",
email: "[email protected]",
locale: "en",
timeZone: "America/Toronto",
bookingSeat: {
referenceUid: "booking-seat-3",
data: {},
},
noShow: false,
}),
],
},
],
organizer,
})
);

mockSuccessfulVideoMeetingCreation({
metadataLookupKey: "dailyvideo",
videoMeetingData: {
id: "MOCK_ID",
password: "MOCK_PASS",
url: `http://mock-dailyvideo.example.com/meeting-1`,
},
});

const reqBookingUser = "seatedAttendee";

const mockBookingData = getMockRequestDataForBooking({
data: {
eventTypeId: 1,
responses: {
email: booker.email,
name: booker.name,
location: { optionValue: "", value: BookingLocations.CalVideo },
},
rescheduleUid: firstBookingUid,
start: secondBookingStartTime,
end: secondBookingEndTime,
user: reqBookingUser,
},
});

const { req } = createMockNextJsRequest({
method: "POST",
body: mockBookingData,
});

req.userId = organizer.id;

await expect(() => handleNewBooking(req)).rejects.toThrowError(ErrorCode.NoAvailableUsersFound);
});
});

describe("Cancelling a booking", () => {
Expand Down

0 comments on commit 591d42f

Please sign in to comment.