Feature/reschedule bookings (#2351)
* WIP bookings page ui changes, created api endpoint * Ui changes mobile/desktop * Added translations * Fix lib import and common names * WIP reschedule * WIP * Save wip * [WIP] builder and class for CalendarEvent, email for attende * update rescheduled emails, booking view and availability page view * Working version reschedule * Fix for req.user as array * Added missing translation and refactor dialog to self component * Test for reschedule * update on types * Update lib no required * Update type on createBooking * fix types * remove preview stripe sub * remove unused file * remove unused import * Fix reschedule test * Refactor and cleaning up code * Email reschedule title fixes * Adding calendar delete and recreate placeholder of cancelled * Add translation * Removed logs, notes, fixed types * Fixes process.env types * Use strict compare * Fixes type inference * Type fixing is my middle name * Update apps/web/components/booking/BookingListItem.tsx * Update apps/web/components/dialog/RescheduleDialog.tsx * Update packages/core/builders/CalendarEvent/director.ts * Update apps/web/pages/success.tsx * Updates rescheduling labels * Update packages/core/builders/CalendarEvent/builder.ts * Type fixes * Update packages/core/builders/CalendarEvent/builder.ts * Only validating input blocked once * E2E fixes * Stripe tests fixes Co-authored-by: Peer Richelsen <[email protected]> Co-authored-by: zomars <[email protected]>
This commit is contained in:
50 files changed
+2129
-241
No files matched your search
@@ -109,6 +109,7 @@ test.describe("pro user", () => {
|
||||
|
||||
await page.goto("/bookings/upcoming");
|
||||
await page.locator('[data-testid="reschedule"]').click();
|
||||
await page.locator('[data-testid="edit"]').click();
|
||||
await page.waitForNavigation({
|
||||
url: (url) => {
|
||||
const bookingId = url.searchParams.get("rescheduleUid");
|
||||
|
||||
@@ -43,6 +43,7 @@ test.describe("dynamic booking", () => {
|
||||
// Logged in
|
||||
await page.goto("/bookings/upcoming");
|
||||
await page.locator('[data-testid="reschedule"]').click();
|
||||
await page.locator('[data-testid="edit"]').click();
|
||||
await page.waitForNavigation({
|
||||
url: (url) => {
|
||||
const bookingId = url.searchParams.get("rescheduleUid");
|
||||
|
||||
@@ -13,6 +13,7 @@ test.describe.serial("Stripe integration", () => {
|
||||
test.afterAll(() => {
|
||||
teardown.deleteAllPaymentsByEmail("[email protected]");
|
||||
teardown.deleteAllBookingsByEmail("[email protected]");
|
||||
teardown.deleteAllPaymentCredentialsByEmail("[email protected]");
|
||||
});
|
||||
test.skip(!IS_STRIPE_ENABLED, "It should only run if Stripe is installed");
|
||||
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
import { Booking } from "@prisma/client";
|
||||
import dayjs from "dayjs";
|
||||
import utc from "dayjs/plugin/utc";
|
||||
import short from "short-uuid";
|
||||
import { v5 as uuidv5, v4 as uuidv4 } from "uuid";
|
||||
|
||||
dayjs.extend(utc);
|
||||
|
||||
const translator = short();
|
||||
|
||||
const TestUtilCreateBookingOnUserId = async (
|
||||
userId: number,
|
||||
username: string,
|
||||
eventTypeId: number,
|
||||
{ confirmed = true, rescheduled = false, paid = false, status = "ACCEPTED" }: Partial<Booking>
|
||||
) => {
|
||||
const startDate = dayjs().add(1, "day").toDate();
|
||||
const seed = `${username}:${dayjs(startDate).utc().format()}:${new Date().getTime()}`;
|
||||
const uid = translator.fromUUID(uuidv5(seed, uuidv5.URL));
|
||||
return await prisma?.booking.create({
|
||||
data: {
|
||||
uid: uid,
|
||||
title: "30min",
|
||||
startTime: startDate,
|
||||
endTime: dayjs().add(1, "day").add(30, "minutes").toDate(),
|
||||
user: {
|
||||
connect: {
|
||||
id: userId,
|
||||
},
|
||||
},
|
||||
attendees: {
|
||||
create: {
|
||||
email: "[email protected]",
|
||||
name: "Attendee Example",
|
||||
timeZone: "Europe/London",
|
||||
},
|
||||
},
|
||||
eventType: {
|
||||
connect: {
|
||||
id: eventTypeId,
|
||||
},
|
||||
},
|
||||
confirmed,
|
||||
rescheduled,
|
||||
paid,
|
||||
status,
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
uid: true,
|
||||
user: true,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
const TestUtilCreatePayment = async (
|
||||
bookingId: number,
|
||||
{ success = false, refunded = false }: { success?: boolean; refunded?: boolean }
|
||||
) => {
|
||||
return await prisma?.payment.create({
|
||||
data: {
|
||||
uid: uuidv4(),
|
||||
amount: 20000,
|
||||
fee: 160,
|
||||
currency: "usd",
|
||||
success,
|
||||
refunded,
|
||||
type: "STRIPE",
|
||||
data: {},
|
||||
externalId: "DEMO_PAYMENT_FROM_DB",
|
||||
booking: {
|
||||
connect: {
|
||||
id: bookingId,
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export { TestUtilCreateBookingOnUserId, TestUtilCreatePayment };
|
||||
@@ -1,11 +1,17 @@
|
||||
import { Prisma } from "@prisma/client";
|
||||
|
||||
import prisma from "@lib/prisma";
|
||||
|
||||
export const deleteAllBookingsByEmail = async (email: string) =>
|
||||
export const deleteAllBookingsByEmail = async (
|
||||
email: string,
|
||||
whereConditional: Prisma.BookingWhereInput = {}
|
||||
) =>
|
||||
prisma.booking.deleteMany({
|
||||
where: {
|
||||
user: {
|
||||
email,
|
||||
},
|
||||
...whereConditional,
|
||||
},
|
||||
});
|
||||
|
||||
@@ -38,3 +44,20 @@ export const deleteAllPaymentsByEmail = async (email: string) => {
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
export const deleteAllPaymentCredentialsByEmail = async (email: string) => {
|
||||
await prisma.user.update({
|
||||
where: {
|
||||
email,
|
||||
},
|
||||
data: {
|
||||
credentials: {
|
||||
deleteMany: {
|
||||
type: {
|
||||
endsWith: "_payment",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,246 @@
|
||||
import { expect, test } from "@playwright/test";
|
||||
import { BookingStatus } from "@prisma/client";
|
||||
import dayjs from "dayjs";
|
||||
|
||||
import { TestUtilCreateBookingOnUserId, TestUtilCreatePayment } from "./lib/dbSetup";
|
||||
import { deleteAllBookingsByEmail } from "./lib/teardown";
|
||||
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
|
||||
);
|
||||
const findUserByEmail = async (email: string) => {
|
||||
return await prisma?.user.findFirst({
|
||||
select: {
|
||||
id: true,
|
||||
email: true,
|
||||
username: true,
|
||||
credentials: true,
|
||||
},
|
||||
where: {
|
||||
email,
|
||||
},
|
||||
});
|
||||
};
|
||||
test.describe("Reschedule Tests", async () => {
|
||||
let currentUser: Awaited<ReturnType<typeof findUserByEmail>>;
|
||||
// Using logged in state from globalSetup
|
||||
test.use({ storageState: "playwright/artifacts/proStorageState.json" });
|
||||
test.beforeAll(async () => {
|
||||
currentUser = await findUserByEmail("[email protected]");
|
||||
});
|
||||
test.afterEach(async () => {
|
||||
try {
|
||||
await deleteAllBookingsByEmail("[email protected]", {
|
||||
createdAt: { gte: dayjs().startOf("day").toISOString() },
|
||||
});
|
||||
} catch (error) {
|
||||
console.log("Error while trying to delete all bookings from pro user");
|
||||
}
|
||||
});
|
||||
|
||||
test("Should do a booking request reschedule from /bookings", async ({ page }) => {
|
||||
const user = currentUser;
|
||||
const eventType = await prisma?.eventType.findFirst({
|
||||
where: {
|
||||
userId: user?.id,
|
||||
slug: "30min",
|
||||
},
|
||||
});
|
||||
let originalBooking;
|
||||
if (user && user.id && user.username && eventType) {
|
||||
originalBooking = await TestUtilCreateBookingOnUserId(user?.id, user?.username, eventType?.id, {
|
||||
status: BookingStatus.ACCEPTED,
|
||||
});
|
||||
}
|
||||
|
||||
await page.goto("/bookings/upcoming");
|
||||
|
||||
await page.locator('[data-testid="reschedule"]').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();
|
||||
|
||||
await page.goto("/bookings/cancelled");
|
||||
|
||||
// Find booking that was recently cancelled
|
||||
const booking = await prisma?.booking.findFirst({
|
||||
select: {
|
||||
id: true,
|
||||
uid: true,
|
||||
cancellationReason: true,
|
||||
status: true,
|
||||
rescheduled: true,
|
||||
},
|
||||
where: { id: originalBooking?.id },
|
||||
});
|
||||
|
||||
expect(booking?.rescheduled).toBe(true);
|
||||
expect(booking?.cancellationReason).toBe("I can't longer have it");
|
||||
expect(booking?.status).toBe(BookingStatus.CANCELLED);
|
||||
});
|
||||
|
||||
test("Should display former time when rescheduling availability", async ({ page }) => {
|
||||
const user = currentUser;
|
||||
const eventType = await prisma?.eventType.findFirst({
|
||||
where: {
|
||||
userId: user?.id,
|
||||
slug: "30min",
|
||||
},
|
||||
});
|
||||
let originalBooking;
|
||||
if (user && user.id && user.username && eventType) {
|
||||
originalBooking = await TestUtilCreateBookingOnUserId(user?.id, user?.username, eventType?.id, {
|
||||
status: BookingStatus.CANCELLED,
|
||||
rescheduled: true,
|
||||
});
|
||||
}
|
||||
|
||||
await page.goto(
|
||||
`/${originalBooking?.user?.username}/${eventType?.slug}?rescheduleUid=${originalBooking?.uid}`
|
||||
);
|
||||
const formerTimeElement = await page.locator('[data-testid="former_time_p"]');
|
||||
await expect(formerTimeElement).toBeVisible();
|
||||
});
|
||||
|
||||
test("Should display request reschedule send on bookings/cancelled", async ({ page }) => {
|
||||
const user = currentUser;
|
||||
const eventType = await prisma?.eventType.findFirst({
|
||||
where: {
|
||||
userId: user?.id,
|
||||
slug: "30min",
|
||||
},
|
||||
});
|
||||
|
||||
if (user && user.id && user.username && eventType) {
|
||||
await TestUtilCreateBookingOnUserId(user?.id, user?.username, eventType?.id, {
|
||||
status: BookingStatus.CANCELLED,
|
||||
rescheduled: true,
|
||||
});
|
||||
}
|
||||
await page.goto("/bookings/cancelled");
|
||||
|
||||
const requestRescheduleSentElement = await page.locator('[data-testid="request_reschedule_sent"]').nth(1);
|
||||
await expect(requestRescheduleSentElement).toBeVisible();
|
||||
});
|
||||
|
||||
test("Should do a reschedule from user owner", async ({ page }) => {
|
||||
const user = currentUser;
|
||||
|
||||
const eventType = await prisma?.eventType.findFirst({
|
||||
where: {
|
||||
userId: user?.id,
|
||||
},
|
||||
});
|
||||
if (user?.id && user?.username && eventType?.id) {
|
||||
const booking = await TestUtilCreateBookingOnUserId(user?.id, user?.username, eventType?.id, {
|
||||
rescheduled: true,
|
||||
status: BookingStatus.CANCELLED,
|
||||
});
|
||||
|
||||
await page.goto(`/${user?.username}/${eventType?.slug}?rescheduleUid=${booking?.uid}`);
|
||||
|
||||
await selectFirstAvailableTimeSlotNextMonth(page);
|
||||
|
||||
await expect(page.locator('[name="name"]')).toBeDisabled();
|
||||
await expect(page.locator('[name="email"]')).toBeDisabled();
|
||||
await expect(page.locator('[name="notes"]')).toBeDisabled();
|
||||
|
||||
await page.locator('[data-testid="confirm-reschedule-button"]').click();
|
||||
|
||||
await page.waitForNavigation({
|
||||
url(url) {
|
||||
return url.pathname.endsWith("/success");
|
||||
},
|
||||
});
|
||||
|
||||
await expect(page).toHaveURL(/.*success/);
|
||||
|
||||
// NOTE: remove if old booking should not be deleted
|
||||
const oldBooking = await prisma?.booking.findFirst({ where: { id: booking?.id } });
|
||||
expect(oldBooking).toBeNull();
|
||||
|
||||
const newBooking = await prisma?.booking.findFirst({ where: { fromReschedule: booking?.uid } });
|
||||
expect(newBooking).not.toBeNull();
|
||||
}
|
||||
});
|
||||
|
||||
test("Unpaid rescheduling should go to payment page", async ({ page }) => {
|
||||
let user = currentUser;
|
||||
|
||||
test.skip(
|
||||
IS_STRIPE_ENABLED && !(user && user.credentials.length > 0),
|
||||
"Skipped as stripe is not installed and user is missing credentials"
|
||||
);
|
||||
|
||||
const eventType = await prisma?.eventType.findFirst({
|
||||
where: {
|
||||
userId: user?.id,
|
||||
slug: "paid",
|
||||
},
|
||||
});
|
||||
if (user?.id && user?.username && eventType?.id) {
|
||||
const booking = await TestUtilCreateBookingOnUserId(user?.id, user?.username, eventType?.id, {
|
||||
rescheduled: true,
|
||||
status: BookingStatus.CANCELLED,
|
||||
paid: false,
|
||||
});
|
||||
if (booking?.id) {
|
||||
await TestUtilCreatePayment(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 page.waitForNavigation({
|
||||
url(url) {
|
||||
return url.pathname.indexOf("/payment") > -1;
|
||||
},
|
||||
});
|
||||
|
||||
await expect(page).toHaveURL(/.*payment/);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test("Paid rescheduling should go to success page", async ({ page }) => {
|
||||
let user = currentUser;
|
||||
try {
|
||||
const eventType = await prisma?.eventType.findFirst({
|
||||
where: {
|
||||
userId: user?.id,
|
||||
slug: "paid",
|
||||
},
|
||||
});
|
||||
if (user?.id && user?.username && eventType?.id) {
|
||||
const booking = await TestUtilCreateBookingOnUserId(user?.id, user?.username, eventType?.id, {
|
||||
rescheduled: true,
|
||||
status: BookingStatus.CANCELLED,
|
||||
paid: true,
|
||||
});
|
||||
if (booking?.id) {
|
||||
await TestUtilCreatePayment(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(/.*success/);
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
await prisma?.payment.delete({
|
||||
where: {
|
||||
externalId: "DEMO_PAYMENT_FROM_DB",
|
||||
},
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user