diff --git a/apps/web/playwright/app-store.e2e.ts b/apps/web/playwright/app-store.e2e.ts index 64d6926337..4130bae2fb 100644 --- a/apps/web/playwright/app-store.e2e.ts +++ b/apps/web/playwright/app-store.e2e.ts @@ -4,6 +4,8 @@ import { test } from "./lib/fixtures"; test.describe.configure({ mode: "parallel" }); +test.afterEach(({ users }) => users.deleteAll()); + test.describe("App Store - Authed", () => { test("Browse apple-calendar and try to install", async ({ page, users }) => { const pro = await users.create(); @@ -12,7 +14,6 @@ test.describe("App Store - Authed", () => { await page.click('[data-testid="app-store-app-card-apple-calendar"]'); await page.click('[data-testid="install-app-button"]'); await expect(page.locator(`text=Connect to Apple Server`)).toBeVisible(); - await pro.delete(); }); test("Installed Apps - Navigation", async ({ page, users }) => { diff --git a/apps/web/playwright/auth/delete-account.e2e.ts b/apps/web/playwright/auth/delete-account.e2e.ts index 367870108a..61c976b932 100644 --- a/apps/web/playwright/auth/delete-account.e2e.ts +++ b/apps/web/playwright/auth/delete-account.e2e.ts @@ -2,6 +2,8 @@ import { expect } from "@playwright/test"; import { test } from "../lib/fixtures"; +test.afterEach(({ users }) => users.deleteAll()); + test("Can delete user account", async ({ page, users }) => { const user = await users.create({ username: "delete-me", diff --git a/apps/web/playwright/auth/forgot-password.e2e.ts b/apps/web/playwright/auth/forgot-password.e2e.ts index 011620954e..ac82c2a7d4 100644 --- a/apps/web/playwright/auth/forgot-password.e2e.ts +++ b/apps/web/playwright/auth/forgot-password.e2e.ts @@ -2,6 +2,8 @@ import { expect } from "@playwright/test"; import { test } from "../lib/fixtures"; +test.afterEach(({ users }) => users.deleteAll()); + test("Can reset forgotten password", async ({ page, users }) => { test.skip(process.env.NEXT_PUBLIC_IS_E2E !== "1", "It shouldn't if we can't skip email"); const user = await users.create(); @@ -47,6 +49,4 @@ test("Can reset forgotten password", async ({ page, users }) => { await page.waitForSelector("[data-testid=dashboard-shell]"); await expect(page.locator("[data-testid=dashboard-shell]")).toBeVisible(); - - await users.deleteAll(); }); diff --git a/apps/web/playwright/booking-pages.e2e.ts b/apps/web/playwright/booking-pages.e2e.ts index 718fc36f6c..ad21965203 100644 --- a/apps/web/playwright/booking-pages.e2e.ts +++ b/apps/web/playwright/booking-pages.e2e.ts @@ -10,15 +10,13 @@ import { } from "./lib/testUtils"; test.describe.configure({ mode: "parallel" }); +test.afterEach(async ({ users }) => users.deleteAll()); test.describe("free user", () => { test.beforeEach(async ({ page, users }) => { const free = await users.create(); await page.goto(`/${free.username}`); }); - test.afterEach(async ({ users }) => { - await users.deleteAll(); - }); test("cannot book same slot multiple times", async ({ page }) => { // Click first event type @@ -58,9 +56,6 @@ test.describe("pro user", () => { const pro = await users.create(); await page.goto(`/${pro.username}`); }); - test.afterEach(async ({ users }) => { - await users.deleteAll(); - }); test("pro user's page has at least 2 visible events", async ({ page }) => { // await page.pause(); diff --git a/apps/web/playwright/change-password.e2e.ts b/apps/web/playwright/change-password.e2e.ts index bbbbe1e6a2..45f3de2d29 100644 --- a/apps/web/playwright/change-password.e2e.ts +++ b/apps/web/playwright/change-password.e2e.ts @@ -24,6 +24,6 @@ test.describe("Change Password Test", () => { const toast = await page.waitForSelector("div[class*='data-testid-toast-success']"); - await expect(toast).toBeTruthy(); + expect(toast).toBeTruthy(); }); }); diff --git a/apps/web/playwright/dynamic-booking-pages.e2e.ts b/apps/web/playwright/dynamic-booking-pages.e2e.ts index 83d76c7a0d..f745806ded 100644 --- a/apps/web/playwright/dynamic-booking-pages.e2e.ts +++ b/apps/web/playwright/dynamic-booking-pages.e2e.ts @@ -7,6 +7,8 @@ import { selectSecondAvailableTimeSlotNextMonth, } from "./lib/testUtils"; +test.afterEach(({ users }) => users.deleteAll()); + test("dynamic booking", async ({ page, users }) => { const pro = await users.create(); await pro.login(); @@ -55,8 +57,6 @@ test("dynamic booking", async ({ page, users }) => { const cancelledHeadline = await page.locator('[data-testid="cancelled-headline"]').innerText(); - await expect(cancelledHeadline).toBe("This event is cancelled"); + expect(cancelledHeadline).toBe("This event is cancelled"); }); - - await users.deleteAll(); }); diff --git a/apps/web/playwright/embed-code-generator.e2e.ts b/apps/web/playwright/embed-code-generator.e2e.ts index 30579183c6..45cc1986a1 100644 --- a/apps/web/playwright/embed-code-generator.e2e.ts +++ b/apps/web/playwright/embed-code-generator.e2e.ts @@ -88,6 +88,8 @@ async function expectToContainValidPreviewIframe( test.describe.configure({ mode: "parallel" }); +test.afterEach(({ users }) => users.deleteAll()); + test.describe("Embed Code Generator Tests", () => { test.beforeEach(async ({ users }) => { const pro = await users.create(); diff --git a/apps/web/playwright/fixtures/users.ts b/apps/web/playwright/fixtures/users.ts index f6d675272f..33f929c3f5 100644 --- a/apps/web/playwright/fixtures/users.ts +++ b/apps/web/playwright/fixtures/users.ts @@ -1,7 +1,7 @@ import type { Page, WorkerInfo } from "@playwright/test"; import type Prisma from "@prisma/client"; import { MembershipRole, Prisma as PrismaType } from "@prisma/client"; -import { hash } from "bcryptjs"; +import { hashSync as hash } from "bcryptjs"; import dayjs from "@calcom/dayjs"; import { DEFAULT_SCHEDULE, getAvailabilityFromSchedule } from "@calcom/lib/availability"; @@ -10,8 +10,8 @@ import { prisma } from "@calcom/prisma"; import type { TimeZoneEnum } from "./types"; // Don't import hashPassword from app as that ends up importing next-auth and initializing it before NEXTAUTH_URL can be updated during tests. -export async function hashPassword(password: string) { - const hashedPassword = await hash(password, 12); +export function hashPassword(password: string) { + const hashedPassword = hash(password, 12); return hashedPassword; } @@ -297,17 +297,14 @@ type CustomUserOptsKeys = "username" | "password" | "completedOnboarding" | "loc type CustomUserOpts = Partial> & { timeZone?: TimeZoneEnum }; // creates the actual user in the db. -const createUser = async ( - workerInfo: WorkerInfo, - opts?: CustomUserOpts | null -): Promise => { +const createUser = (workerInfo: WorkerInfo, opts?: CustomUserOpts | null): PrismaType.UserCreateInput => { // build a unique name for our user const uname = `${opts?.username || "user"}-${workerInfo.workerIndex}-${Date.now()}`; return { username: uname, name: opts?.name, email: `${uname}@example.com`, - password: await hashPassword(uname), + password: hashPassword(uname), emailVerified: new Date(), completedOnboarding: opts?.completedOnboarding ?? true, timeZone: opts?.timeZone ?? dayjs.tz.guess(), diff --git a/apps/web/playwright/integrations-stripe.e2e.ts b/apps/web/playwright/integrations-stripe.e2e.ts index 6757be33ba..389ebc477e 100644 --- a/apps/web/playwright/integrations-stripe.e2e.ts +++ b/apps/web/playwright/integrations-stripe.e2e.ts @@ -4,6 +4,7 @@ import { test } from "./lib/fixtures"; import { selectFirstAvailableTimeSlotNextMonth, todo } from "./lib/testUtils"; test.describe.configure({ mode: "parallel" }); +test.afterEach(({ users }) => users.deleteAll()); const IS_STRIPE_ENABLED = !!( process.env.STRIPE_CLIENT_ID && @@ -32,9 +33,6 @@ test.describe("Stripe integration", () => { await expect( page.locator(`li:has-text("Stripe") >> [data-testid="stripe_payment-integration-disconnect-button"]`) ).toContainText(""); - - // Cleanup - await users.deleteAll(); }); }); @@ -70,9 +68,6 @@ test.describe("Stripe integration", () => { // Make sure we're navigated to the success page await expect(page.locator("[data-testid=success-page]")).toBeVisible(); - - // Cleanup - await users.deleteAll(); }); todo("Pending payment booking should not be confirmed by default"); diff --git a/apps/web/playwright/integrations.e2e.ts b/apps/web/playwright/integrations.e2e.ts index 3b89b19013..0e8a6e90ea 100644 --- a/apps/web/playwright/integrations.e2e.ts +++ b/apps/web/playwright/integrations.e2e.ts @@ -159,6 +159,7 @@ test.afterEach(() => requestInterceptor.resetHandlers()); // Disable API mocking after the tests are done. test.afterAll(() => requestInterceptor.close()); +test.afterEach(({ users }) => users.deleteAll()); // TODO: Fix MSW mocking test.fixme("Integrations", () => { @@ -210,17 +211,6 @@ test.fixme("Integrations", () => { }); }; test.describe("Zoom App", () => { - test.afterEach(async () => { - await prisma?.credential.deleteMany({ - where: { - user: { - email: "pro@example.com", - }, - type: "zoom_video", - }, - }); - }); - test("Can add integration", async ({ page, users }) => { const user = await users.create(); await user.login(); diff --git a/apps/web/playwright/lib/testUtils.ts b/apps/web/playwright/lib/testUtils.ts index ef64586a92..b97f5f29f5 100644 --- a/apps/web/playwright/lib/testUtils.ts +++ b/apps/web/playwright/lib/testUtils.ts @@ -1,9 +1,11 @@ import type { Page } from "@playwright/test"; -import { expect, test } from "@playwright/test"; +import { expect } from "@playwright/test"; import type { IncomingMessage, ServerResponse } from "http"; import { createServer } from "http"; import noop from "lodash/noop"; +import { test } from "./fixtures"; + export function todo(title: string) { // eslint-disable-next-line playwright/no-skipped-test test.skip(title, noop); diff --git a/apps/web/playwright/onboarding.e2e.ts b/apps/web/playwright/onboarding.e2e.ts index edc166fb08..664ee7178c 100644 --- a/apps/web/playwright/onboarding.e2e.ts +++ b/apps/web/playwright/onboarding.e2e.ts @@ -5,6 +5,8 @@ import { test } from "./lib/fixtures"; test.describe.configure({ mode: "serial" }); +test.afterEach(({ users }) => users.deleteAll()); + test.describe("Onboarding", () => { test.describe("Onboarding v2", () => { test("Onboarding Flow", async ({ page, users }) => { diff --git a/apps/web/playwright/reschedule.e2e.ts b/apps/web/playwright/reschedule.e2e.ts index d69470daa6..bf50b7dabd 100644 --- a/apps/web/playwright/reschedule.e2e.ts +++ b/apps/web/playwright/reschedule.e2e.ts @@ -14,10 +14,9 @@ const IS_STRIPE_ENABLED = !!( test.describe.configure({ mode: "parallel" }); +test.afterEach(({ users }) => users.deleteAll()); + test.describe("Reschedule Tests", async () => { - test.afterEach(async ({ users }) => { - await users.deleteAll(); - }); test("Should do a booking request reschedule from /bookings", async ({ page, users, bookings }) => { const user = await users.create(); diff --git a/apps/web/playwright/teams.e2e.ts b/apps/web/playwright/teams.e2e.ts index d31cbefaa2..1305bf7222 100644 --- a/apps/web/playwright/teams.e2e.ts +++ b/apps/web/playwright/teams.e2e.ts @@ -1,14 +1,14 @@ import { expect } from "@playwright/test"; +import { prisma } from "@calcom/prisma"; + import { test } from "./lib/fixtures"; test.describe.configure({ mode: "parallel" }); -test.describe("Teams", () => { - test.afterEach(async ({ users }) => { - await users.deleteAll(); - }); +test.afterEach(({ users }) => users.deleteAll()); +test.describe("Teams", () => { test("Can create teams via Wizard", async ({ page, users }) => { const user = await users.create(); const inviteeEmail = `${user.username}+invitee@example.com`; @@ -44,6 +44,8 @@ test.describe("Teams", () => { await removeMemberButton.click(); await removeMemberButton.waitFor({ state: "hidden" }); expect(await page.locator('[data-testid="pending-member-item"]').count()).toBe(1); + // Cleanup here since this user is created without our fixtures. + await prisma.user.delete({ where: { email: inviteeEmail } }); }); await test.step("Can publish team", async () => { diff --git a/apps/web/playwright/webhook.e2e.ts b/apps/web/playwright/webhook.e2e.ts index 725311650a..6440e1a5e0 100644 --- a/apps/web/playwright/webhook.e2e.ts +++ b/apps/web/playwright/webhook.e2e.ts @@ -3,6 +3,8 @@ import { expect } from "@playwright/test"; import { test } from "./lib/fixtures"; import { createHttpServer, selectFirstAvailableTimeSlotNextMonth, waitFor } from "./lib/testUtils"; +test.afterEach(({ users }) => users.deleteAll()); + test("add webhook & test that creating an event triggers a webhook call", async ({ page, users, diff --git a/apps/web/playwright/wipe-my-cal.e2e.ts b/apps/web/playwright/wipe-my-cal.e2e.ts index da7e6ad0bd..47a327d625 100644 --- a/apps/web/playwright/wipe-my-cal.e2e.ts +++ b/apps/web/playwright/wipe-my-cal.e2e.ts @@ -7,6 +7,8 @@ import { test } from "./lib/fixtures"; test.describe.configure({ mode: "parallel" }); +test.afterEach(({ users }) => users.deleteAll()); + test.describe("Wipe my Cal App Test", () => { test("Browse upcoming bookings and validate button shows and triggering wipe my cal button", async ({ page, @@ -47,7 +49,5 @@ test.describe("Wipe my Cal App Test", () => { page.locator("data-testid=send_request").click(); // There will not be any today-bookings await expect(page.locator('[data-testid="today-bookings"]')).toBeHidden(); - - await users.deleteAll(); }); });