Zoom/Hubspot Tests with MSW mocking of requests initiated from Next.js server (#3210)
* Add code from previous PR * Remove env variables from wrong place * Fix tests * Remove dead code * Package.json updates * Fix eslint error * Fix issue due to conflict resolution Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> Co-authored-by: zomars <[email protected]>
This commit is contained in:
20 files changed
+916
-106
No files matched your search
@@ -10,8 +10,10 @@
|
||||
"dev": "next dev",
|
||||
"dx": "yarn dev",
|
||||
"test": "dotenv -e ./test/.env.test -- jest",
|
||||
"test-e2e": "NEXT_PUBLIC_IS_E2E=1 yarn playwright test --config=../../tests/config/playwright.config.ts --project=chromium",
|
||||
"test-e2e-integrations": "NEXT_PUBLIC_IS_E2E=1 yarn playwright test --config=playwright-integrations/config/playwright.config.ts --project=chromium",
|
||||
"test-e2e-integrations-quick": "QUICK=true E2E_DEV_SERVER=1 yarn test-e2e-integrations",
|
||||
"db-setup-tests": "dotenv -e ./test/.env.test -- yarn workspace @calcom/prisma prisma generate",
|
||||
"test-e2e": "cd ../.. && yarn playwright test --config=tests/config/playwright.config.ts --project=chromium",
|
||||
"playwright-report": "playwright show-report playwright/reports/playwright-html-report",
|
||||
"test-codegen": "yarn playwright codegen http://localhost:3000",
|
||||
"type-check": "tsc --pretty --noEmit",
|
||||
@@ -132,6 +134,7 @@
|
||||
"@types/accept-language-parser": "1.5.2",
|
||||
"@types/async": "^3.2.15",
|
||||
"@types/bcryptjs": "^2.4.2",
|
||||
"@types/detect-port": "^1.3.2",
|
||||
"@types/glidejs__glide": "^3.4.2",
|
||||
"@types/jest": "^28.1.7",
|
||||
"@types/lodash": "^4.14.182",
|
||||
@@ -150,6 +153,7 @@
|
||||
"@types/stripe": "^8.0.417",
|
||||
"@types/uuid": "8.3.1",
|
||||
"autoprefixer": "^10.4.7",
|
||||
"detect-port": "^1.3.0",
|
||||
"babel-jest": "^28.1.0",
|
||||
"copy-webpack-plugin": "^11.0.0",
|
||||
"env-cmd": "^10.1.0",
|
||||
@@ -159,6 +163,7 @@
|
||||
"jest-mock-extended": "^2.0.7",
|
||||
"mockdate": "^3.0.5",
|
||||
"module-alias": "^2.2.2",
|
||||
"msw": "^0.42.3",
|
||||
"postcss": "^8.4.13",
|
||||
"tailwindcss": "^3.1.6",
|
||||
"ts-jest": "^28.0.8",
|
||||
|
||||
@@ -45,7 +45,7 @@ function ConnectOrDisconnectIntegrationButton(props: {
|
||||
<DisconnectIntegration
|
||||
id={credentialId}
|
||||
render={(btnProps) => (
|
||||
<Button {...btnProps} color="warn" data-testid="integration-connection-button">
|
||||
<Button {...btnProps} color="warn" data-testid={type + "-integration-disconnect-button"}>
|
||||
{t("disconnect")}
|
||||
</Button>
|
||||
)}
|
||||
@@ -57,7 +57,7 @@ function ConnectOrDisconnectIntegrationButton(props: {
|
||||
<DisconnectIntegration
|
||||
id={credentialId}
|
||||
render={(btnProps) => (
|
||||
<Button {...btnProps} color="warn" data-testid="integration-connection-button">
|
||||
<Button {...btnProps} color="warn" data-testid={type + "-integration-disconnect-button"}>
|
||||
{t("disconnect")}
|
||||
</Button>
|
||||
)}
|
||||
@@ -100,7 +100,7 @@ interface IntegrationsContainerProps {
|
||||
|
||||
const IntegrationsContainer = ({ variant, className = "" }: IntegrationsContainerProps): JSX.Element => {
|
||||
const { t } = useLocale();
|
||||
const query = trpc.useQuery(["viewer.integrations", { variant, onlyInstalled: true }], { suspense: true });
|
||||
const query = trpc.useQuery(["viewer.integrations", { variant, onlyInstalled: true }]);
|
||||
return (
|
||||
<QueryCell
|
||||
query={query}
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
test-results
|
||||
@@ -0,0 +1,68 @@
|
||||
import { devices, PlaywrightTestConfig } from "@playwright/test";
|
||||
import dotenv from "dotenv";
|
||||
import { addAliases } from "module-alias";
|
||||
import * as path from "path";
|
||||
|
||||
dotenv.config({ path: "./env" });
|
||||
|
||||
// Add aliases for the paths specified in the tsconfig.json file.
|
||||
// This is needed because playwright does not consider tsconfig.json
|
||||
// For more info, see:
|
||||
// https://stackoverflow.com/questions/69023682/typescript-playwright-error-cannot-find-module
|
||||
// https://github.com/microsoft/playwright/issues/7066#issuecomment-983984496
|
||||
addAliases({
|
||||
"@components": __dirname + "/apps/web/components",
|
||||
"@lib": __dirname + "/apps/web/lib",
|
||||
"@server": __dirname + "/apps/web/server",
|
||||
"@ee": __dirname + "/apps/web/ee",
|
||||
});
|
||||
|
||||
const outputDir = path.join(__dirname, "..", "test-results");
|
||||
const testDir = path.join(__dirname, "..", "tests");
|
||||
|
||||
const DEFAULT_NAVIGATION_TIMEOUT = 600000;
|
||||
|
||||
const headless = !!process.env.CI || !!process.env.PLAYWRIGHT_HEADLESS;
|
||||
process.env.PLAYWRIGHT_TEST_BASE_URL = "http://localhost:3000";
|
||||
const quickMode = process.env.QUICK === "true";
|
||||
|
||||
const config: PlaywrightTestConfig = {
|
||||
forbidOnly: !!process.env.CI,
|
||||
retries: 0,
|
||||
workers: quickMode ? 1 : 1,
|
||||
timeout: 60_000,
|
||||
maxFailures: headless ? 10 : undefined,
|
||||
reporter: [
|
||||
[process.env.CI ? "github" : "list"],
|
||||
["html", { outputFolder: path.join(outputDir, "reports/playwright-html-report"), open: "never" }],
|
||||
["junit", { outputFile: path.join(outputDir, "reports/results.xml") }],
|
||||
],
|
||||
outputDir,
|
||||
use: {
|
||||
baseURL: "http://localhost:3000/",
|
||||
locale: "en-US",
|
||||
trace: "retain-on-failure",
|
||||
headless,
|
||||
},
|
||||
projects: [
|
||||
{
|
||||
name: "chromium",
|
||||
testDir,
|
||||
use: {
|
||||
...devices["Desktop Chrome"],
|
||||
/** If navigation takes more than this, then something's wrong, let's fail fast. */
|
||||
navigationTimeout: DEFAULT_NAVIGATION_TIMEOUT,
|
||||
},
|
||||
},
|
||||
/* {
|
||||
name: "firefox",
|
||||
use: { ...devices["Desktop Firefox"] },
|
||||
},
|
||||
{
|
||||
name: "webkit",
|
||||
use: { ...devices["Desktop Safari"] },
|
||||
}, */
|
||||
],
|
||||
};
|
||||
|
||||
export default config;
|
||||
@@ -0,0 +1,51 @@
|
||||
import { test as base } from "@playwright/test";
|
||||
import { Server } from "http";
|
||||
import { rest } from "msw";
|
||||
import type { SetupServerApi } from "msw/node";
|
||||
|
||||
import { nextServer } from "../../playwright-integrations/next-server";
|
||||
import { createBookingsFixture } from "../../playwright/fixtures/bookings";
|
||||
import { createPaymentsFixture } from "../../playwright/fixtures/payments";
|
||||
import { createUsersFixture } from "../../playwright/fixtures/users";
|
||||
|
||||
interface Fixtures {
|
||||
users: ReturnType<typeof createUsersFixture>;
|
||||
bookings: ReturnType<typeof createBookingsFixture>;
|
||||
payments: ReturnType<typeof createPaymentsFixture>;
|
||||
server: Server;
|
||||
requestInterceptor: SetupServerApi;
|
||||
rest: typeof rest;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see https://playwright.dev/docs/test-fixtures
|
||||
*/
|
||||
export const test = base.extend<Fixtures>({
|
||||
users: async ({ page }, use, workerInfo) => {
|
||||
const usersFixture = createUsersFixture(page, workerInfo);
|
||||
await use(usersFixture);
|
||||
},
|
||||
bookings: async ({ page }, use) => {
|
||||
const bookingsFixture = createBookingsFixture(page);
|
||||
await use(bookingsFixture);
|
||||
},
|
||||
payments: async ({ page }, use) => {
|
||||
const payemntsFixture = createPaymentsFixture(page);
|
||||
await use(payemntsFixture);
|
||||
},
|
||||
// This fixture runs for each worker, ensuring that every worker starts it's own Next.js instance on which we can attach MSW
|
||||
// A single worker can run many tests
|
||||
server: [
|
||||
async ({}, use) => {
|
||||
const server = await nextServer();
|
||||
await use(server);
|
||||
server.close();
|
||||
},
|
||||
{
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
//@ts-ignore
|
||||
scope: "worker",
|
||||
auto: true,
|
||||
},
|
||||
],
|
||||
});
|
||||
@@ -0,0 +1,52 @@
|
||||
import detect from "detect-port";
|
||||
import { createServer, Server } from "http";
|
||||
import next from "next";
|
||||
import { parse } from "url";
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-namespace
|
||||
declare let process: {
|
||||
env: {
|
||||
E2E_DEV_SERVER: string;
|
||||
PLAYWRIGHT_TEST_BASE_URL: string;
|
||||
NEXT_PUBLIC_WEBAPP_URL: string;
|
||||
NEXT_PUBLIC_WEBSITE_URL: string;
|
||||
};
|
||||
};
|
||||
|
||||
export const nextServer = async ({ port = 3000 } = { port: 3000 }) => {
|
||||
// eslint-disable-next-line turbo/no-undeclared-env-vars
|
||||
const dev = process.env.E2E_DEV_SERVER === "1" ? true : false;
|
||||
if (dev) {
|
||||
port = await detect(Math.round((1 + Math.random()) * 3000));
|
||||
}
|
||||
process.env.PLAYWRIGHT_TEST_BASE_URL =
|
||||
process.env.NEXT_PUBLIC_WEBAPP_URL =
|
||||
process.env.NEXT_PUBLIC_WEBSITE_URL =
|
||||
"http://localhost:" + port;
|
||||
const app = next({
|
||||
dev: dev,
|
||||
port,
|
||||
hostname: "localhost",
|
||||
});
|
||||
console.log("Started Next Server", { dev, port });
|
||||
|
||||
await app.prepare();
|
||||
const handle = app.getRequestHandler();
|
||||
// start next server on arbitrary port
|
||||
const server: Server = await new Promise((resolve) => {
|
||||
const server = createServer((req, res) => {
|
||||
if (!req.url) {
|
||||
throw new Error("URL not present");
|
||||
}
|
||||
const parsedUrl = parse(req.url, true);
|
||||
handle(req, res, parsedUrl);
|
||||
});
|
||||
server.listen({ port: port }, () => {
|
||||
resolve(server);
|
||||
});
|
||||
server.on("error", (error) => {
|
||||
if (error) throw new Error("Could not start Next.js server -" + error.message);
|
||||
});
|
||||
});
|
||||
return server;
|
||||
};
|
||||
@@ -0,0 +1,430 @@
|
||||
import { expect, Page, Route } from "@playwright/test";
|
||||
import { rest } from "msw";
|
||||
import { setupServer } from "msw/node";
|
||||
import { v4 as uuidv4 } from "uuid";
|
||||
|
||||
import { prisma } from "@calcom/prisma";
|
||||
import {
|
||||
createHttpServer,
|
||||
selectFirstAvailableTimeSlotNextMonth,
|
||||
todo,
|
||||
waitFor,
|
||||
} from "@calcom/web/playwright/lib/testUtils";
|
||||
|
||||
import { test } from "../lib/fixtures";
|
||||
|
||||
declare let global: {
|
||||
E2E_EMAILS?: ({ text: string } | Record<string, unknown>)[];
|
||||
};
|
||||
|
||||
const requestInterceptor = setupServer(
|
||||
rest.post("https://api.hubapi.com/oauth/v1/token", (req, res, ctx) => {
|
||||
console.log(req.body);
|
||||
return res(ctx.status(200));
|
||||
})
|
||||
);
|
||||
requestInterceptor.listen({
|
||||
// Comment this to log which all requests are going that are unmocked
|
||||
onUnhandledRequest: "bypass",
|
||||
});
|
||||
requestInterceptor.use();
|
||||
|
||||
const addOauthBasedIntegration = async function ({
|
||||
page,
|
||||
slug,
|
||||
authorization,
|
||||
token,
|
||||
}: {
|
||||
page: Page;
|
||||
slug: string;
|
||||
authorization: {
|
||||
url: string;
|
||||
verify: (config: {
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
requestHeaders: any;
|
||||
params: URLSearchParams;
|
||||
code: string;
|
||||
}) => Parameters<Route["fulfill"]>[0];
|
||||
};
|
||||
token: {
|
||||
url: string;
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
verify: (config: { requestHeaders: any; params: URLSearchParams; code: string }) => {
|
||||
status: number;
|
||||
body: any;
|
||||
};
|
||||
};
|
||||
}) {
|
||||
const code = uuidv4();
|
||||
// Note the difference b/w MSW wildcard and Playwright wildards. Playwright requires query params to be explicitly specified.
|
||||
page.route(`${authorization.url}?**`, (route, request) => {
|
||||
const u = new URL(request.url());
|
||||
const result = authorization.verify({
|
||||
requestHeaders: request.allHeaders(),
|
||||
params: u.searchParams,
|
||||
code,
|
||||
});
|
||||
|
||||
return route.fulfill(result);
|
||||
});
|
||||
requestInterceptor.use(
|
||||
rest.post(token.url, (req, res, ctx) => {
|
||||
const params = new URLSearchParams(req.body as string);
|
||||
const result = token.verify({ requestHeaders: req.headers, params, code });
|
||||
|
||||
return res(ctx.status(result.status), ctx.json(result.body));
|
||||
})
|
||||
);
|
||||
|
||||
await page.goto(`${process.env.PLAYWRIGHT_TEST_BASE_URL}/apps/${slug}`);
|
||||
await page.click('[data-testid="install-app-button"]');
|
||||
};
|
||||
|
||||
const addLocationIntegrationToFirstEvent = async function ({ user }: { user: { username: string | null } }) {
|
||||
const eventType = await prisma.eventType.findFirst({
|
||||
where: {
|
||||
users: {
|
||||
some: {
|
||||
username: user.username,
|
||||
},
|
||||
},
|
||||
price: 0,
|
||||
},
|
||||
});
|
||||
|
||||
if (!eventType) {
|
||||
throw new Error("Event type not found");
|
||||
}
|
||||
await prisma.eventType.update({
|
||||
where: {
|
||||
id: eventType.id,
|
||||
},
|
||||
data: {
|
||||
locations: [{ type: "integrations:zoom" }],
|
||||
},
|
||||
});
|
||||
return eventType;
|
||||
};
|
||||
|
||||
async function bookEvent(page: Page, calLink: string) {
|
||||
// Let current month dates fully render.
|
||||
// There is a bug where if we don't let current month fully render and quickly click go to next month, current month get's rendered
|
||||
// This doesn't seem to be replicable with the speed of a person, only during automation.
|
||||
// It would also allow correct snapshot to be taken for current month.
|
||||
// eslint-disable-next-line playwright/no-wait-for-timeout
|
||||
await page.waitForTimeout(1000);
|
||||
await page.goto(`${process.env.PLAYWRIGHT_TEST_BASE_URL}/${calLink}`);
|
||||
|
||||
await page.locator('[data-testid="day"][data-disabled="false"]').nth(0).click();
|
||||
page.locator('[data-testid="time"]').nth(0).click();
|
||||
await page.waitForNavigation({
|
||||
url(url) {
|
||||
return url.pathname.includes("/book");
|
||||
},
|
||||
});
|
||||
const meetingId = 123456789;
|
||||
|
||||
requestInterceptor.use(
|
||||
rest.post("https://api.zoom.us/v2/users/me/meetings", (req, res, ctx) => {
|
||||
return res(
|
||||
ctx.status(200),
|
||||
ctx.json({
|
||||
id: meetingId,
|
||||
password: "TestPass",
|
||||
join_url: `https://zoom.us/j/${meetingId}`,
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
// --- fill form
|
||||
await page.fill('[name="name"]', "Integration User");
|
||||
await page.fill('[name="email"]', "[email protected]");
|
||||
await page.press('[name="email"]', "Enter");
|
||||
const response = await page.waitForResponse("**/api/book/event");
|
||||
const responseObj = await response.json();
|
||||
const bookingId = responseObj.uid;
|
||||
await page.waitForSelector("[data-testid=success-page]");
|
||||
// Make sure we're navigated to the success page
|
||||
await expect(page.locator("[data-testid=success-page]")).toBeVisible();
|
||||
expect(global.E2E_EMAILS?.length).toBe(2);
|
||||
expect(
|
||||
global.E2E_EMAILS?.every((email) => (email.text as string).includes(`https://zoom.us/j/${meetingId}`))
|
||||
).toBe(true);
|
||||
return bookingId;
|
||||
}
|
||||
|
||||
test.describe.configure({ mode: "parallel" });
|
||||
|
||||
test.describe("Integrations", () => {
|
||||
test.beforeEach(() => {
|
||||
global.E2E_EMAILS = [];
|
||||
});
|
||||
const addZoomIntegration = async function ({ page }: { page: Page }) {
|
||||
await addOauthBasedIntegration({
|
||||
page,
|
||||
slug: "zoom",
|
||||
authorization: {
|
||||
url: "https://zoom.us/oauth/authorize",
|
||||
verify({ params, code }) {
|
||||
expect(params.get("redirect_uri")).toBeTruthy();
|
||||
return {
|
||||
status: 307,
|
||||
headers: {
|
||||
location: `${params.get("redirect_uri")}?code=${code}`,
|
||||
},
|
||||
};
|
||||
},
|
||||
},
|
||||
token: {
|
||||
url: "https://zoom.us/oauth/token",
|
||||
verify({ requestHeaders, code }) {
|
||||
const authorization = requestHeaders.get("authorization").replace("Basic ", "");
|
||||
const clientPair = Buffer.from(authorization, "base64").toString();
|
||||
const [clientId, clientSecret] = clientPair.split(":");
|
||||
// Ensure that zoom credentials are passed.
|
||||
// TODO: We should also ensure that these credentials are correct e.g. in this case should be READ from DB
|
||||
expect(clientId).toBeTruthy();
|
||||
expect(clientSecret).toBeTruthy();
|
||||
|
||||
return {
|
||||
status: 200,
|
||||
body: {
|
||||
access_token:
|
||||
"eyJhbGciOiJIUzUxMiIsInYiOiIyLjAiLCJraWQiOiI8S0lEPiJ9.eyJ2ZXIiOiI2IiwiY2xpZW50SWQiOiI8Q2xpZW50X0lEPiIsImNvZGUiOiI8Q29kZT4iLCJpc3MiOiJ1cm46em9vbTpjb25uZWN0OmNsaWVudGlkOjxDbGllbnRfSUQ-IiwiYXV0aGVudGljYXRpb25JZCI6IjxBdXRoZW50aWNhdGlvbl9JRD4iLCJ1c2VySWQiOiI8VXNlcl9JRD4iLCJncm91cE51bWJlciI6MCwiYXVkIjoiaHR0cHM6Ly9vYXV0aC56b29tLnVzIiwiYWNjb3VudElkIjoiPEFjY291bnRfSUQ-IiwibmJmIjoxNTgwMTQ2OTkzLCJleHAiOjE1ODAxNTA1OTMsInRva2VuVHlwZSI6ImFjY2Vzc190b2tlbiIsImlhdCI6MTU4MDE0Njk5MywianRpIjoiPEpUST4iLCJ0b2xlcmFuY2VJZCI6MjV9.F9o_w7_lde4Jlmk_yspIlDc-6QGmVrCbe_6El-xrZehnMx7qyoZPUzyuNAKUKcHfbdZa6Q4QBSvpd6eIFXvjHw",
|
||||
token_type: "bearer",
|
||||
refresh_token:
|
||||
"eyJhbGciOiJIUzUxMiIsInYiOiIyLjAiLCJraWQiOiI8S0lEPiJ9.eyJ2ZXIiOiI2IiwiY2xpZW50SWQiOiI8Q2xpZW50X0lEPiIsImNvZGUiOiI8Q29kZT4iLCJpc3MiOiJ1cm46em9vbTpjb25uZWN0OmNsaWVudGlkOjxDbGllbnRfSUQ-IiwiYXV0aGVudGljYXRpb25JZCI6IjxBdXRoZW50aWNhdGlvbl9JRD4iLCJ1c2VySWQiOiI8VXNlcl9JRD4iLCJncm91cE51bWJlciI6MCwiYXVkIjoiaHR0cHM6Ly9vYXV0aC56b29tLnVzIiwiYWNjb3VudElkIjoiPEFjY291bnRfSUQ-IiwibmJmIjoxNTgwMTQ2OTkzLCJleHAiOjIwNTMxODY5OTMsInRva2VuVHlwZSI6InJlZnJlc2hfdG9rZW4iLCJpYXQiOjE1ODAxNDY5OTMsImp0aSI6IjxKVEk-IiwidG9sZXJhbmNlSWQiOjI1fQ.Xcn_1i_tE6n-wy6_-3JZArIEbiP4AS3paSD0hzb0OZwvYSf-iebQBr0Nucupe57HUDB5NfR9VuyvQ3b74qZAfA",
|
||||
expires_in: 3599,
|
||||
// Without this permission, meeting can't be created.
|
||||
scope: "meeting:write",
|
||||
},
|
||||
};
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
test.describe("Zoom App", () => {
|
||||
test.afterEach(async () => {
|
||||
await prisma?.credential.deleteMany({
|
||||
where: {
|
||||
user: {
|
||||
email: "[email protected]",
|
||||
},
|
||||
type: "zoom_video",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
test("Can add integration", async ({ page, users }) => {
|
||||
const user = await users.create();
|
||||
await user.login();
|
||||
await addZoomIntegration({ page });
|
||||
await page.waitForNavigation({
|
||||
url: (url) => {
|
||||
return url.pathname === "/apps/installed";
|
||||
},
|
||||
});
|
||||
//TODO: Check that disconnect button is now visible
|
||||
});
|
||||
|
||||
test("can choose zoom as a location during booking", async ({ page, users }) => {
|
||||
const user = await users.create();
|
||||
await user.login();
|
||||
const eventType = await addLocationIntegrationToFirstEvent({ user });
|
||||
await addZoomIntegration({ page });
|
||||
await page.waitForNavigation({
|
||||
url: (url) => {
|
||||
return url.pathname === "/apps/installed";
|
||||
},
|
||||
});
|
||||
|
||||
await bookEvent(page, `${user.username}/${eventType.slug}`);
|
||||
// Ensure that zoom was informed about the meeting
|
||||
// Verify that email had zoom link
|
||||
// POST https://api.zoom.us/v2/users/me/meetings
|
||||
// Verify Header-> Authorization: "Bearer " + accessToken,
|
||||
/**
|
||||
* {
|
||||
topic: event.title,
|
||||
type: 2, // Means that this is a scheduled meeting
|
||||
start_time: event.startTime,
|
||||
duration: (new Date(event.endTime).getTime() - new Date(event.startTime).getTime()) / 60000,
|
||||
//schedule_for: "string", TODO: Used when scheduling the meeting for someone else (needed?)
|
||||
timezone: event.attendees[0].timeZone,
|
||||
//password: "string", TODO: Should we use a password? Maybe generate a random one?
|
||||
agenda: event.description,
|
||||
settings: {
|
||||
host_video: true,
|
||||
participant_video: true,
|
||||
cn_meeting: false, // TODO: true if host meeting in China
|
||||
in_meeting: false, // TODO: true if host meeting in India
|
||||
join_before_host: true,
|
||||
mute_upon_entry: false,
|
||||
watermark: false,
|
||||
use_pmi: false,
|
||||
approval_type: 2,
|
||||
audio: "both",
|
||||
auto_recording: "none",
|
||||
enforce_login: false,
|
||||
registrants_email_notification: true,
|
||||
},
|
||||
};
|
||||
*/
|
||||
});
|
||||
test("Can disconnect from integration", async ({ page, users }) => {
|
||||
const user = await users.create();
|
||||
await user.login();
|
||||
await addZoomIntegration({ page });
|
||||
await page.waitForNavigation({
|
||||
url: (url) => {
|
||||
return url.pathname === "/apps/installed";
|
||||
},
|
||||
});
|
||||
|
||||
// FIXME: First time reaching /apps/installed throws error in UI.
|
||||
// Temporary use this hack to fix it but remove this HACK before merge.
|
||||
/** HACK STARTS */
|
||||
await page.locator('[href="/apps"]').first().click();
|
||||
await page.waitForNavigation({
|
||||
url: (url) => {
|
||||
return url.pathname === "/apps";
|
||||
},
|
||||
});
|
||||
await page.locator('[href="/apps/installed"]').first().click();
|
||||
/** HACK ENDS */
|
||||
|
||||
await page.locator('[data-testid="zoom_video-integration-disconnect-button"]').click();
|
||||
await page.locator('[data-testid="confirm-button"]').click();
|
||||
await expect(page.locator('[data-testid="confirm-integration-disconnect-button"]')).toHaveCount(0);
|
||||
});
|
||||
});
|
||||
|
||||
test.describe("Hubspot App", () => {
|
||||
test("Can add integration", async ({ page, users }) => {
|
||||
const user = await users.create();
|
||||
await user.login();
|
||||
await addOauthBasedIntegration({
|
||||
page,
|
||||
slug: "hubspot",
|
||||
authorization: {
|
||||
url: "https://app.hubspot.com/oauth/authorize",
|
||||
verify({ params, code }) {
|
||||
expect(params.get("redirect_uri")).toBeTruthy();
|
||||
// TODO: We can check if client_id is correctly read from DB or not
|
||||
expect(params.get("client_id")).toBeTruthy();
|
||||
expect(params.get("scope")).toBe(
|
||||
["crm.objects.contacts.read", "crm.objects.contacts.write"].join(" ")
|
||||
);
|
||||
|
||||
return {
|
||||
// TODO: Should
|
||||
status: 307,
|
||||
headers: {
|
||||
location: `${params.get("redirect_uri")}?code=${code}`,
|
||||
},
|
||||
};
|
||||
},
|
||||
},
|
||||
token: {
|
||||
url: "https://api.hubapi.com/oauth/v1/token",
|
||||
verify({ params, code }) {
|
||||
expect(params.get("grant_type")).toBe("authorization_code");
|
||||
expect(params.get("code")).toBe(code);
|
||||
expect(params.get("client_id")).toBeTruthy();
|
||||
expect(params.get("client_secret")).toBeTruthy();
|
||||
return {
|
||||
status: 200,
|
||||
body: {
|
||||
expiresIn: "3600",
|
||||
},
|
||||
};
|
||||
},
|
||||
},
|
||||
});
|
||||
await page.waitForNavigation({
|
||||
url: (url) => {
|
||||
return url.pathname === "/apps/installed";
|
||||
},
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
todo("Can add Google Calendar");
|
||||
|
||||
todo("Can add Office 365 Calendar");
|
||||
|
||||
todo("Can add CalDav Calendar");
|
||||
|
||||
todo("Can add Apple Calendar");
|
||||
|
||||
test("add webhook & test that creating an event triggers a webhook call", async ({
|
||||
page,
|
||||
users,
|
||||
}, testInfo) => {
|
||||
const webhookReceiver = createHttpServer();
|
||||
const user = await users.create();
|
||||
const [eventType] = user.eventTypes;
|
||||
await user.login();
|
||||
await page.goto(`${process.env.PLAYWRIGHT_TEST_BASE_URL}/settings/developer`);
|
||||
|
||||
// --- add webhook
|
||||
await page.click('[data-testid="new_webhook"]');
|
||||
|
||||
await expect(page.locator(`[data-testid='WebhookDialogForm']`)).toBeVisible();
|
||||
|
||||
await page.fill('[name="subscriberUrl"]', webhookReceiver.url);
|
||||
|
||||
await page.fill('[name="secret"]', "secret");
|
||||
|
||||
await page.click("[type=submit]");
|
||||
|
||||
// dialog is closed
|
||||
await expect(page.locator(`[data-testid='WebhookDialogForm']`)).not.toBeVisible();
|
||||
// page contains the url
|
||||
expect(page.locator(`text='${webhookReceiver.url}'`)).toBeDefined();
|
||||
|
||||
// --- Book the first available day next month in the pro user's "30min"-event
|
||||
await page.goto(`${process.env.PLAYWRIGHT_TEST_BASE_URL}/${user.username}/${eventType.slug}`);
|
||||
await selectFirstAvailableTimeSlotNextMonth(page);
|
||||
|
||||
// --- fill form
|
||||
await page.fill('[name="name"]', "Test Testson");
|
||||
await page.fill('[name="email"]', "[email protected]");
|
||||
await page.press('[name="email"]', "Enter");
|
||||
|
||||
// --- check that webhook was called
|
||||
await waitFor(() => {
|
||||
expect(webhookReceiver.requestList.length).toBe(1);
|
||||
});
|
||||
|
||||
const [request] = webhookReceiver.requestList;
|
||||
const body = request.body as any;
|
||||
|
||||
// remove dynamic properties that differs depending on where you run the tests
|
||||
const dynamic = "[redacted/dynamic]";
|
||||
body.createdAt = dynamic;
|
||||
body.payload.startTime = dynamic;
|
||||
body.payload.endTime = dynamic;
|
||||
body.payload.location = dynamic;
|
||||
for (const attendee of body.payload.attendees) {
|
||||
attendee.timeZone = dynamic;
|
||||
attendee.language = dynamic;
|
||||
}
|
||||
body.payload.organizer.email = dynamic;
|
||||
body.payload.organizer.timeZone = dynamic;
|
||||
body.payload.organizer.language = dynamic;
|
||||
body.payload.uid = dynamic;
|
||||
body.payload.bookingId = dynamic;
|
||||
body.payload.additionalInformation = dynamic;
|
||||
body.payload.requiresConfirmation = dynamic;
|
||||
body.payload.eventTypeId = dynamic;
|
||||
|
||||
// if we change the shape of our webhooks, we can simply update this by clicking `u`
|
||||
// console.log("BODY", body);
|
||||
// Text files shouldn't have platform specific suffixes
|
||||
testInfo.snapshotSuffix = "";
|
||||
expect(JSON.stringify(body)).toMatchSnapshot(`webhookResponse.txt`);
|
||||
|
||||
webhookReceiver.close();
|
||||
});
|
||||
});
|
||||
File renamed without changes.
@@ -1,13 +1,19 @@
|
||||
import type { Page, WorkerInfo } from "@playwright/test";
|
||||
import type Prisma from "@prisma/client";
|
||||
import { Prisma as PrismaType, UserPlan } from "@prisma/client";
|
||||
import { hash } from "bcryptjs";
|
||||
|
||||
import { hashPassword } from "@calcom/lib/auth";
|
||||
import { DEFAULT_SCHEDULE, getAvailabilityFromSchedule } from "@calcom/lib/availability";
|
||||
import { prisma } from "@calcom/prisma";
|
||||
|
||||
import { 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);
|
||||
return hashedPassword;
|
||||
}
|
||||
|
||||
type UserFixture = ReturnType<typeof createUserFixture>;
|
||||
|
||||
const userIncludes = PrismaType.validator<PrismaType.UserInclude>()({
|
||||
@@ -66,7 +72,7 @@ export const createUsersFixture = (page: Page, workerInfo: WorkerInfo) => {
|
||||
},
|
||||
get: () => store.users,
|
||||
logout: async () => {
|
||||
await page.goto("/auth/logout");
|
||||
await page.goto(`${process.env.PLAYWRIGHT_TEST_BASE_URL}/auth/logout`);
|
||||
},
|
||||
deleteAll: async () => {
|
||||
const ids = store.users.map((u) => u.id);
|
||||
@@ -161,8 +167,10 @@ export async function login(
|
||||
const signInLocator = loginLocator.locator('[type="submit"]');
|
||||
|
||||
//login
|
||||
await page.goto("/");
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
await page.goto(process.env.PLAYWRIGHT_TEST_BASE_URL!);
|
||||
await emailLocator.fill(user.email ?? `${user.username}@example.com`);
|
||||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
||||
await passwordLocator.fill(user.password ?? user.username!);
|
||||
await signInLocator.click();
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ test.describe("Stripe integration", () => {
|
||||
|
||||
/** If Stripe is added correctly we should see the "Disconnect" button */
|
||||
await expect(
|
||||
page.locator(`li:has-text("Stripe") >> [data-testid="integration-connection-button"]`)
|
||||
page.locator(`li:has-text("Stripe") >> [data-testid="stripe_payment-integration-disconnect-button"]`)
|
||||
).toContainText("Disconnect");
|
||||
|
||||
// Cleanup
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
import { expect } from "@playwright/test";
|
||||
|
||||
import { test } from "./lib/fixtures";
|
||||
import { createHttpServer, selectFirstAvailableTimeSlotNextMonth, todo, waitFor } from "./lib/testUtils";
|
||||
|
||||
test.describe.configure({ mode: "parallel" });
|
||||
|
||||
test.describe("Integrations", () => {
|
||||
todo("Can add Zoom integration");
|
||||
|
||||
todo("Can add Google Calendar");
|
||||
|
||||
todo("Can add Office 365 Calendar");
|
||||
|
||||
todo("Can add CalDav Calendar");
|
||||
|
||||
todo("Can add Apple Calendar");
|
||||
|
||||
test("add webhook & test that creating an event triggers a webhook call", async ({
|
||||
page,
|
||||
users,
|
||||
}, testInfo) => {
|
||||
const webhookReceiver = createHttpServer();
|
||||
const user = await users.create();
|
||||
const [eventType] = user.eventTypes;
|
||||
await user.login();
|
||||
await page.goto("/settings/developer");
|
||||
|
||||
// --- add webhook
|
||||
await page.click('[data-testid="new_webhook"]');
|
||||
|
||||
await expect(page.locator(`[data-testid='WebhookDialogForm']`)).toBeVisible();
|
||||
|
||||
await page.fill('[name="subscriberUrl"]', webhookReceiver.url);
|
||||
|
||||
await page.fill('[name="secret"]', "secret");
|
||||
|
||||
await page.click("[type=submit]");
|
||||
|
||||
// dialog is closed
|
||||
await expect(page.locator(`[data-testid='WebhookDialogForm']`)).not.toBeVisible();
|
||||
// page contains the url
|
||||
expect(page.locator(`text='${webhookReceiver.url}'`)).toBeDefined();
|
||||
|
||||
// --- Book the first available day next month in the pro user's "30min"-event
|
||||
await page.goto(`/${user.username}/${eventType.slug}`);
|
||||
await selectFirstAvailableTimeSlotNextMonth(page);
|
||||
|
||||
// --- fill form
|
||||
await page.fill('[name="name"]', "Test Testson");
|
||||
await page.fill('[name="email"]', "[email protected]");
|
||||
await page.press('[name="email"]', "Enter");
|
||||
|
||||
// --- check that webhook was called
|
||||
await waitFor(() => {
|
||||
expect(webhookReceiver.requestList.length).toBe(1);
|
||||
});
|
||||
|
||||
const [request] = webhookReceiver.requestList;
|
||||
const body = request.body as any;
|
||||
|
||||
// remove dynamic properties that differs depending on where you run the tests
|
||||
const dynamic = "[redacted/dynamic]";
|
||||
body.createdAt = dynamic;
|
||||
body.payload.startTime = dynamic;
|
||||
body.payload.endTime = dynamic;
|
||||
body.payload.location = dynamic;
|
||||
for (const attendee of body.payload.attendees) {
|
||||
attendee.timeZone = dynamic;
|
||||
attendee.language = dynamic;
|
||||
}
|
||||
body.payload.organizer.email = dynamic;
|
||||
body.payload.organizer.timeZone = dynamic;
|
||||
body.payload.organizer.language = dynamic;
|
||||
body.payload.uid = dynamic;
|
||||
body.payload.bookingId = dynamic;
|
||||
body.payload.additionalInformation = dynamic;
|
||||
body.payload.requiresConfirmation = dynamic;
|
||||
body.payload.eventTypeId = dynamic;
|
||||
|
||||
// if we change the shape of our webhooks, we can simply update this by clicking `u`
|
||||
// console.log("BODY", body);
|
||||
// Text files shouldn't have platform specific suffixes
|
||||
testInfo.snapshotSuffix = "";
|
||||
expect(JSON.stringify(body)).toMatchSnapshot(`webhookResponse.txt`);
|
||||
|
||||
webhookReceiver.close();
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user