cal.pub0.org/apps/web/playwright/reschedule.e2e.ts

199 lines
7.3 KiB
TypeScript
Raw Normal View History

2022-05-14 03:02:10 +00:00
import { expect } from "@playwright/test";
import { BookingStatus } from "@prisma/client";
import prisma from "@calcom/prisma";
2022-05-12 03:07:22 +00:00
2022-05-14 03:02:10 +00:00
import { test } from "./lib/fixtures";
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" });
test.describe("Reschedule Tests", async () => {
2022-05-14 03:02:10 +00:00
test.afterEach(async ({ users }) => {
await users.deleteAll();
});
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();
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-05-14 03:02:10 +00:00
await user.login();
await page.goto("/bookings/upcoming");
Change location of booking (#2658) * add functionality to change location in booking and send out mail * add i18n * change location with dropdown like in event-types * small fixes and code clean up * clean code * improve format of current Location string * clean code * clear selection when dialog closed * added mutation and changed props (first working verison) * clean code * clean code * clean code * clean code * fix typo * change maxHeight of select * use useWatch for selectedLocation * pass default values with props * set current location directly in useState * clear selected values when updating location * fix trpc query for credentialst * change icons for editing booking * improve naming of variables * remove unnecessary orderBy * use locationOptionsToString method * fix current location naming for Cal Video * add phone input * save phone number as location of booking * remove input field for phone number for event-types * fix redirection issue * show previous selected location in event-type * remove attendee number from selection for booking * make first letter of location lowercase * remove input field for attendee phone number * clear Errors when changing location type * set location details to optional * clean code * fixing issue that dropdown doesn't close when dialog opens * clean code * make overflow visibile in dialog * fix existing bug with address not showing in event-type settings * fix issue with losing focus after validation * close rejection dialog * small spelling fixes * fix issue with LocationChangeEmail * fix failing E2E test * fix failing E2E test * fix E2E test * bug fix for saving user phone, and other minor changes * merge main * improve text * fix UI of booking list * Delete admin * remove selection after update and submit * add translation for error message * add default values for checkbox * add "your phone number" to locations on booking page * remove duplicate attributes from viewer.bookings Co-authored-by: Omar López <zomars@me.com> * check if user is authorized to make changes to booking * remove location string * clan code for displayLocaitonPublicly checkbox * fetch locationOptions on server side * remove trpc query for credentials * fix phone number input * fix labels of host and attendee phone number for booking page * Migrates edit location to tRPC * Link elemnt should only be used in `a` tags * Adds missin router * Migrates locationOptions to tRPC query * Type fixes Co-authored-by: CarinaWolli <wollencarina@gmail.com> Co-authored-by: Alan <alannnc@gmail.com> Co-authored-by: Omar López <zomars@me.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
2022-05-27 23:27:41 +00:00
await page.locator('[data-testid="edit_booking"]').nth(0).click();
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();
2022-05-14 03:02:10 +00:00
await expect(page.locator('[id="modal-title"]')).not.toBeVisible();
2022-05-14 03:02:10 +00:00
const updatedBooking = await booking.self();
2022-05-14 03:02:10 +00:00
expect(updatedBooking.rescheduled).toBe(true);
expect(updatedBooking.cancellationReason).toBe("I can't longer have it");
expect(updatedBooking.status).toBe(BookingStatus.CANCELLED);
await booking.delete();
});
2022-05-14 03:02:10 +00:00
test("Should display former time when rescheduling availability", async ({ page, users, bookings }) => {
Feature/booking page refactor (#3035) * Extracted UI related logic on the DatePicker, stripped out all logic * wip * fixed small regression due to merge * Fix alignment of the chevrons * Added isToday dot, added onMonthChange so we can fetch this month slots * Added includedDates to inverse excludedDates * removed trpcState * Improvements to the state * All params are now dynamic * This builds the flat map so not all paths block on every new build * Added requiresConfirmation * Correctly take into account getFilteredTimes to make the calendar function * Rewritten team availability, seems to work * Circumvent i18n flicker by showing the loader instead * 'You can remove this code. Its not being used now' - Hariom * Nailed a persistent little bug, new Date() caused the current day to flicker on and off * TS fixes * Fix some eventType details in AvailableTimes * '5 / 6 Seats Available' instead of '6 / Seats Available' * More type fixes * Removed unrelated merge artifact * Use WEBAPP_URL instead of hardcoded * Next round of TS fixes * I believe this was mistyped * Temporarily disabled rescheduling 'this is when you originally scheduled', so removed dep * Sorting some dead code * This page has a lot of red, not all related to this PR * A PR to your PR (#3067) * Cleanup * Cleanup * Uses zod to parse params * Type fixes * Fixes ISR * E2E fixes * Disabled dynamic bookings until post v1.7 * More test fixes * Fixed border position (transparent border) to prevent dot from jumping - and possibly fix spacing * Disabled style nitpicks * Delete useSlots.ts Removed early design artifact * Unlock DatePicker locale * Adds mini spinner to DatePicker Co-authored-by: Peer Richelsen <peeroke@gmail.com> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> Co-authored-by: zomars <zomars@me.com>
2022-06-15 20:54:31 +00:00
test.skip(true, "TODO: Re-enable after v1.7 launch");
2022-05-14 03:02:10 +00:00
const user = await users.create();
const booking = await bookings.create(user.id, user.username, user.eventTypes[0].id!, {
status: BookingStatus.CANCELLED,
rescheduled: true,
});
2022-05-14 03:02:10 +00:00
await page.goto(`/${user.username}/${user.eventTypes[0].slug}?rescheduleUid=${booking.uid}`);
const formerTimeElement = page.locator('[data-testid="former_time_p_desktop"]');
await expect(formerTimeElement).toBeVisible();
2022-05-14 03:02:10 +00:00
await booking.delete();
});
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-05-14 03:02:10 +00:00
await user.login();
await page.goto("/bookings/cancelled");
2022-05-14 03:02:10 +00:00
const requestRescheduleSentElement = page.locator('[data-testid="request_reschedule_sent"]').nth(1);
await expect(requestRescheduleSentElement).toBeVisible();
2022-05-14 03:02:10 +00:00
await booking.delete();
});
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-05-14 03:02:10 +00:00
await page.goto(`/${user.username}/${eventType.slug}?rescheduleUid=${booking.uid}`);
2022-05-14 03:02:10 +00:00
await selectFirstAvailableTimeSlotNextMonth(page);
2022-05-14 03:02:10 +00:00
await expect(page.locator('[name="name"]')).toBeDisabled();
await expect(page.locator('[name="email"]')).toBeDisabled();
2022-05-14 03:02:10 +00:00
await page.locator('[data-testid="confirm-reschedule-button"]').click();
2022-05-14 03:02:10 +00:00
await expect(page.locator("[data-testid=success-page]")).toBeVisible();
2022-05-14 03:02:10 +00:00
// NOTE: remove if old booking should not be deleted
expect(await booking.self()).toBeNull();
2022-05-14 03:02:10 +00:00
const newBooking = await prisma.booking.findFirst({ where: { fromReschedule: booking.uid } });
expect(newBooking).not.toBeNull();
await prisma.booking.delete({ where: { id: newBooking?.id } });
});
2022-05-14 03:02:10 +00:00
test("Unpaid rescheduling should go to payment page", async ({ page, users, bookings, payments }) => {
// 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();
await user.login();
await user.getPaymentCredential();
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,
});
const payment = await payments.create(booking.id);
await page.goto(`/${user.username}/${eventType.slug}?rescheduleUid=${booking.uid}`);
await selectFirstAvailableTimeSlotNextMonth(page);
2022-05-14 03:02:10 +00:00
await page.locator('[data-testid="confirm-reschedule-button"]').click();
2022-05-14 03:02:10 +00:00
await page.waitForNavigation({
url(url) {
return url.pathname.indexOf("/payment") > -1;
},
});
2022-05-14 03:02:10 +00:00
await expect(page).toHaveURL(/.*payment/);
await payment.delete();
});
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();
await user.login();
await user.getPaymentCredential();
await users.logout();
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();
await expect(page).toHaveURL(/.*booking/);
2022-05-14 03:02:10 +00:00
await payment.delete();
});
test("Opt in event should be PENDING when rescheduled by USER", async ({ page, users, bookings }) => {
const user = await users.create();
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();
await expect(page).toHaveURL(/.*booking/);
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();
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 user.login();
await page.goto(`/${user.username}/${eventType.slug}?rescheduleUid=${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);
});
});