Test: when merging more than available seats, then fail

This commit is contained in:
Joe Au-Yeung 2024-01-04 16:38:41 -05:00
parent 294152dc58
commit 27b04fb03a

View File

@ -1494,6 +1494,185 @@ describe("handleSeats", () => {
expect(originalBooking?.status).toEqual(BookingStatus.CANCELLED);
});
test("When merging more attendees than seats, fail ", 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: plus1DateString } = getDate({ dateIncrement: 1 });
const firstBookingStartTime = `${plus1DateString}T04:00:00.00Z`;
const firstBookingUid = "abc123";
const firstBookingId = 1;
const secondBookingUid = "def456";
const secondBookingId = 2;
const { dateString: plus2DateString } = getDate({ dateIncrement: 2 });
const secondBookingStartTime = `${plus2DateString}T04:00:00Z`;
const secondBookingEndTime = `${plus2DateString}T05:15:00Z`;
await createBookingScenario(
getScenarioData({
eventTypes: [
{
id: firstBookingId,
slug: "seated-event",
slotInterval: 45,
length: 45,
users: [
{
id: 101,
},
],
seatsPerTimeSlot: 3,
seatsShowAttendees: false,
},
],
bookings: [
{
id: 1,
uid: firstBookingUid,
eventTypeId: 1,
userId: organizer.id,
status: BookingStatus.ACCEPTED,
startTime: firstBookingStartTime,
endTime: secondBookingEndTime,
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: "seat1@test.com",
locale: "en",
timeZone: "America/Toronto",
bookingSeat: {
referenceUid: "booking-seat-1",
data: {},
},
}),
getMockBookingAttendee({
id: 2,
name: "Seat 2",
email: "seat2@test.com",
locale: "en",
timeZone: "America/Toronto",
bookingSeat: {
referenceUid: "booking-seat-2",
data: {},
},
}),
],
},
{
id: secondBookingId,
uid: secondBookingUid,
eventTypeId: 1,
status: BookingStatus.ACCEPTED,
startTime: secondBookingStartTime,
endTime: secondBookingEndTime,
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: 3,
name: "Seat 3",
email: "seat3@test.com",
locale: "en",
timeZone: "America/Toronto",
bookingSeat: {
referenceUid: "booking-seat-3",
data: {},
},
}),
getMockBookingAttendee({
id: 4,
name: "Seat 4",
email: "seat4@test.com",
locale: "en",
timeZone: "America/Toronto",
bookingSeat: {
referenceUid: "booking-seat-4",
data: {},
},
}),
],
},
],
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;
// const rescheduledBooking = await handleNewBooking(req);
await expect(() => handleNewBooking(req)).rejects.toThrowError(
"Booking does not have enough available seats"
);
});
});
});
});