Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ describe(
timeout: TIMEOUT,
targetSubject: resetPassSubject,
targetEmail: emailOne,
requireHtml: true,
})
.then((email) => {
if (email) {
Expand Down Expand Up @@ -282,6 +283,7 @@ describe(
timeout: TIMEOUT,
targetSubject: inviteEmailSubject,
targetEmail: emailTwo,
requireHtml: true,
})
.then((email) => {
if (email) {
Expand Down Expand Up @@ -362,6 +364,7 @@ describe(
timeout: TIMEOUT,
targetSubject: inviteEmailSubject,
targetEmail: emailThree,
requireHtml: true,
})
.then((email) => {
if (email) {
Expand Down Expand Up @@ -464,6 +467,7 @@ describe(
timeout: TIMEOUT,
targetSubject: inviteEmailSubject,
targetEmail: emailFour,
requireHtml: true,
})
.then((email) => {
if (email) {
Expand Down
26 changes: 18 additions & 8 deletions app/client/cypress/support/Pages/AggregateHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2025,6 +2025,7 @@ export class AggregateHelper {

public waitForEmail({
pollInterval,
requireHtml = false,
targetEmail,
targetSubject,
timeout,
Expand All @@ -2033,6 +2034,7 @@ export class AggregateHelper {
timeout: number;
targetSubject: string;
targetEmail?: string;
requireHtml?: boolean;
}): Cypress.Chainable<any> {
const endTime = Date.now() + timeout;
let latestEmail: any = null;
Expand All @@ -2058,6 +2060,7 @@ export class AggregateHelper {
from: string;
};
text: string;
html?: string;
}> = res.body;

const matchingEmails = emails.filter((email) => {
Expand All @@ -2066,14 +2069,21 @@ export class AggregateHelper {
.toLowerCase()
.includes(targetSubject.trim().toLowerCase());

if (targetEmail) {
const emailTo = email.headers.to.trim().toLowerCase();
return (
subjectMatch && emailTo === targetEmail.trim().toLowerCase()
);
}

return subjectMatch;
const recipientMatch = targetEmail
? email.headers.to.trim().toLowerCase() ===
targetEmail.trim().toLowerCase()
: true;

// When the caller needs the HTML body, treat a matched email whose
// body has not been populated yet as "not yet delivered" and keep
// polling, rather than returning it and letting the caller throw on
// email.html. Maildev can surface an email's metadata before its
// HTML part is parsed, especially under load.
const htmlReady =
!requireHtml ||
(typeof email.html === "string" && email.html.length > 0);

return subjectMatch && recipientMatch && htmlReady;
});

if (matchingEmails.length > 0) {
Expand Down
Loading