Skip to content

Commit

Permalink
chore: add a/b test and env variables
Browse files Browse the repository at this point in the history
  • Loading branch information
DmytroHryshyn committed Nov 29, 2023
1 parent 79d727e commit 9000e9b
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 2 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -290,3 +290,7 @@ E2E_TEST_OIDC_USER_PASSWORD=
AB_TEST_BUCKET_PROBABILITY=50
# whether we redirect to the future/event-types from event-types or not
APP_ROUTER_EVENT_TYPES_ENABLED=1
# whether we redirect to the future/apps/categories from /apps/categories or not
APP_ROUTER_APPS_CATEGORIES_ENABLED=1
# whether we redirect to the future/apps/categories/[category] from /apps/categories/[category] or not
APP_ROUTER_APPS_CATEGORIES_CATEGORY_ENABLED=1
5 changes: 3 additions & 2 deletions apps/web/abTest/middlewareFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import { NextResponse, URLPattern } from "next/server";
import z from "zod";

const ROUTES: [URLPattern, boolean][] = [
["/event-types", process.env.APP_ROUTER_EVENT_TYPES_ENABLED === "1"] as const,
["/apps/categories", Boolean(process.env.APP_ROUTER_APPS_CATEGORIES_ENABLED)] as const,
["/apps/categories/:category", Boolean(process.env.APP_ROUTER_APPS_CATEGORIES_CATEGORY_ENABLED)] as const,
["/event-types", Boolean(process.env.APP_ROUTER_EVENT_TYPES_ENABLED)] as const,
].map(([pathname, enabled]) => [
new URLPattern({
pathname,
Expand All @@ -27,7 +29,6 @@ export const abTestMiddlewareFactory =
const override = req.cookies.has(FUTURE_ROUTES_OVERRIDE_COOKIE_NAME);

const route = ROUTES.find(([regExp]) => regExp.test(req.url)) ?? null;

const enabled = route !== null ? route[1] || override : false;

if (pathname.includes("future") || !enabled) {
Expand Down
6 changes: 6 additions & 0 deletions apps/web/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ export const config = {
"/apps/routing_forms/:path*",
"/event-types",
"/future/event-types/",

"/apps/categories/",
"/future/apps/categories/",

"/apps/categories/:category/",
"/future/apps/categories/:category/",
],
};

Expand Down
61 changes: 61 additions & 0 deletions apps/web/playwright/ab-tests-redirect.e2e.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { expect } from "@playwright/test";

import { test } from "./lib/fixtures";

test.describe.configure({ mode: "parallel" });

test.describe("apps/ A/B tests", () => {
test("should point to the /future/apps/categories", async ({ page, users, context }) => {
await context.addCookies([
{
name: "x-calcom-future-routes-override",
value: "1",
url: "http://localhost:3000",
},
]);
const user = await users.create();

await user.apiLogin();

await page.goto("/apps/categories");

await page.waitForLoadState();

const dataNextJsRouter = await page.evaluate(() =>
window.document.documentElement.getAttribute("data-nextjs-router")
);

expect(dataNextJsRouter).toEqual("app");

const locator = page.getByTestId("app-store-category-messaging");

await expect(locator).toBeVisible();
});

test("should point to the /future/apps/categories/[category]", async ({ page, users, context }) => {
await context.addCookies([
{
name: "x-calcom-future-routes-override",
value: "1",
url: "http://localhost:3000",
},
]);
const user = await users.create();

await user.apiLogin();

await page.goto("/apps/categories/messaging");

await page.waitForLoadState();

const dataNextJsRouter = await page.evaluate(() =>
window.document.documentElement.getAttribute("data-nextjs-router")
);

expect(dataNextJsRouter).toEqual("app");

const locator = page.getByText(/messaging apps/i);

await expect(locator).toBeVisible();
});
});
2 changes: 2 additions & 0 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,8 @@
"ANALYZE",
"API_KEY_PREFIX",
"APP_ROUTER_EVENT_TYPES_ENABLED",
"APP_ROUTER_APPS_CATEGORIES_CATEGORY_ENABLED",
"APP_ROUTER_APPS_CATEGORIES_ENABLED",
"APP_USER_NAME",
"BASECAMP3_CLIENT_ID",
"BASECAMP3_CLIENT_SECRET",
Expand Down

0 comments on commit 9000e9b

Please sign in to comment.