Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion packages/features/bookings/lib/getBookingToDelete.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { HttpError } from "@calcom/lib/http-error";
import prisma, { bookingMinimalSelect } from "@calcom/prisma";
import { credentialForCalendarServiceSelect } from "@calcom/prisma/selects/credential";

export async function getBookingToDelete(id: number | undefined, uid: string | undefined) {
return await prisma.booking.findUniqueOrThrow({
const booking = await prisma.booking.findUnique({
where: {
id,
uid,
Expand Down Expand Up @@ -111,6 +112,12 @@ export async function getBookingToDelete(id: number | undefined, uid: string | u
status: true,
},
});

if (!booking) {
throw new HttpError({ statusCode: 404, message: "Booking not found" });
}
Comment thread
yashs33244 marked this conversation as resolved.

return booking;
}

export type BookingToDelete = Awaited<ReturnType<typeof getBookingToDelete>>;
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,22 @@ describe("Cancel Booking", () => {
).rejects.toThrow("Cannot cancel a booking that has already ended");
});

test("Should throw HttpError 404 when booking does not exist", async () => {
const handleCancelBooking = (await import("@calcom/features/bookings/lib/handleCancelBooking")).default;

await expect(
handleCancelBooking({
bookingData: {
uid: "non-existent-booking-uid",
cancelledBy: "[email protected]",
},
})
).rejects.toMatchObject({
statusCode: 404,
message: "Booking not found",
});
});

test("Should block canceling bookings without a cancellation reason when cancelledBy is set to the host", async () => {
const handleCancelBooking = (await import("@calcom/features/bookings/lib/handleCancelBooking")).default;

Expand Down
Loading