1- import { expect } from "@playwright/test" ;
2- import type { Page } from "@playwright/test" ;
3- import type { createUsersFixture } from "./fixtures/users" ;
4-
51import { WEBAPP_URL } from "@calcom/lib/constants" ;
62import type { PrismaClient } from "@calcom/prisma" ;
7-
3+ import type { Page } from "@playwright/test" ;
4+ import { expect } from "@playwright/test" ;
5+ import { JSDOM } from "jsdom" ;
6+ import type { Messages } from "mailhog" ;
87import type { createEmailsFixture } from "./fixtures/emails" ;
8+ import type { createUsersFixture } from "./fixtures/users" ;
99import { test } from "./lib/fixtures" ;
1010import { getEmailsReceivedByUser , submitAndWaitForResponse } from "./lib/testUtils" ;
11- import { expectInvitationEmailToBeReceived } from "./team/expects" ;
11+
12+ const expectInvitationEmailToBeReceived = async ( {
13+ emails,
14+ userEmail,
15+ subject,
16+ returnLink,
17+ } : {
18+ emails : ReturnType < typeof createEmailsFixture > ;
19+ userEmail : string ;
20+ subject ?: string | null ;
21+ returnLink ?: string ;
22+ } ) => {
23+ if ( ! emails ) return null ;
24+
25+ const receivedEmails = await getEmailsReceivedByUser ( { emails, userEmail } ) ;
26+ expect ( receivedEmails ?. total ) . toBe ( 1 ) ;
27+
28+ const [ firstReceivedEmail ] = ( receivedEmails as Messages ) . items ;
29+ if ( subject ) {
30+ expect ( firstReceivedEmail . subject ) . toBe ( subject ) ;
31+ }
32+ if ( ! returnLink ) return null ;
33+
34+ const dom = new JSDOM ( firstReceivedEmail . html ) ;
35+ const anchor = dom . window . document . querySelector ( `a[href*="${ returnLink } "]` ) ;
36+ return anchor ?. getAttribute ( "href" ) ?? null ;
37+ } ;
1238
1339test . describe . configure ( { mode : "parallel" } ) ;
1440
@@ -170,12 +196,10 @@ test.describe("Update Profile", () => {
170196 } ) ;
171197
172198 const testEmailVerificationLink = async ( {
173- page,
174199 prisma,
175200 emails,
176201 secondaryEmail,
177202 } : {
178- page : Page ;
179203 prisma : PrismaClient ;
180204 emails : ReturnType < typeof createEmailsFixture > ;
181205 secondaryEmail : string ;
@@ -186,13 +210,12 @@ test.describe("Update Profile", () => {
186210 identifier : secondaryEmail ,
187211 } ,
188212 } ) ;
189- const inviteLink = await expectInvitationEmailToBeReceived (
190- page ,
213+ const inviteLink = await expectInvitationEmailToBeReceived ( {
191214 emails,
192- secondaryEmail ,
193- "Verify your email address" ,
194- "verify-email"
195- ) ;
215+ userEmail : secondaryEmail ,
216+ subject : "Verify your email address" ,
217+ returnLink : "verify-email" ,
218+ } ) ;
196219 expect ( inviteLink ) . toEqual ( `${ WEBAPP_URL } /api/auth/verify-email?token=${ verificationToken ?. token } ` ) ;
197220 } ) ;
198221 } ;
@@ -236,13 +259,12 @@ test.describe("Update Profile", () => {
236259 identifier : secondaryEmail ,
237260 } ,
238261 } ) ;
239- const inviteLink = await expectInvitationEmailToBeReceived (
240- page ,
262+ const inviteLink = await expectInvitationEmailToBeReceived ( {
241263 emails,
242- secondaryEmail ,
243- "Verify your email address" ,
244- "verify-email"
245- ) ;
264+ userEmail : secondaryEmail ,
265+ subject : "Verify your email address" ,
266+ returnLink : "verify-email" ,
267+ } ) ;
246268 expect ( inviteLink ?. endsWith ( `/api/auth/verify-email?token=${ verificationToken ?. token } ` ) ) . toEqual ( true ) ;
247269 } ) ;
248270
@@ -385,7 +407,7 @@ test.describe("Update Profile", () => {
385407 await expect ( page . locator ( "button[data-testid=resend-verify-email-button]" ) ) . toBeEnabled ( ) ;
386408 await page . getByTestId ( "resend-verify-email-button" ) . click ( ) ;
387409
388- await testEmailVerificationLink ( { page , prisma, emails, secondaryEmail } ) ;
410+ await testEmailVerificationLink ( { prisma, emails, secondaryEmail } ) ;
389411
390412 const verificationToken = await prisma . verificationToken . findFirst ( {
391413 where : {
0 commit comments