fix: Flakiness in tests (#12929)

This commit is contained in:
Hariom Balhara authored and GitHub committed 2023-12-23 07:48:02 -05:00
1 parent c4792c55fe
commit 55c9efec3e
13 files changed
+134 -60

No files matched your search

@@ -5,9 +5,8 @@ import prisma from "@calcom/prisma";
import { test } from "../../lib/fixtures";
test.afterAll(({ users, emails }) => {
test.afterAll(({ users }) => {
users.deleteAll();
emails?.deleteAll();
});
test.describe("user1NotMemberOfOrg1 is part of team1MemberOfOrg1", () => {
+4 -3
View File
@@ -2,13 +2,14 @@ import type { Page } from "@playwright/test";
import { expect } from "@playwright/test";
import { JSDOM } from "jsdom";
// eslint-disable-next-line no-restricted-imports
import type { API, Messages } from "mailhog";
import type { Messages } from "mailhog";
import type { createEmailsFixture } from "playwright/fixtures/emails";
import { getEmailsReceivedByUser } from "../lib/testUtils";
export async function expectInvitationEmailToBeReceived(
page: Page,
emails: API | undefined,
emails: ReturnType<typeof createEmailsFixture>,
userEmail: string,
subject: string,
returnLink?: string
@@ -16,7 +17,7 @@ export async function expectInvitationEmailToBeReceived(
if (!emails) return null;
// We need to wait for the email to go through, otherwise it will fail
// eslint-disable-next-line playwright/no-wait-for-timeout
await page.waitForTimeout(5000);
await page.waitForTimeout(2000);
const receivedEmails = await getEmailsReceivedByUser({ emails, userEmail });
expect(receivedEmails?.total).toBe(1);
const [firstReceivedEmail] = (receivedEmails as Messages).items;
@@ -1,13 +1,14 @@
import { expect } from "@playwright/test";
import path from "path";
import { uuid } from "short-uuid";
import { test } from "../lib/fixtures";
import { generateTotpCode } from "../lib/testUtils";
import { expectInvitationEmailToBeReceived } from "./expects";
test.afterAll(({ users, emails }) => {
test.afterAll(({ users, orgs }) => {
users.deleteAll();
emails?.deleteAll();
orgs.deleteAll();
});
function capitalize(text: string) {
@@ -26,6 +27,11 @@ test.describe("Organization", () => {
const orgOwner = await users.create({
role: "ADMIN",
});
const instanceAdmin = await users.create({
username: `admin-${uuid()}`,
email: users.trackEmail({ username: "admin", domain: "example.com" }),
role: "ADMIN",
});
const orgDomain = `${orgOwner.username}-org`;
const orgName = capitalize(`${orgOwner.username}-org`);
await orgOwner.apiLogin();
@@ -38,7 +44,8 @@ test.describe("Organization", () => {
await expect(page.locator(".text-red-700")).toHaveCount(3);
// Happy path
await page.locator("input[name=adminEmail]").fill(`john@${orgDomain}.com`);
const adminEmail = users.trackEmail({ username: "john", domain: `${orgDomain}.com` });
await page.locator("input[name=adminEmail]").fill(adminEmail);
expect(await page.locator("input[name=name]").inputValue()).toEqual(orgName);
expect(await page.locator("input[name=slug]").inputValue()).toEqual(orgDomain);
await page.locator("button[type=submit]").click();
@@ -48,7 +55,7 @@ test.describe("Organization", () => {
await expectInvitationEmailToBeReceived(
page,
emails,
`john@${orgOwner.username}-org.com`,
adminEmail,
"Verify your email to create an organization"
);
@@ -56,12 +63,11 @@ test.describe("Organization", () => {
// Code verification
await expect(page.locator("#modal-title")).toBeVisible();
await page.locator("input[name='2fa1']").fill(generateTotpCode(`john@${orgDomain}.com`));
// Check admin email about DNS pending action
await expectInvitationEmailToBeReceived(
page,
emails,
"[email protected]",
instanceAdmin.email,
"New organization created: pending action"
);
@@ -105,14 +111,15 @@ test.describe("Organization", () => {
await page.locator("button[type=submit]").click();
// Happy path
await page.locator('textarea[name="emails"]').fill(`rick@${orgDomain}.com`);
const adminEmail = users.trackEmail({ username: "rick", domain: `${orgDomain}.com` });
await page.locator('textarea[name="emails"]').fill(adminEmail);
await page.locator("button[type=submit]").click();
// Check if invited admin received the invitation email
await expectInvitationEmailToBeReceived(
page,
emails,
`rick@${orgDomain}.com`,
adminEmail,
`${orgName}'s admin invited you to join the organization ${orgName} on Cal.com`
);
@@ -9,12 +9,12 @@ import { expectInvitationEmailToBeReceived } from "./expects";
test.describe.configure({ mode: "parallel" });
test.afterEach(async ({ users, emails }) => {
test.afterEach(async ({ users, orgs }) => {
await users.deleteAll();
emails?.deleteAll();
await orgs.deleteAll();
});
test.describe.serial("Organization", () => {
test.describe("Organization", () => {
test.describe("Email not matching orgAutoAcceptEmail", () => {
test("Org Invitation", async ({ browser, page, users, emails }) => {
const orgOwner = await users.create(undefined, { hasTeam: true, isOrg: true });
@@ -24,9 +24,10 @@ test.describe.serial("Organization", () => {
await page.waitForLoadState("networkidle");
await test.step("By email", async () => {
const invitedUserEmail = `rick-${Date.now()}@domain.com`;
const invitedUserEmail = users.trackEmail({ username: "rick", domain: "domain.com" });
// '-domain' because the email doesn't match orgAutoAcceptEmail
const usernameDerivedFromEmail = `${invitedUserEmail.split("@")[0]}-domain`;
await inviteAnEmail(page, invitedUserEmail);
const inviteLink = await expectInvitationEmailToBeReceived(
page,
@@ -66,7 +67,7 @@ test.describe.serial("Organization", () => {
await test.step("By invite link", async () => {
const inviteLink = await copyInviteLink(page);
const email = `rick-${Date.now()}@domain.com`;
const email = users.trackEmail({ username: "rick", domain: "domain.com" });
// '-domain' because the email doesn't match orgAutoAcceptEmail
const usernameDerivedFromEmail = `${email.split("@")[0]}-domain`;
await signupFromInviteLink({ browser, inviteLink, email });
@@ -91,7 +92,7 @@ test.describe.serial("Organization", () => {
await test.step("By email", async () => {
await page.goto(`/settings/teams/${team.id}/members`);
await page.waitForLoadState("networkidle");
const invitedUserEmail = `rick-${Date.now()}@domain.com`;
const invitedUserEmail = users.trackEmail({ username: "rick", domain: "domain.com" });
// '-domain' because the email doesn't match orgAutoAcceptEmail
const usernameDerivedFromEmail = `${invitedUserEmail.split("@")[0]}-domain`;
await inviteAnEmail(page, invitedUserEmail);
@@ -154,7 +155,7 @@ test.describe.serial("Organization", () => {
await test.step("By invite link", async () => {
await page.goto(`/settings/teams/${team.id}/members`);
const inviteLink = await copyInviteLink(page);
const email = `rick-${Date.now()}@domain.com`;
const email = users.trackEmail({ username: "rick", domain: "domain.com" });
// '-domain' because the email doesn't match orgAutoAcceptEmail
const usernameDerivedFromEmail = `${email.split("@")[0]}-domain`;
await signupFromInviteLink({ browser, inviteLink, email });
@@ -190,7 +191,7 @@ test.describe.serial("Organization", () => {
await page.waitForLoadState("networkidle");
await test.step("By email", async () => {
const invitedUserEmail = `rick-${Date.now()}@example.com`;
const invitedUserEmail = users.trackEmail({ username: "rick", domain: "example.com" });
const usernameDerivedFromEmail = invitedUserEmail.split("@")[0];
await inviteAnEmail(page, invitedUserEmail);
const inviteLink = await expectInvitationEmailToBeReceived(
@@ -231,7 +232,7 @@ test.describe.serial("Organization", () => {
await test.step("By invite link", async () => {
const inviteLink = await copyInviteLink(page);
const email = `rick-${Date.now()}@example.com`;
const email = users.trackEmail({ username: "rick", domain: "example.com" });
const usernameDerivedFromEmail = email.split("@")[0];
await signupFromInviteLink({ browser, inviteLink, email });
@@ -262,7 +263,7 @@ test.describe.serial("Organization", () => {
await test.step("By email", async () => {
await page.goto(`/settings/teams/${team.id}/members`);
await page.waitForLoadState("networkidle");
const invitedUserEmail = `rick-${Date.now()}@example.com`;
const invitedUserEmail = users.trackEmail({ username: "rick", domain: "example.com" });
const usernameDerivedFromEmail = invitedUserEmail.split("@")[0];
await inviteAnEmail(page, invitedUserEmail);
await expectUserToBeAMemberOfTeam({
@@ -323,7 +324,7 @@ test.describe.serial("Organization", () => {
await page.goto(`/settings/teams/${team.id}/members`);
const inviteLink = await copyInviteLink(page);
const email = `rick-${Date.now()}@example.com`;
const email = users.trackEmail({ username: "rick", domain: "example.com" });
// '-domain' because the email doesn't match orgAutoAcceptEmail
const usernameDerivedFromEmail = `${email.split("@")[0]}`;
@@ -460,6 +461,7 @@ async function expectUserToBeAMemberOfTeam({
}) {
// Check newly invited member is not pending anymore
await page.goto(`/settings/teams/${teamId}/members`);
await page.reload();
expect(
(
await page.locator(`[data-testid="member-${username}"] [data-testid=member-role]`).textContent()