2022-05-14 03:02:10 +00:00
|
|
|
import { expect } from "@playwright/test";
|
2022-04-14 21:25:24 +00:00
|
|
|
|
2023-08-10 19:07:57 +00:00
|
|
|
import dayjs from "@calcom/dayjs";
|
2022-07-28 19:58:26 +00:00
|
|
|
import prisma from "@calcom/prisma";
|
2023-05-02 11:44:05 +00:00
|
|
|
import { BookingStatus } from "@calcom/prisma/enums";
|
2022-05-12 03:07:22 +00:00
|
|
|
|
2022-05-14 03:02:10 +00:00
|
|
|
import { test } from "./lib/fixtures";
|
2022-04-14 21:25:24 +00:00
|
|
|
import { selectFirstAvailableTimeSlotNextMonth } from "./lib/testUtils";
|
|
|
|
|
|
|
|
const IS_STRIPE_ENABLED = !!(
|
|
|
|
process.env.STRIPE_CLIENT_ID &&
|
|
|
|
process.env.NEXT_PUBLIC_STRIPE_PUBLIC_KEY &&
|
|
|
|
process.env.STRIPE_PRIVATE_KEY
|
|
|
|
);
|
2022-05-14 03:02:10 +00:00
|
|
|
|
|
|
|
test.describe.configure({ mode: "parallel" });
|
|
|
|
|
2023-03-01 20:18:51 +00:00
|
|
|
test.afterEach(({ users }) => users.deleteAll());
|
|
|
|
|
2023-07-11 11:31:55 +00:00
|
|
|
test.describe("Reschedule Tests", async () => {
|
2022-05-14 03:02:10 +00:00
|
|
|
test("Should do a booking request reschedule from /bookings", async ({ page, users, bookings }) => {
|
|
|
|
const user = await users.create();
|
2023-03-14 04:19:05 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
2022-05-14 03:02:10 +00:00
|
|
|
const booking = await bookings.create(user.id, user.username, user.eventTypes[0].id!, {
|
|
|
|
status: BookingStatus.ACCEPTED,
|
2022-04-14 21:25:24 +00:00
|
|
|
});
|
|
|
|
|
2023-06-06 18:02:32 +00:00
|
|
|
await user.apiLogin();
|
2022-04-14 21:25:24 +00:00
|
|
|
await page.goto("/bookings/upcoming");
|
|
|
|
|
2022-05-27 23:27:41 +00:00
|
|
|
await page.locator('[data-testid="edit_booking"]').nth(0).click();
|
2022-04-14 21:25:24 +00:00
|
|
|
|
|
|
|
await page.locator('[data-testid="reschedule_request"]').click();
|
|
|
|
|
|
|
|
await page.fill('[data-testid="reschedule_reason"]', "I can't longer have it");
|
|
|
|
|
|
|
|
await page.locator('button[data-testid="send_request"]').click();
|
2023-02-16 22:39:57 +00:00
|
|
|
await expect(page.locator('[id="modal-title"]')).toBeHidden();
|
2022-04-14 21:25:24 +00:00
|
|
|
|
2022-05-14 03:02:10 +00:00
|
|
|
const updatedBooking = await booking.self();
|
2022-04-14 21:25:24 +00:00
|
|
|
|
2023-06-06 11:59:57 +00:00
|
|
|
expect(updatedBooking?.rescheduled).toBe(true);
|
|
|
|
expect(updatedBooking?.cancellationReason).toBe("I can't longer have it");
|
|
|
|
expect(updatedBooking?.status).toBe(BookingStatus.CANCELLED);
|
2022-05-14 03:02:10 +00:00
|
|
|
await booking.delete();
|
2022-04-14 21:25:24 +00:00
|
|
|
});
|
|
|
|
|
2022-05-14 03:02:10 +00:00
|
|
|
test("Should display former time when rescheduling availability", async ({ page, users, bookings }) => {
|
|
|
|
const user = await users.create();
|
2023-03-14 04:19:05 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
2022-05-14 03:02:10 +00:00
|
|
|
const booking = await bookings.create(user.id, user.username, user.eventTypes[0].id!, {
|
|
|
|
status: BookingStatus.CANCELLED,
|
|
|
|
rescheduled: true,
|
2022-04-14 21:25:24 +00:00
|
|
|
});
|
2022-05-14 03:02:10 +00:00
|
|
|
|
|
|
|
await page.goto(`/${user.username}/${user.eventTypes[0].slug}?rescheduleUid=${booking.uid}`);
|
2023-03-14 04:19:05 +00:00
|
|
|
|
|
|
|
await selectFirstAvailableTimeSlotNextMonth(page);
|
|
|
|
|
|
|
|
const formerTimeElement = page.locator('[data-testid="former_time_p"]');
|
2022-04-14 21:25:24 +00:00
|
|
|
await expect(formerTimeElement).toBeVisible();
|
2022-05-14 03:02:10 +00:00
|
|
|
await booking.delete();
|
2022-04-14 21:25:24 +00:00
|
|
|
});
|
|
|
|
|
2022-05-14 03:02:10 +00:00
|
|
|
test("Should display request reschedule send on bookings/cancelled", async ({ page, users, bookings }) => {
|
|
|
|
const user = await users.create();
|
|
|
|
const booking = await bookings.create(user.id, user.username, user.eventTypes[0].id, {
|
|
|
|
status: BookingStatus.CANCELLED,
|
|
|
|
rescheduled: true,
|
2022-04-14 21:25:24 +00:00
|
|
|
});
|
|
|
|
|
2023-06-06 18:02:32 +00:00
|
|
|
await user.apiLogin();
|
2022-04-14 21:25:24 +00:00
|
|
|
await page.goto("/bookings/cancelled");
|
|
|
|
|
2022-05-14 03:02:10 +00:00
|
|
|
const requestRescheduleSentElement = page.locator('[data-testid="request_reschedule_sent"]').nth(1);
|
2022-04-14 21:25:24 +00:00
|
|
|
await expect(requestRescheduleSentElement).toBeVisible();
|
2022-05-14 03:02:10 +00:00
|
|
|
await booking.delete();
|
2022-04-14 21:25:24 +00:00
|
|
|
});
|
|
|
|
|
2022-05-14 03:02:10 +00:00
|
|
|
test("Should do a reschedule from user owner", async ({ page, users, bookings }) => {
|
|
|
|
const user = await users.create();
|
|
|
|
const [eventType] = user.eventTypes;
|
|
|
|
const booking = await bookings.create(user.id, user.username, eventType.id, {
|
|
|
|
status: BookingStatus.CANCELLED,
|
|
|
|
rescheduled: true,
|
2022-04-14 21:25:24 +00:00
|
|
|
});
|
|
|
|
|
2022-05-14 03:02:10 +00:00
|
|
|
await page.goto(`/${user.username}/${eventType.slug}?rescheduleUid=${booking.uid}`);
|
2022-04-14 21:25:24 +00:00
|
|
|
|
2022-05-14 03:02:10 +00:00
|
|
|
await selectFirstAvailableTimeSlotNextMonth(page);
|
2022-04-14 21:25:24 +00:00
|
|
|
|
2022-05-14 03:02:10 +00:00
|
|
|
await expect(page.locator('[name="name"]')).toBeDisabled();
|
|
|
|
await expect(page.locator('[name="email"]')).toBeDisabled();
|
2022-04-14 21:25:24 +00:00
|
|
|
|
2022-05-14 03:02:10 +00:00
|
|
|
await page.locator('[data-testid="confirm-reschedule-button"]').click();
|
2022-04-14 21:25:24 +00:00
|
|
|
|
2023-03-14 04:19:05 +00:00
|
|
|
await page.waitForLoadState("networkidle");
|
|
|
|
|
2022-05-14 03:02:10 +00:00
|
|
|
await expect(page.locator("[data-testid=success-page]")).toBeVisible();
|
2022-04-14 21:25:24 +00:00
|
|
|
|
2023-04-02 10:09:57 +00:00
|
|
|
const newBooking = await prisma.booking.findFirstOrThrow({ where: { fromReschedule: booking.uid } });
|
|
|
|
const rescheduledBooking = await prisma.booking.findFirstOrThrow({ where: { uid: booking.uid } });
|
2023-03-27 09:34:41 +00:00
|
|
|
|
2022-05-14 03:02:10 +00:00
|
|
|
expect(newBooking).not.toBeNull();
|
2023-04-02 10:09:57 +00:00
|
|
|
expect(rescheduledBooking.status).toBe(BookingStatus.CANCELLED);
|
|
|
|
|
|
|
|
await prisma.booking.deleteMany({
|
|
|
|
where: {
|
|
|
|
id: {
|
|
|
|
in: [newBooking.id, rescheduledBooking.id],
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
2022-04-14 21:25:24 +00:00
|
|
|
});
|
|
|
|
|
2022-05-14 03:02:10 +00:00
|
|
|
test("Unpaid rescheduling should go to payment page", async ({ page, users, bookings, payments }) => {
|
2022-05-17 19:31:49 +00:00
|
|
|
// eslint-disable-next-line playwright/no-skipped-test
|
2022-05-14 03:02:10 +00:00
|
|
|
test.skip(!IS_STRIPE_ENABLED, "Skipped as Stripe is not installed");
|
|
|
|
const user = await users.create();
|
2023-06-06 18:02:32 +00:00
|
|
|
await user.apiLogin();
|
2022-05-14 03:02:10 +00:00
|
|
|
await user.getPaymentCredential();
|
2023-03-14 04:19:05 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
2022-05-14 03:02:10 +00:00
|
|
|
const eventType = user.eventTypes.find((e) => e.slug === "paid")!;
|
|
|
|
const booking = await bookings.create(user.id, user.username, eventType.id, {
|
|
|
|
rescheduled: true,
|
|
|
|
status: BookingStatus.CANCELLED,
|
|
|
|
paid: false,
|
|
|
|
});
|
2023-02-08 20:36:22 +00:00
|
|
|
await prisma.eventType.update({
|
|
|
|
where: {
|
|
|
|
id: eventType.id,
|
|
|
|
},
|
|
|
|
data: {
|
|
|
|
metadata: {
|
|
|
|
apps: {
|
|
|
|
stripe: {
|
|
|
|
price: 20000,
|
|
|
|
enabled: true,
|
|
|
|
currency: "usd",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
2022-05-14 03:02:10 +00:00
|
|
|
const payment = await payments.create(booking.id);
|
|
|
|
await page.goto(`/${user.username}/${eventType.slug}?rescheduleUid=${booking.uid}`);
|
|
|
|
|
|
|
|
await selectFirstAvailableTimeSlotNextMonth(page);
|
2022-04-14 21:25:24 +00:00
|
|
|
|
2022-05-14 03:02:10 +00:00
|
|
|
await page.locator('[data-testid="confirm-reschedule-button"]').click();
|
2022-04-14 21:25:24 +00:00
|
|
|
|
2023-05-02 16:58:39 +00:00
|
|
|
await page.waitForURL((url) => {
|
|
|
|
return url.pathname.indexOf("/payment") > -1;
|
2022-04-14 21:25:24 +00:00
|
|
|
});
|
2022-05-14 03:02:10 +00:00
|
|
|
|
|
|
|
await expect(page).toHaveURL(/.*payment/);
|
2022-04-14 21:25:24 +00:00
|
|
|
});
|
|
|
|
|
2022-05-14 03:02:10 +00:00
|
|
|
test("Paid rescheduling should go to success page", async ({ page, users, bookings, payments }) => {
|
|
|
|
const user = await users.create();
|
2023-06-06 18:02:32 +00:00
|
|
|
await user.apiLogin();
|
2022-05-16 16:27:36 +00:00
|
|
|
await user.getPaymentCredential();
|
|
|
|
await users.logout();
|
2023-03-14 04:19:05 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
2022-05-14 03:02:10 +00:00
|
|
|
const eventType = user.eventTypes.find((e) => e.slug === "paid")!;
|
|
|
|
const booking = await bookings.create(user.id, user.username, eventType.id, {
|
|
|
|
rescheduled: true,
|
|
|
|
status: BookingStatus.CANCELLED,
|
|
|
|
paid: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
const payment = await payments.create(booking.id);
|
|
|
|
await page.goto(`/${user?.username}/${eventType?.slug}?rescheduleUid=${booking?.uid}`);
|
|
|
|
|
|
|
|
await selectFirstAvailableTimeSlotNextMonth(page);
|
|
|
|
|
|
|
|
await page.locator('[data-testid="confirm-reschedule-button"]').click();
|
|
|
|
|
2022-11-29 20:27:29 +00:00
|
|
|
await expect(page).toHaveURL(/.*booking/);
|
2022-04-14 21:25:24 +00:00
|
|
|
});
|
2022-08-05 17:08:47 +00:00
|
|
|
|
|
|
|
test("Opt in event should be PENDING when rescheduled by USER", async ({ page, users, bookings }) => {
|
|
|
|
const user = await users.create();
|
2023-03-14 04:19:05 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
2022-08-05 17:08:47 +00:00
|
|
|
const eventType = user.eventTypes.find((e) => e.slug === "opt-in")!;
|
|
|
|
const booking = await bookings.create(user.id, user.username, eventType.id, {
|
|
|
|
status: BookingStatus.ACCEPTED,
|
|
|
|
});
|
|
|
|
|
|
|
|
await page.goto(`/${user.username}/${eventType.slug}?rescheduleUid=${booking.uid}`);
|
|
|
|
|
|
|
|
await selectFirstAvailableTimeSlotNextMonth(page);
|
|
|
|
|
|
|
|
await page.locator('[data-testid="confirm-reschedule-button"]').click();
|
|
|
|
|
2022-11-29 20:27:29 +00:00
|
|
|
await expect(page).toHaveURL(/.*booking/);
|
2022-08-05 17:08:47 +00:00
|
|
|
|
|
|
|
const newBooking = await prisma.booking.findFirst({ where: { fromReschedule: booking?.uid } });
|
|
|
|
expect(newBooking).not.toBeNull();
|
|
|
|
expect(newBooking?.status).toBe(BookingStatus.PENDING);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("Opt in event should be ACCEPTED when rescheduled by OWNER", async ({ page, users, bookings }) => {
|
|
|
|
const user = await users.create();
|
2023-03-14 04:19:05 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
2022-08-05 17:08:47 +00:00
|
|
|
const eventType = user.eventTypes.find((e) => e.slug === "opt-in")!;
|
|
|
|
const booking = await bookings.create(user.id, user.username, eventType.id, {
|
|
|
|
status: BookingStatus.ACCEPTED,
|
|
|
|
});
|
2023-06-06 18:02:32 +00:00
|
|
|
await user.apiLogin();
|
2022-08-05 17:08:47 +00:00
|
|
|
|
|
|
|
await page.goto(`/${user.username}/${eventType.slug}?rescheduleUid=${booking.uid}`);
|
|
|
|
|
|
|
|
await selectFirstAvailableTimeSlotNextMonth(page);
|
|
|
|
|
|
|
|
await page.locator('[data-testid="confirm-reschedule-button"]').click();
|
|
|
|
|
2022-11-29 20:27:29 +00:00
|
|
|
await expect(page).toHaveURL(/.*booking/);
|
2022-08-05 17:08:47 +00:00
|
|
|
|
|
|
|
const newBooking = await prisma.booking.findFirst({ where: { fromReschedule: booking?.uid } });
|
|
|
|
expect(newBooking).not.toBeNull();
|
|
|
|
expect(newBooking?.status).toBe(BookingStatus.ACCEPTED);
|
|
|
|
});
|
2023-06-10 03:47:50 +00:00
|
|
|
|
|
|
|
test("Attendee should be able to reschedule a booking", async ({ page, users, bookings }) => {
|
|
|
|
const user = await users.create();
|
|
|
|
const eventType = user.eventTypes[0];
|
|
|
|
const booking = await bookings.create(user.id, user.username, eventType.id);
|
|
|
|
|
|
|
|
// Go to attendee's reschedule link
|
|
|
|
await page.goto(`/reschedule/${booking.uid}`);
|
|
|
|
|
|
|
|
await selectFirstAvailableTimeSlotNextMonth(page);
|
|
|
|
|
|
|
|
await page.locator('[data-testid="confirm-reschedule-button"]').click();
|
|
|
|
|
|
|
|
await expect(page).toHaveURL(/.*booking/);
|
|
|
|
|
|
|
|
const newBooking = await prisma.booking.findFirst({ where: { fromReschedule: booking?.uid } });
|
|
|
|
expect(newBooking).not.toBeNull();
|
|
|
|
expect(newBooking?.status).toBe(BookingStatus.ACCEPTED);
|
|
|
|
});
|
2023-08-10 19:07:57 +00:00
|
|
|
|
|
|
|
test("Should be able to book slot that overlaps with original rescheduled booking", async ({
|
|
|
|
page,
|
|
|
|
users,
|
|
|
|
bookings,
|
|
|
|
}) => {
|
|
|
|
const user = await users.create();
|
|
|
|
const eventType = user.eventTypes[0];
|
|
|
|
const startTime = dayjs().add(1, "day").set("hour", 10).set("minute", 0).toDate();
|
|
|
|
const endTime = dayjs().add(1, "day").set("hour", 10).set("minute", 30).toDate();
|
|
|
|
|
|
|
|
const booking = await bookings.create(user.id, user.username, eventType.id, {}, startTime, endTime);
|
|
|
|
|
|
|
|
await page.goto(`/reschedule/${booking.uid}`);
|
|
|
|
|
|
|
|
//book same slot again
|
|
|
|
page.getByRole("button", { name: dayjs(startTime).format("D"), exact: true }).click();
|
|
|
|
|
|
|
|
page.getByRole("button", { name: dayjs(startTime).format("h:mmA") }).click();
|
|
|
|
|
|
|
|
await page.locator('[data-testid="confirm-reschedule-button"]').click();
|
|
|
|
await expect(page).toHaveURL(/.*booking/);
|
|
|
|
});
|
2022-04-14 21:25:24 +00:00
|
|
|
});
|