Scheduling infrastructure for absolutely everyone.
Fixing en error case for invalid eventTypeId
Leo Giovanetti70b9969fe390
diff --git a/pages/api/bookings/_post.ts b/pages/api/bookings/_post.tsindex 2509c24540d..da7d473d396 100644--- a/pages/api/bookings/_post.ts+++ b/pages/api/bookings/_post.ts@@ -64,14 +64,15 @@ async function handler(const eventTypeDb = await prisma.eventType.findUnique({where: { id: booking.eventTypeId },});+ if (!eventTypeDb) throw new HttpError({ statusCode: 400, message: "Invalid eventTypeId." });const eventType = schemaEventTypeReadPublic.parse(eventTypeDb);let bookings: z.infer<typeof schemaBookingReadPublic>[];if (!eventType) throw new HttpError({ statusCode: 400, message: "Could not create new booking" });if (eventType.recurringEvent) {console.log("Event type has recurring configuration");- if (!booking.recurringCount) throw new HttpError({ statusCode: 400, message: "Missing recurringCount" });+ if (!booking.recurringCount) throw new HttpError({ statusCode: 400, message: "Missing recurringCount." });if (eventType.recurringEvent.count && booking.recurringCount > eventType?.recurringEvent.count) {- throw new HttpError({ statusCode: 400, message: "Invalid recurringCount" });+ throw new HttpError({ statusCode: 400, message: "Invalid recurringCount." });}// Event type is recurring, ceating each bookingconst recurringEventId = uuidv4();diff --git a/test/lib/bookings/_post.test.ts b/test/lib/bookings/_post.test.tsindex 5fc57e5c9d0..1fc3d0d1080 100644--- a/test/lib/bookings/_post.test.ts+++ b/test/lib/bookings/_post.test.ts@@ -28,7 +28,8 @@ describe("POST /api/bookings", () => {expect(res._getStatusCode()).toBe(400);expect(JSON.parse(res._getData())).toEqual(expect.objectContaining({- message: "Booking body is invalid.",+ message:+ "'invalid_type' in 'eventTypeId': Required; 'invalid_type' in 'title': Required; 'invalid_type' in 'startTime': Required; 'invalid_type' in 'startTime': Required; 'invalid_type' in 'endTime': Required; 'invalid_type' in 'endTime': Required",}));});@@ -45,7 +46,7 @@ describe("POST /api/bookings", () => {prisma,});- //prismaMock.eventType.findUnique.mockResolvedValue(null);+ prismaMock.eventType.findUnique.mockResolvedValue(null);await handler(req, res);