fix: Exclude current rescheduled booking from limit (#13870)
* fix: Exclude current rescheduled booking from limit * fix: type check * chore: test for rescheduling during limit
This commit is contained in:
1 parent
af6899d122
commit
28c793c3fe
3 files changed
+72
-2
No files matched your search
@@ -7,6 +7,8 @@ import { expect } from "@playwright/test";
|
||||
import type { Dayjs } from "@calcom/dayjs";
|
||||
import dayjs from "@calcom/dayjs";
|
||||
import { intervalLimitKeyToUnit } from "@calcom/lib/intervalLimit";
|
||||
import prisma from "@calcom/prisma";
|
||||
import { BookingStatus } from "@calcom/prisma/client";
|
||||
import { entries } from "@calcom/prisma/zod-utils";
|
||||
import type { IntervalLimit } from "@calcom/types/Calendar";
|
||||
|
||||
@@ -88,6 +90,7 @@ test.skip("Booking limits", () => {
|
||||
await expect(bookingDay).toBeVisible({ timeout: 10_000 });
|
||||
const availableDaysBefore = await availableDays.count();
|
||||
|
||||
let latestRescheduleUrl: string | null = null;
|
||||
await test.step("can book up to limit", async () => {
|
||||
for (let i = 0; i < bookingLimit; i++) {
|
||||
await bookingDay.click();
|
||||
@@ -98,6 +101,9 @@ test.skip("Booking limits", () => {
|
||||
slotUrl = page.url();
|
||||
|
||||
await expect(page.getByTestId("success-page")).toBeVisible();
|
||||
latestRescheduleUrl = await page
|
||||
.locator('span[data-testid="reschedule-link"] > a')
|
||||
.getAttribute("href");
|
||||
|
||||
await page.goto(monthUrl);
|
||||
}
|
||||
@@ -131,6 +137,55 @@ test.skip("Booking limits", () => {
|
||||
await expect(page.getByTestId("booking-fail")).toBeVisible({ timeout: 1000 });
|
||||
});
|
||||
|
||||
await test.step("but can reschedule", async () => {
|
||||
const bookingId = latestRescheduleUrl?.split("/").pop();
|
||||
const rescheduledBooking = await prisma.booking.findFirstOrThrow({ where: { uid: bookingId } });
|
||||
|
||||
const year = rescheduledBooking.startTime.getFullYear();
|
||||
const month = String(rescheduledBooking.startTime.getMonth() + 1).padStart(2, "0");
|
||||
const day = String(rescheduledBooking.startTime.getDate()).padStart(2, "0");
|
||||
|
||||
await page.goto(
|
||||
`/${user.username}/${
|
||||
user.eventTypes.at(-1)?.slug
|
||||
}?rescheduleUid=${bookingId}&date=${year}-${month}-${day}&month=${year}-${month}`
|
||||
);
|
||||
|
||||
const formerDay = availableDays.getByText(rescheduledBooking.startTime.getDate().toString(), {
|
||||
exact: true,
|
||||
});
|
||||
await expect(formerDay).toBeVisible();
|
||||
|
||||
const formerTimeElement = page.locator('[data-testid="former_time_p"]');
|
||||
await expect(formerTimeElement).toBeVisible();
|
||||
|
||||
await page.locator('[data-testid="time"]').nth(0).click();
|
||||
|
||||
await expect(page.locator('[name="name"]')).toBeDisabled();
|
||||
await expect(page.locator('[name="email"]')).toBeDisabled();
|
||||
|
||||
await page.locator('[data-testid="confirm-reschedule-button"]').click();
|
||||
|
||||
await page.waitForLoadState("networkidle");
|
||||
await expect(page.locator("[data-testid=success-page]")).toBeVisible();
|
||||
|
||||
const newBooking = await prisma.booking.findFirstOrThrow({ where: { fromReschedule: bookingId } });
|
||||
expect(newBooking).not.toBeNull();
|
||||
|
||||
const updatedRescheduledBooking = await prisma.booking.findFirstOrThrow({
|
||||
where: { uid: bookingId },
|
||||
});
|
||||
expect(updatedRescheduledBooking.status).toBe(BookingStatus.CANCELLED);
|
||||
|
||||
await prisma.booking.deleteMany({
|
||||
where: {
|
||||
id: {
|
||||
in: [newBooking.id, rescheduledBooking.id],
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
await test.step(`month after booking`, async () => {
|
||||
await page.goto(getLastEventUrlWithMonth(user, firstMondayInBookingMonth.add(1, "month")));
|
||||
|
||||
|
||||
@@ -1103,6 +1103,8 @@ async function handler(
|
||||
firstUsersMetadata?.defaultConferencingApp?.appLink;
|
||||
}
|
||||
|
||||
let rescheduleUid = reqBody.rescheduleUid;
|
||||
|
||||
if (
|
||||
Object.prototype.hasOwnProperty.call(eventType, "bookingLimits") ||
|
||||
Object.prototype.hasOwnProperty.call(eventType, "durationLimits")
|
||||
@@ -1116,6 +1118,7 @@ async function handler(
|
||||
eventType.bookingLimits as IntervalLimit,
|
||||
startAsDate,
|
||||
eventType.id,
|
||||
rescheduleUid,
|
||||
eventType.schedule?.timeZone
|
||||
);
|
||||
}
|
||||
@@ -1124,7 +1127,6 @@ async function handler(
|
||||
}
|
||||
}
|
||||
|
||||
let rescheduleUid = reqBody.rescheduleUid;
|
||||
let bookingSeat: BookingSeat = null;
|
||||
|
||||
let originalRescheduledBooking: BookingType = null;
|
||||
|
||||
@@ -12,6 +12,7 @@ export async function checkBookingLimits(
|
||||
bookingLimits: IntervalLimit,
|
||||
eventStartDate: Date,
|
||||
eventId: number,
|
||||
rescheduleUid?: string | undefined,
|
||||
timeZone?: string | null
|
||||
) {
|
||||
const parsedBookingLimits = parseBookingLimit(bookingLimits);
|
||||
@@ -19,7 +20,14 @@ export async function checkBookingLimits(
|
||||
|
||||
// not iterating entries to preserve types
|
||||
const limitCalculations = ascendingLimitKeys.map((key) =>
|
||||
checkBookingLimit({ key, limitingNumber: parsedBookingLimits[key], eventStartDate, eventId, timeZone })
|
||||
checkBookingLimit({
|
||||
key,
|
||||
limitingNumber: parsedBookingLimits[key],
|
||||
eventStartDate,
|
||||
eventId,
|
||||
timeZone,
|
||||
rescheduleUid,
|
||||
})
|
||||
);
|
||||
|
||||
try {
|
||||
@@ -34,12 +42,14 @@ export async function checkBookingLimit({
|
||||
eventId,
|
||||
key,
|
||||
limitingNumber,
|
||||
rescheduleUid,
|
||||
timeZone,
|
||||
}: {
|
||||
eventStartDate: Date;
|
||||
eventId: number;
|
||||
key: keyof IntervalLimit;
|
||||
limitingNumber: number | undefined;
|
||||
rescheduleUid?: string | undefined;
|
||||
timeZone?: string | null;
|
||||
}) {
|
||||
{
|
||||
@@ -63,6 +73,9 @@ export async function checkBookingLimit({
|
||||
endTime: {
|
||||
lte: endDate,
|
||||
},
|
||||
uid: {
|
||||
not: rescheduleUid,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user