Owner rescheduling, merge two bookings together
This commit is contained in:
parent
6fc8a65892
commit
294152dc58
|
@ -1142,8 +1142,6 @@ describe("handleSeats", () => {
|
|||
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`;
|
||||
|
@ -1285,6 +1283,217 @@ describe("handleSeats", () => {
|
|||
|
||||
expect(bookingSeats).toHaveLength(3);
|
||||
});
|
||||
|
||||
test("When rescheduling to existing booking, merge attendees ", 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: 4,
|
||||
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);
|
||||
|
||||
// Ensure that the booking has been moved
|
||||
expect(rescheduledBooking?.startTime).toEqual(secondBookingStartTime);
|
||||
expect(rescheduledBooking?.endTime).toEqual(secondBookingEndTime);
|
||||
|
||||
// Ensure that the attendees are still a part of the event
|
||||
const attendees = await prismaMock.attendee.findMany({
|
||||
where: {
|
||||
bookingId: rescheduledBooking?.id,
|
||||
},
|
||||
});
|
||||
|
||||
expect(attendees).toHaveLength(4);
|
||||
|
||||
// Ensure that the bookingSeats are still a part of the event
|
||||
const bookingSeats = await prismaMock.bookingSeat.findMany({
|
||||
where: {
|
||||
bookingId: rescheduledBooking?.id,
|
||||
},
|
||||
});
|
||||
|
||||
expect(bookingSeats).toHaveLength(4);
|
||||
|
||||
// Ensure that the previous booking has been canceled
|
||||
const originalBooking = await prismaMock.booking.findFirst({
|
||||
where: {
|
||||
id: firstBookingId,
|
||||
},
|
||||
select: {
|
||||
status: true,
|
||||
},
|
||||
});
|
||||
|
||||
expect(originalBooking?.status).toEqual(BookingStatus.CANCELLED);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue
Block a user