chore: expect emails e2e (#10881)
* refactor: emails e2e * fix: email subject with nameless organizer * fix: comment on NEXT_PUBLIC_IS_E2E * chore: E2E_TEST_MAILHOG_ENABLED env * feat: IS_MAILHOG_ENABLED * doc: E2E_TEST_MAILHOG_ENABLED * fix: comment * fix: env order * chore: add E2E_TEST_MAILHOG_ENABLED to e2e env
This commit is contained in:
1 parent
376f023e0f
commit
bab41ca8a6
12 files changed
+85
-30
No files matched your search
@@ -1,5 +1,4 @@
|
||||
import { expect } from "@playwright/test";
|
||||
import type { Messages } from "mailhog";
|
||||
|
||||
import { randomString } from "@calcom/lib/random";
|
||||
|
||||
@@ -8,6 +7,7 @@ import {
|
||||
bookFirstEvent,
|
||||
bookOptinEvent,
|
||||
bookTimeSlot,
|
||||
expectEmailsToHaveSubject,
|
||||
selectFirstAvailableTimeSlotNextMonth,
|
||||
testEmail,
|
||||
testName,
|
||||
@@ -41,19 +41,13 @@ test.describe("free user", () => {
|
||||
// Make sure we're navigated to the success page
|
||||
await expect(page.locator("[data-testid=success-page]")).toBeVisible();
|
||||
const { title: eventTitle } = await user.getFirstEventAsOwner();
|
||||
// TODO: follow DRY
|
||||
const emailsOrganiserReceived = await emails.search(user.email, "to");
|
||||
const emailsBookerReceived = await emails.search(bookerObj.email, "to");
|
||||
expect(emailsOrganiserReceived?.total).toBe(1);
|
||||
expect(emailsBookerReceived?.total).toBe(1);
|
||||
|
||||
const [organizerFirstEmail] = (emailsOrganiserReceived as Messages).items;
|
||||
const [bookerFirstEmail] = (emailsBookerReceived as Messages).items;
|
||||
const emailSubject = `${eventTitle} between ${user.name} and ${bookerObj.name}`;
|
||||
|
||||
expect(organizerFirstEmail.subject).toBe(emailSubject);
|
||||
expect(bookerFirstEmail.subject).toBe(emailSubject);
|
||||
|
||||
await expectEmailsToHaveSubject({
|
||||
emails,
|
||||
organizer: user,
|
||||
booker: bookerObj,
|
||||
eventTitle,
|
||||
});
|
||||
await page.goto(bookingUrl);
|
||||
|
||||
// book same time spot again
|
||||
|
||||
@@ -118,7 +118,7 @@ const createTeamAndAddUser = async (
|
||||
};
|
||||
|
||||
// creates a user fixture instance and stores the collection
|
||||
export const createUsersFixture = (page: Page, emails: API, workerInfo: WorkerInfo) => {
|
||||
export const createUsersFixture = (page: Page, emails: API | undefined, workerInfo: WorkerInfo) => {
|
||||
const store = { users: [], page } as { users: UserFixture[]; page: typeof page };
|
||||
return {
|
||||
create: async (
|
||||
@@ -332,19 +332,22 @@ export const createUsersFixture = (page: Page, emails: API, workerInfo: WorkerIn
|
||||
await page.goto("/auth/logout");
|
||||
},
|
||||
deleteAll: async () => {
|
||||
const emailMessageIds: string[] = [];
|
||||
const ids = store.users.map((u) => u.id);
|
||||
for (const user of store.users) {
|
||||
const emailMessages = await emails.search(user.email);
|
||||
if (emailMessages && emailMessages.count > 0) {
|
||||
emailMessages.items.forEach((item) => {
|
||||
emailMessageIds.push(item.ID);
|
||||
});
|
||||
if (emails) {
|
||||
const emailMessageIds: string[] = [];
|
||||
for (const user of store.users) {
|
||||
const emailMessages = await emails.search(user.email);
|
||||
if (emailMessages && emailMessages.count > 0) {
|
||||
emailMessages.items.forEach((item) => {
|
||||
emailMessageIds.push(item.ID);
|
||||
});
|
||||
}
|
||||
}
|
||||
for (const id of emailMessageIds) {
|
||||
await emails.deleteMessage(id);
|
||||
}
|
||||
}
|
||||
for (const id of emailMessageIds) {
|
||||
await emails.deleteMessage(id);
|
||||
}
|
||||
|
||||
await prisma.user.deleteMany({ where: { id: { in: ids } } });
|
||||
store.users = [];
|
||||
},
|
||||
|
||||
@@ -3,6 +3,7 @@ import { test as base } from "@playwright/test";
|
||||
import type { API } from "mailhog";
|
||||
import mailhog from "mailhog";
|
||||
|
||||
import { IS_MAILHOG_ENABLED } from "@calcom/lib/constants";
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import type { ExpectedUrlDetails } from "../../../../playwright.config";
|
||||
@@ -21,7 +22,7 @@ export interface Fixtures {
|
||||
getActionFiredDetails: ReturnType<typeof createGetActionFiredDetails>;
|
||||
servers: ReturnType<typeof createServersFixture>;
|
||||
prisma: typeof prisma;
|
||||
emails: API;
|
||||
emails?: API;
|
||||
}
|
||||
|
||||
declare global {
|
||||
@@ -71,7 +72,11 @@ export const test = base.extend<Fixtures>({
|
||||
await use(prisma);
|
||||
},
|
||||
emails: async ({}, use) => {
|
||||
const mailhogAPI = mailhog();
|
||||
await use(mailhogAPI);
|
||||
if (IS_MAILHOG_ENABLED) {
|
||||
const mailhogAPI = mailhog();
|
||||
await use(mailhogAPI);
|
||||
} else {
|
||||
await use(undefined);
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -4,6 +4,7 @@ import type { IncomingMessage, ServerResponse } from "http";
|
||||
import { createServer } from "http";
|
||||
// eslint-disable-next-line no-restricted-imports
|
||||
import { noop } from "lodash";
|
||||
import type { API, Messages } from "mailhog";
|
||||
|
||||
import { test } from "./fixtures";
|
||||
|
||||
@@ -191,3 +192,39 @@ export async function installAppleCalendar(page: Page) {
|
||||
await page.waitForURL("/apps/apple-calendar");
|
||||
await page.click('[data-testid="install-app-button"]');
|
||||
}
|
||||
export async function getEmailsReceivedByUser({
|
||||
emails,
|
||||
userEmail,
|
||||
}: {
|
||||
emails?: API;
|
||||
userEmail: string;
|
||||
}): Promise<Messages | null> {
|
||||
if (!emails) return null;
|
||||
return emails.search(userEmail, "to");
|
||||
}
|
||||
|
||||
export async function expectEmailsToHaveSubject({
|
||||
emails,
|
||||
organizer,
|
||||
booker,
|
||||
eventTitle,
|
||||
}: {
|
||||
emails?: API;
|
||||
organizer: { name?: string | null; email: string };
|
||||
booker: { name: string; email: string };
|
||||
eventTitle: string;
|
||||
}) {
|
||||
if (!emails) return null;
|
||||
const emailsOrganizerReceived = await getEmailsReceivedByUser({ emails, userEmail: organizer.email });
|
||||
const emailsBookerReceived = await getEmailsReceivedByUser({ emails, userEmail: booker.email });
|
||||
|
||||
expect(emailsOrganizerReceived?.total).toBe(1);
|
||||
expect(emailsBookerReceived?.total).toBe(1);
|
||||
|
||||
const [organizerFirstEmail] = (emailsOrganizerReceived as Messages).items;
|
||||
const [bookerFirstEmail] = (emailsBookerReceived as Messages).items;
|
||||
const emailSubject = `${eventTitle} between ${organizer.name ?? "Nameless"} and ${booker.name}`;
|
||||
|
||||
expect(organizerFirstEmail.subject).toBe(emailSubject);
|
||||
expect(bookerFirstEmail.subject).toBe(emailSubject);
|
||||
}
|
||||
Reference in new issue
Block a user