Fix/wipe vital app revision (#2983)
* Fixes for both apps regarding event update/delete * Added wipe my cal test * Added eslint ignore * Fix test * Merge both test into a single test * remove duplicated line * Using prisma from calcom pkg and removing optional chaining from current invocations Co-authored-by: Peer Richelsen <[email protected]> Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
8 files changed
+88
-40
No files matched your search
@@ -61,7 +61,7 @@ const handler = async (
|
|||||||
if (session?.user?.id) {
|
if (session?.user?.id) {
|
||||||
userOwner = await findUserDataByUserId(session?.user.id);
|
userOwner = await findUserDataByUserId(session?.user.id);
|
||||||
} else {
|
} else {
|
||||||
return res.status(501);
|
return res.status(501).end();
|
||||||
}
|
}
|
||||||
|
|
||||||
const bookingToReschedule = await prisma.booking.findFirst({
|
const bookingToReschedule = await prisma.booking.findFirst({
|
||||||
@@ -235,10 +235,10 @@ function validate(
|
|||||||
if (error instanceof ZodError && error?.name === "ZodError") {
|
if (error instanceof ZodError && error?.name === "ZodError") {
|
||||||
return res.status(400).json(error?.issues);
|
return res.status(400).json(error?.issues);
|
||||||
}
|
}
|
||||||
return res.status(402);
|
return res.status(402).end();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return res.status(405);
|
return res.status(405).end();
|
||||||
}
|
}
|
||||||
await handler(req, res);
|
await handler(req, res);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -21,9 +21,11 @@ export const createBookingsFixture = (page: Page) => {
|
|||||||
userId: number,
|
userId: number,
|
||||||
username: string | null,
|
username: string | null,
|
||||||
eventTypeId = -1,
|
eventTypeId = -1,
|
||||||
{ rescheduled = false, paid = false, status = "ACCEPTED" }: Partial<Prisma.BookingCreateInput> = {}
|
{ rescheduled = false, paid = false, status = "ACCEPTED" }: Partial<Prisma.BookingCreateInput> = {},
|
||||||
|
startDateParam?: Date,
|
||||||
|
endDateParam?: Date
|
||||||
) => {
|
) => {
|
||||||
const startDate = dayjs().add(1, "day").toDate();
|
const startDate = startDateParam || dayjs().add(1, "day").toDate();
|
||||||
const seed = `${username}:${dayjs(startDate).utc().format()}:${new Date().getTime()}`;
|
const seed = `${username}:${dayjs(startDate).utc().format()}:${new Date().getTime()}`;
|
||||||
const uid = translator.fromUUID(uuidv5(seed, uuidv5.URL));
|
const uid = translator.fromUUID(uuidv5(seed, uuidv5.URL));
|
||||||
const booking = await prisma.booking.create({
|
const booking = await prisma.booking.create({
|
||||||
@@ -31,7 +33,7 @@ export const createBookingsFixture = (page: Page) => {
|
|||||||
uid: uid,
|
uid: uid,
|
||||||
title: "30min",
|
title: "30min",
|
||||||
startTime: startDate,
|
startTime: startDate,
|
||||||
endTime: dayjs().add(1, "day").add(30, "minutes").toDate(),
|
endTime: endDateParam || dayjs().add(1, "day").add(30, "minutes").toDate(),
|
||||||
user: {
|
user: {
|
||||||
connect: {
|
connect: {
|
||||||
id: userId,
|
id: userId,
|
||||||
|
|||||||
@@ -0,0 +1,69 @@
|
|||||||
|
import { expect } from "@playwright/test";
|
||||||
|
import dayjs from "dayjs";
|
||||||
|
|
||||||
|
import prisma from "@calcom/prisma";
|
||||||
|
|
||||||
|
import { test } from "../../lib/fixtures";
|
||||||
|
|
||||||
|
test.describe.configure({ mode: "parallel" });
|
||||||
|
|
||||||
|
test.describe("Wipe my Cal App Test", () => {
|
||||||
|
test("Browse upcoming bookings and validate button shows and triggering wipe my cal button", async ({
|
||||||
|
page,
|
||||||
|
users,
|
||||||
|
bookings,
|
||||||
|
}) => {
|
||||||
|
const pro = await users.create();
|
||||||
|
const [eventType] = pro.eventTypes;
|
||||||
|
await prisma.credential.create({
|
||||||
|
data: {
|
||||||
|
key: {},
|
||||||
|
type: "wipemycal_other",
|
||||||
|
userId: pro.id,
|
||||||
|
appId: "wipe-my-cal",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
await bookings.create(
|
||||||
|
pro.id,
|
||||||
|
pro.username,
|
||||||
|
eventType.id,
|
||||||
|
{},
|
||||||
|
dayjs().endOf("day").subtract(29, "minutes").toDate(),
|
||||||
|
dayjs().endOf("day").toDate()
|
||||||
|
);
|
||||||
|
await prisma.credential.create({
|
||||||
|
data: {
|
||||||
|
key: {},
|
||||||
|
type: "wipemycal_other",
|
||||||
|
userId: pro.id,
|
||||||
|
appId: "wipe-my-cal",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await bookings.create(pro.id, pro.username, eventType.id, {});
|
||||||
|
await bookings.create(pro.id, pro.username, eventType.id, {});
|
||||||
|
await pro.login();
|
||||||
|
await page.goto("/bookings/upcoming");
|
||||||
|
await expect(page.locator("data-testid=wipe-today-button")).toBeVisible();
|
||||||
|
|
||||||
|
const totalUserBookings = await prisma.booking.findMany({
|
||||||
|
where: {
|
||||||
|
userId: pro.id,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
expect(totalUserBookings?.length).toBe(3);
|
||||||
|
await page.locator("data-testid=wipe-today-button").click();
|
||||||
|
await page.locator("data-testid=send_request").click();
|
||||||
|
// eslint-disable-next-line playwright/no-wait-for-timeout
|
||||||
|
await page.waitForTimeout(250);
|
||||||
|
const totalUserBookingsCancelled = await prisma.booking.findMany({
|
||||||
|
where: {
|
||||||
|
userId: pro.id,
|
||||||
|
status: "CANCELLED",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
await expect(totalUserBookingsCancelled?.length).toBe(1);
|
||||||
|
await users.deleteAll();
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -139,19 +139,6 @@ const Reschedule = async (bookingUid: string, cancellationReason: string) => {
|
|||||||
logger.error(error.message);
|
logger.error(error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Creating cancelled event as placeholders in calendars, remove when virtual calendar handles it
|
|
||||||
try {
|
|
||||||
const eventManager = new EventManager({
|
|
||||||
credentials: userOwner.credentials,
|
|
||||||
destinationCalendar: userOwner.destinationCalendar,
|
|
||||||
});
|
|
||||||
builder.calendarEvent.title = `Cancelled: ${builder.calendarEvent.title}`;
|
|
||||||
await eventManager.updateAndSetCancelledPlaceholder(builder.calendarEvent, bookingToReschedule);
|
|
||||||
} catch (error) {
|
|
||||||
if (error instanceof Error) {
|
|
||||||
logger.error(error.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send emails
|
// Send emails
|
||||||
try {
|
try {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ const handler = async (req: NextApiRequest, res: NextApiResponse) => {
|
|||||||
if (!req.session?.user?.id) {
|
if (!req.session?.user?.id) {
|
||||||
return res.status(401).json({ message: "You must be logged in to do this" });
|
return res.status(401).json({ message: "You must be logged in to do this" });
|
||||||
}
|
}
|
||||||
let result = false;
|
|
||||||
try {
|
try {
|
||||||
const { initialDate, endDate } = req.body;
|
const { initialDate, endDate } = req.body;
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ const wipeMyCalAction = async (props: IWipeMyCalAction) => {
|
|||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
const endpoint = "/api/integrations/wipemycalother/wipe";
|
const endpoint = "/api/integrations/wipemycalother/wipe";
|
||||||
return fetch(`${process.env.NEXT_PUBLIC_APP_BASE_URL}` + endpoint, {
|
return fetch(`${process.env.NEXT_PUBLIC_WEBAPP_URL}` + endpoint, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
@@ -81,7 +81,7 @@ export const ConfirmDialog = (props: IConfirmDialogWipe) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={isOpenDialog} onOpenChange={setIsOpenDialog}>
|
<Dialog open={isOpenDialog} onOpenChange={setIsOpenDialog}>
|
||||||
<DialogContent>
|
<DialogContent onOpenAutoFocus={(e) => e.preventDefault()}>
|
||||||
<div className="flex flex-row space-x-3">
|
<div className="flex flex-row space-x-3">
|
||||||
<div className="flex h-10 w-10 flex-shrink-0 justify-center rounded-full bg-[#FAFAFA]">
|
<div className="flex h-10 w-10 flex-shrink-0 justify-center rounded-full bg-[#FAFAFA]">
|
||||||
<ClockIcon className="m-auto h-6 w-6"></ClockIcon>
|
<ClockIcon className="m-auto h-6 w-6"></ClockIcon>
|
||||||
@@ -99,9 +99,10 @@ export const ConfirmDialog = (props: IConfirmDialogWipe) => {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<DialogFooter>
|
<DialogFooter>
|
||||||
<DialogClose>
|
<Button color="secondary" onClick={() => setIsOpenDialog(false)}>
|
||||||
<Button color="secondary">{t("cancel")}</Button>
|
{t("cancel")}
|
||||||
</DialogClose>
|
</Button>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
data-testid="send_request"
|
data-testid="send_request"
|
||||||
disabled={isLoading}
|
disabled={isLoading}
|
||||||
|
|||||||
@@ -32,7 +32,9 @@ const WipeMyCalActionButton = (props: IWipeMyCalActionButtonProps) => {
|
|||||||
{data && isSuccess && !isLoading && credentialId && (
|
{data && isSuccess && !isLoading && credentialId && (
|
||||||
<>
|
<>
|
||||||
<ConfirmDialog trpc={trpc} isOpenDialog={openDialog} setIsOpenDialog={setOpenDialog} />
|
<ConfirmDialog trpc={trpc} isOpenDialog={openDialog} setIsOpenDialog={setOpenDialog} />
|
||||||
<Button onClick={() => setOpenDialog(true)}>Wipe Today</Button>
|
<Button onClick={() => setOpenDialog(true)} data-testid="wipe-today-button">
|
||||||
|
Wipe Today
|
||||||
|
</Button>
|
||||||
</>
|
</>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ const Reschedule = async (bookingUid: string, cancellationReason: string) => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
const [mainAttendee] = bookingToReschedule.attendees;
|
const [mainAttendee] = bookingToReschedule.attendees;
|
||||||
// @NOTE: Should we assume attendees language?
|
|
||||||
const tAttendees = await getTranslation(mainAttendee.locale ?? "en", "common");
|
const tAttendees = await getTranslation(mainAttendee.locale ?? "en", "common");
|
||||||
const usersToPeopleType = (
|
const usersToPeopleType = (
|
||||||
users: PersonAttendeeCommonFields[],
|
users: PersonAttendeeCommonFields[],
|
||||||
@@ -139,19 +139,6 @@ const Reschedule = async (bookingUid: string, cancellationReason: string) => {
|
|||||||
logger.error(error.message);
|
logger.error(error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Creating cancelled event as placeholders in calendars, remove when virtual calendar handles it
|
|
||||||
try {
|
|
||||||
const eventManager = new EventManager({
|
|
||||||
credentials: userOwner.credentials,
|
|
||||||
destinationCalendar: userOwner.destinationCalendar,
|
|
||||||
});
|
|
||||||
builder.calendarEvent.title = `Cancelled: ${builder.calendarEvent.title}`;
|
|
||||||
await eventManager.updateAndSetCancelledPlaceholder(builder.calendarEvent, bookingToReschedule);
|
|
||||||
} catch (error) {
|
|
||||||
if (error instanceof Error) {
|
|
||||||
logger.error(error.message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send emails
|
// Send emails
|
||||||
try {
|
try {
|
||||||
|
|||||||
Reference in new issue
Block a user