fix: deprecating email test for core

This commit is contained in:
zomars 2023-12-11 17:12:23 -07:00
parent a20179727b
commit 0af3c278c7
4 changed files with 25 additions and 32 deletions

View File

@ -9,6 +9,8 @@ import { noop } from "lodash";
import type { API, Messages } from "mailhog";
import { totp } from "otplib";
import { WEBAPP_URL } from "@calcom/lib/constants";
import type { PrismaClient } from "@calcom/prisma";
import type { Prisma } from "@calcom/prisma/client";
import { BookingStatus } from "@calcom/prisma/enums";
import type { IntervalLimit } from "@calcom/types/Calendar";
@ -336,3 +338,15 @@ export async function fillStripeTestCheckout(page: Page) {
await page.fill("[name=billingName]", "Stripe Stripeson");
await page.click(".SubmitButton--complete-Shimmer");
}
export async function sendTeamInviteAndGetLink(page: Page, prisma: PrismaClient, identifier: string) {
const response = page.waitForResponse("**/api/trpc/teams/inviteMember?batch=1");
await page.getByTestId("invite-new-member-button").click();
await response;
const verificationToken = await prisma.verificationToken.findFirstOrThrow({
where: { identifier },
});
expect(verificationToken).toBeDefined();
const token = verificationToken.token;
return `${WEBAPP_URL}/signup?token=${token}&callbackUrl=/getting-started`;
}

View File

@ -6,6 +6,10 @@ import type { API, Messages } from "mailhog";
import { getEmailsReceivedByUser } from "../lib/testUtils";
/**
* @deprecated
* Avoid using this function, it's not 100% reliable. And it will slow down the tests.
*/
export async function expectInvitationEmailToBeReceived(
page: Page,
emails: API | undefined,

View File

@ -1,7 +1,7 @@
import { expect } from "@playwright/test";
import { test } from "../lib/fixtures";
import { getInviteLink } from "../lib/testUtils";
import { getInviteLink, sendTeamInviteAndGetLink } from "../lib/testUtils";
import { expectInvitationEmailToBeReceived } from "./expects";
test.describe.configure({ mode: "parallel" });
@ -12,7 +12,7 @@ test.afterEach(async ({ users, emails }) => {
});
test.describe("Organization", () => {
test("Invitation (non verified)", async ({ browser, page, users, emails }) => {
test("Invitation (non verified)", async ({ browser, page, users, prisma }) => {
const orgOwner = await users.create(undefined, { hasTeam: true, isOrg: true });
const { team: org } = await orgOwner.getOrgMembership();
await orgOwner.apiLogin();
@ -23,24 +23,13 @@ test.describe("Organization", () => {
const invitedUserEmail = `rick@domain-${Date.now()}.com`;
await page.locator('button:text("Add")').click();
await page.locator('input[name="inviteUser"]').fill(invitedUserEmail);
await page.locator('button:text("Send invite")').click();
await page.waitForLoadState("networkidle");
const inviteLink = await expectInvitationEmailToBeReceived(
page,
emails,
invitedUserEmail,
`${org.name}'s admin invited you to join the organization ${org.name} on Cal.com`,
"signup?token"
);
const inviteLink = await sendTeamInviteAndGetLink(page, prisma, invitedUserEmail);
// Check newly invited member exists and is pending
await expect(
page.locator(`[data-testid="email-${invitedUserEmail.replace("@", "")}-pending"]`)
).toHaveCount(1);
// eslint-disable-next-line playwright/no-conditional-in-test
if (!inviteLink) return null;
// Follow invite link in new window
const context = await browser.newContext();
const newPage = await context.newPage();

View File

@ -1,11 +1,10 @@
import { expect } from "@playwright/test";
import { randomBytes } from "crypto";
import { APP_NAME, IS_PREMIUM_USERNAME_ENABLED, IS_MAILHOG_ENABLED } from "@calcom/lib/constants";
import { APP_NAME, IS_MAILHOG_ENABLED, IS_PREMIUM_USERNAME_ENABLED } from "@calcom/lib/constants";
import { test } from "./lib/fixtures";
import { getEmailsReceivedByUser, localize } from "./lib/testUtils";
import { expectInvitationEmailToBeReceived } from "./team/expects";
import { getEmailsReceivedByUser, localize, sendTeamInviteAndGetLink } from "./lib/testUtils";
test.describe.configure({ mode: "parallel" });
@ -230,7 +229,7 @@ test.describe("Signup Flow Test", async () => {
const verifyEmail = receivedEmails?.items[0];
expect(verifyEmail?.subject).toBe(`${APP_NAME}: Verify your account`);
});
test("If signup is disabled allow team invites", async ({ browser, page, users, emails }) => {
test("If signup is disabled allow team invites", async ({ browser, page, users, prisma }) => {
// eslint-disable-next-line playwright/no-skipped-test
test.skip(process.env.NEXT_PUBLIC_DISABLE_SIGNUP !== "true", "Skipping due to signup being enabled");
@ -246,24 +245,11 @@ test.describe("Signup Flow Test", async () => {
const invitedUserEmail = `rick_${Date.now()}@domain-${Date.now()}.com`;
await page.locator(`button:text("${t("add")}")`).click();
await page.locator('input[name="inviteUser"]').fill(invitedUserEmail);
await page.locator(`button:text("${t("send_invite")}")`).click();
await page.waitForLoadState("networkidle");
const inviteLink = await expectInvitationEmailToBeReceived(
page,
emails,
invitedUserEmail,
`${team.name}'s admin invited you to join the team ${team.name} on Cal.com`,
"signup?token"
);
const inviteLink = await sendTeamInviteAndGetLink(page, prisma, invitedUserEmail);
//Check newly invited member exists and is pending
await expect(
page.locator(`[data-testid="email-${invitedUserEmail.replace("@", "")}-pending"]`)
).toHaveCount(1);
// eslint-disable-next-line playwright/no-conditional-in-test
if (!inviteLink) return;
// Follow invite link to new window
const context = await browser.newContext();
const newPage = await context.newPage();