fix: Disable cancel button for past bookings (#22667)
* fix: Remove cancel button for past bookings * fix types and few improvements * add proper tests for backend changes * chore * Update [bookingUid].tsx * Update bookings-single-view.tsx * remove comment * Update tests --------- Co-authored-by: Kartik Saini <[email protected]> Co-authored-by: Anik Dhabal Babu <[email protected]>
This commit is contained in:
6 files changed
+135
-3
No files matched your search
@@ -120,6 +120,13 @@ async function handler(input: CancelBookingInput) {
|
||||
});
|
||||
}
|
||||
|
||||
if (bookingToDelete.endTime && new Date() > new Date(bookingToDelete.endTime)) {
|
||||
throw new HttpError({
|
||||
statusCode: 400,
|
||||
message: "Cannot cancel a booking that has already ended",
|
||||
});
|
||||
}
|
||||
|
||||
// If the booking is a seated event and there is no seatReferenceUid we should validate that logged in user is host
|
||||
if (bookingToDelete.eventType?.seatsPerTimeSlot && !seatReferenceUid) {
|
||||
const userIsHost = bookingToDelete.eventType.hosts.find((host) => {
|
||||
|
||||
@@ -420,4 +420,73 @@ describe("Cancel Booking", () => {
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
test("Should block cancelling past bookings", async () => {
|
||||
const handleCancelBooking = (await import("@calcom/features/bookings/lib/handleCancelBooking")).default;
|
||||
|
||||
const booker = getBooker({
|
||||
email: "[email protected]",
|
||||
name: "Booker",
|
||||
});
|
||||
|
||||
const organizer = getOrganizer({
|
||||
name: "Organizer",
|
||||
email: "[email protected]",
|
||||
id: 101,
|
||||
schedules: [TestData.schedules.IstWorkHours],
|
||||
credentials: [getGoogleCalendarCredential()],
|
||||
selectedCalendars: [TestData.selectedCalendars.google],
|
||||
});
|
||||
|
||||
const uidOfBookingToBeCancelled = "past-booking";
|
||||
const idOfBookingToBeCancelled = 3040;
|
||||
const { dateString: minus1DateString } = getDate({ dateIncrement: -1 });
|
||||
|
||||
await createBookingScenario(
|
||||
getScenarioData({
|
||||
eventTypes: [
|
||||
{
|
||||
id: 1,
|
||||
slotInterval: 30,
|
||||
length: 30,
|
||||
users: [
|
||||
{
|
||||
id: 101,
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
bookings: [
|
||||
{
|
||||
id: idOfBookingToBeCancelled,
|
||||
uid: uidOfBookingToBeCancelled,
|
||||
eventTypeId: 1,
|
||||
userId: 101,
|
||||
responses: {
|
||||
email: booker.email,
|
||||
name: booker.name,
|
||||
location: { optionValue: "", value: BookingLocations.CalVideo },
|
||||
},
|
||||
status: BookingStatus.ACCEPTED,
|
||||
startTime: `${minus1DateString}T05:00:00.000Z`,
|
||||
endTime: `${minus1DateString}T05:30:00.000Z`,
|
||||
},
|
||||
],
|
||||
organizer,
|
||||
apps: [TestData.apps["daily-video"]],
|
||||
})
|
||||
);
|
||||
|
||||
// This should throw an error with current implementation
|
||||
await expect(
|
||||
handleCancelBooking({
|
||||
bookingData: {
|
||||
id: idOfBookingToBeCancelled,
|
||||
uid: uidOfBookingToBeCancelled,
|
||||
cancelledBy: organizer.email,
|
||||
cancellationReason: "Testing past booking cancellation",
|
||||
},
|
||||
})
|
||||
).rejects.toThrow("Cannot cancel a booking that has already ended");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user