From 74803dc12281ce53c8ecc2851dc423d8f8e51deb Mon Sep 17 00:00:00 2001 From: DmytroHryshyn <125881252+DmytroHryshyn@users.noreply.github.com> Date: Fri, 19 Jan 2024 15:02:34 +0200 Subject: [PATCH] fix: fix-e2e-tests (#13330) --- .../apps/categories/getServerSideProps.tsx | 4 +- apps/web/lib/apps/getServerSideProps.tsx | 4 +- apps/web/lib/buildLegacyCtx.tsx | 30 +++++------ .../[[...step]]/getServerSideProps.tsx | 4 +- .../lib/video/[uid]/getServerSideProps.tsx | 4 +- apps/web/pages/auth/forgot-password/index.tsx | 3 +- apps/web/pages/auth/setup/index.tsx | 4 +- apps/web/pages/auth/signin.tsx | 4 +- apps/web/pages/auth/sso/[provider].tsx | 4 +- apps/web/playwright/ab-tests-redirect.e2e.ts | 53 +++++++++++++++---- 10 files changed, 73 insertions(+), 41 deletions(-) diff --git a/apps/web/lib/apps/categories/getServerSideProps.tsx b/apps/web/lib/apps/categories/getServerSideProps.tsx index 80f91be001..db3f86519c 100644 --- a/apps/web/lib/apps/categories/getServerSideProps.tsx +++ b/apps/web/lib/apps/categories/getServerSideProps.tsx @@ -6,11 +6,11 @@ import { getServerSession } from "@calcom/features/auth/lib/getServerSession"; import { ssrInit } from "@server/lib/ssr"; export const getServerSideProps = async (context: GetServerSidePropsContext) => { - const { req, res } = context; + const { req } = context; const ssr = await ssrInit(context); - const session = await getServerSession({ req, res }); + const session = await getServerSession({ req }); let appStore; if (session?.user?.id) { diff --git a/apps/web/lib/apps/getServerSideProps.tsx b/apps/web/lib/apps/getServerSideProps.tsx index c0a3e2acc0..e662f3cf17 100644 --- a/apps/web/lib/apps/getServerSideProps.tsx +++ b/apps/web/lib/apps/getServerSideProps.tsx @@ -9,11 +9,11 @@ import type { AppCategories } from "@calcom/prisma/enums"; import { ssrInit } from "@server/lib/ssr"; export const getServerSideProps = async (context: GetServerSidePropsContext) => { - const { req, res } = context; + const { req } = context; const ssr = await ssrInit(context); - const session = await getServerSession({ req, res }); + const session = await getServerSession({ req }); let appStore, userAdminTeams: UserAdminTeams; if (session?.user?.id) { diff --git a/apps/web/lib/buildLegacyCtx.tsx b/apps/web/lib/buildLegacyCtx.tsx index 3aa9372de7..14430210a3 100644 --- a/apps/web/lib/buildLegacyCtx.tsx +++ b/apps/web/lib/buildLegacyCtx.tsx @@ -32,22 +32,18 @@ export const buildLegacyCtx = ( params: Params, searchParams: SearchParams ) => { - return new Proxy>( - { - query: { ...searchParams, ...params }, - params, - req: { headers: buildLegacyHeaders(headers), cookies: buildLegacyCookies(cookies) }, - }, - { - get(obj, prop) { - if (prop === "res") { - throw new Error( - "You are trying to access the 'res' property of the context, which is not supported in app dir" - ); - } - - return obj[prop as keyof typeof obj]; + return { + query: { ...searchParams, ...params }, + params, + req: { headers: buildLegacyHeaders(headers), cookies: buildLegacyCookies(cookies) }, + res: new Proxy(Object.create(null), { + // const { req, res } = ctx - valid + // res.anything - throw + get() { + throw new Error( + "You are trying to access the 'res' property of the context, which is not supported in app dir" + ); }, - } - ) as unknown as GetServerSidePropsContext; + }), + } as unknown as GetServerSidePropsContext; }; diff --git a/apps/web/lib/getting-started/[[...step]]/getServerSideProps.tsx b/apps/web/lib/getting-started/[[...step]]/getServerSideProps.tsx index e6fa841c67..7163afa276 100644 --- a/apps/web/lib/getting-started/[[...step]]/getServerSideProps.tsx +++ b/apps/web/lib/getting-started/[[...step]]/getServerSideProps.tsx @@ -8,9 +8,9 @@ import prisma from "@calcom/prisma"; import { ssrInit } from "@server/lib/ssr"; export const getServerSideProps = async (context: GetServerSidePropsContext) => { - const { req, res } = context; + const { req } = context; - const session = await getServerSession({ req, res }); + const session = await getServerSession({ req }); if (!session?.user?.id) { return { redirect: { permanent: false, destination: "/auth/login" } }; diff --git a/apps/web/lib/video/[uid]/getServerSideProps.tsx b/apps/web/lib/video/[uid]/getServerSideProps.tsx index 6052f58a4c..a0d6d78896 100644 --- a/apps/web/lib/video/[uid]/getServerSideProps.tsx +++ b/apps/web/lib/video/[uid]/getServerSideProps.tsx @@ -10,7 +10,7 @@ import { ssrInit } from "@server/lib/ssr"; const md = new MarkdownIt("default", { html: true, breaks: true, linkify: true }); export async function getServerSideProps(context: GetServerSidePropsContext) { - const { req, res } = context; + const { req } = context; const ssr = await ssrInit(context); @@ -79,7 +79,7 @@ export async function getServerSideProps(context: GetServerSidePropsContext) { endTime: booking.endTime.toString(), }); - const session = await getServerSession({ req, res }); + const session = await getServerSession({ req }); // set meetingPassword to null for guests if (session?.user.id !== bookingObj.user?.id) { diff --git a/apps/web/pages/auth/forgot-password/index.tsx b/apps/web/pages/auth/forgot-password/index.tsx index fe68bc4e99..6e7df24840 100644 --- a/apps/web/pages/auth/forgot-password/index.tsx +++ b/apps/web/pages/auth/forgot-password/index.tsx @@ -148,8 +148,9 @@ ForgotPassword.PageWrapper = PageWrapper; export const getServerSideProps = async (context: GetServerSidePropsContext) => { const { req, res } = context; - const session = await getServerSession({ req, res }); + const session = await getServerSession({ req }); + // @TODO res will not be available in future pages (app dir) if (session) { res.writeHead(302, { Location: "/" }); res.end(); diff --git a/apps/web/pages/auth/setup/index.tsx b/apps/web/pages/auth/setup/index.tsx index bc128f4cff..89830d3613 100644 --- a/apps/web/pages/auth/setup/index.tsx +++ b/apps/web/pages/auth/setup/index.tsx @@ -153,12 +153,12 @@ Setup.PageWrapper = PageWrapper; export default Setup; export const getServerSideProps = async (context: GetServerSidePropsContext) => { - const { req, res } = context; + const { req } = context; const ssr = await ssrInit(context); const userCount = await prisma.user.count(); - const session = await getServerSession({ req, res }); + const session = await getServerSession({ req }); if (session?.user.role && session?.user.role !== UserPermissionRole.ADMIN) { return { diff --git a/apps/web/pages/auth/signin.tsx b/apps/web/pages/auth/signin.tsx index 295879ddd3..8ac84add2a 100644 --- a/apps/web/pages/auth/signin.tsx +++ b/apps/web/pages/auth/signin.tsx @@ -30,9 +30,9 @@ signin.PageWrapper = PageWrapper; export default signin; export async function getServerSideProps(context: GetServerSidePropsContext) { - const { req, res } = context; + const { req } = context; - const session = await getServerSession({ req, res }); + const session = await getServerSession({ req }); const csrfToken = await getCsrfToken(context); const providers = await getProviders(); if (session) { diff --git a/apps/web/pages/auth/sso/[provider].tsx b/apps/web/pages/auth/sso/[provider].tsx index 7337b4b311..f1a2e759ba 100644 --- a/apps/web/pages/auth/sso/[provider].tsx +++ b/apps/web/pages/auth/sso/[provider].tsx @@ -63,9 +63,9 @@ export const getServerSideProps = async (context: GetServerSidePropsContext) => throw new Error(`File is not named sso/[provider]`); } - const { req, res } = context; + const { req } = context; - const session = await getServerSession({ req, res }); + const session = await getServerSession({ req }); const ssr = await ssrInit(context); const { currentOrgDomain } = orgDomainConfig(context.req); diff --git a/apps/web/playwright/ab-tests-redirect.e2e.ts b/apps/web/playwright/ab-tests-redirect.e2e.ts index b3fd798349..24dd82ccd4 100644 --- a/apps/web/playwright/ab-tests-redirect.e2e.ts +++ b/apps/web/playwright/ab-tests-redirect.e2e.ts @@ -1,3 +1,4 @@ +import type { Page } from "@playwright/test"; import { expect } from "@playwright/test"; import { test } from "./lib/fixtures"; @@ -5,8 +6,16 @@ import { testBothFutureAndLegacyRoutes } from "./lib/future-legacy-routes"; test.describe.configure({ mode: "parallel" }); +const ensureAppDir = async (page: Page) => { + const dataNextJsRouter = await page.evaluate(() => + window.document.documentElement.getAttribute("data-nextjs-router") + ); + + expect(dataNextJsRouter).toEqual("app"); +}; + testBothFutureAndLegacyRoutes.describe("apps/ A/B tests", (routeVariant) => { - test("should render the /apps/installed/[category]", async ({ page, users, context }) => { + test("should render the /apps/installed/[category]", async ({ page, users }) => { const user = await users.create(); await user.apiLogin(); @@ -15,10 +24,14 @@ testBothFutureAndLegacyRoutes.describe("apps/ A/B tests", (routeVariant) => { const locator = page.getByRole("heading", { name: "Messaging" }); + if (routeVariant === "future") { + await ensureAppDir(page); + } + await expect(locator).toBeVisible(); }); - test("should render the /apps/[slug]", async ({ page, users, context }) => { + test("should render the /apps/[slug]", async ({ page, users }) => { const user = await users.create(); await user.apiLogin(); @@ -27,10 +40,14 @@ testBothFutureAndLegacyRoutes.describe("apps/ A/B tests", (routeVariant) => { const locator = page.getByRole("heading", { name: "Telegram" }); + if (routeVariant === "future") { + await ensureAppDir(page); + } + await expect(locator).toBeVisible(); }); - test("should render the /apps/[slug]/setup", async ({ page, users, context }) => { + test("should render the /apps/[slug]/setup", async ({ page, users }) => { const user = await users.create(); await user.apiLogin(); @@ -39,11 +56,14 @@ testBothFutureAndLegacyRoutes.describe("apps/ A/B tests", (routeVariant) => { const locator = page.getByRole("heading", { name: "Connect to Apple Server" }); + if (routeVariant === "future") { + await ensureAppDir(page); + } + await expect(locator).toBeVisible(); }); - test("should render the /apps/categories", async ({ page, users, context }) => { - test.skip(routeVariant === "future", "Future route not ready yet"); + test("should render the /apps/categories", async ({ page, users }) => { const user = await users.create(); await user.apiLogin(); @@ -52,10 +72,14 @@ testBothFutureAndLegacyRoutes.describe("apps/ A/B tests", (routeVariant) => { const locator = page.getByTestId("app-store-category-messaging"); + if (routeVariant === "future") { + await ensureAppDir(page); + } + await expect(locator).toBeVisible(); }); - test("should render the /apps/categories/[category]", async ({ page, users, context }) => { + test("should render the /apps/categories/[category]", async ({ page, users }) => { const user = await users.create(); await user.apiLogin(); @@ -64,10 +88,14 @@ testBothFutureAndLegacyRoutes.describe("apps/ A/B tests", (routeVariant) => { const locator = page.getByText(/messaging apps/i); + if (routeVariant === "future") { + await ensureAppDir(page); + } + await expect(locator).toBeVisible(); }); - test("should render the /bookings/[status]", async ({ page, users, context }) => { + test("should render the /bookings/[status]", async ({ page, users }) => { const user = await users.create(); await user.apiLogin(); @@ -76,11 +104,14 @@ testBothFutureAndLegacyRoutes.describe("apps/ A/B tests", (routeVariant) => { const locator = page.getByTestId("horizontal-tab-upcoming"); + if (routeVariant === "future") { + await ensureAppDir(page); + } + await expect(locator).toHaveClass(/bg-emphasis/); }); - test("should render the /getting-started", async ({ page, users, context }) => { - test.skip(routeVariant === "future", "Future route not ready yet"); + test("should render the /getting-started", async ({ page, users }) => { const user = await users.create({ completedOnboarding: false, name: null }); await user.apiLogin(); @@ -89,6 +120,10 @@ testBothFutureAndLegacyRoutes.describe("apps/ A/B tests", (routeVariant) => { const locator = page.getByText("Apple Calendar"); + if (routeVariant === "future") { + await ensureAppDir(page); + } + await expect(locator).toBeVisible(); }); });