-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Retry mail test automation to address flakiness (#146)
Co-authored-by: Cyrill Kulka <[email protected]>
- Loading branch information
1 parent
e6bd948
commit 1a8553c
Showing
1 changed file
with
48 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,54 @@ | ||
describe("Send mail with PHP", () => { | ||
it("Should send an email with PHP", () => { | ||
let token = Cypress.env("MAILTRAP_TOKEN"); | ||
let accountId = Cypress.env("MAILTRAP_ACCOUNTID"); | ||
let inboxId = Cypress.env("MAILTRAP_INBOXID"); | ||
|
||
expect(token).to.exist; | ||
expect(accountId).to.exist; | ||
expect(inboxId).to.exist; | ||
|
||
// Clean email inbox | ||
cy.request({ | ||
method: "PATCH", | ||
url: `https://mailtrap.io/api/accounts/${accountId}/inboxes/${inboxId}/clean`, | ||
auth: { | ||
bearer: token, | ||
it( | ||
"Should send an email with PHP", | ||
{ | ||
// Retry to address flakiness of sending and receiving emails | ||
retries: { | ||
runMode: 3, | ||
openMode: 3, | ||
}, | ||
}); | ||
}, | ||
() => { | ||
let token = Cypress.env("MAILTRAP_TOKEN"); | ||
let accountId = Cypress.env("MAILTRAP_ACCOUNTID"); | ||
let inboxId = Cypress.env("MAILTRAP_INBOXID"); | ||
|
||
// Send email through PHP | ||
expect(Cypress.env("MAILTRAP_SUBJECT")).to.exist; | ||
cy.request({ | ||
method: "GET", | ||
url: "localhost/mail-test.php", | ||
qs: { | ||
subject: Cypress.env("MAILTRAP_SUBJECT"), | ||
}, | ||
}); | ||
expect(token, "No mailtrap API token MAILTRAP_TOKEN").to.exist; | ||
expect(accountId, "No mailtrap account id MAILTRAP_ACCOUNTID").to.exist; | ||
expect(inboxId, "No mailtrap inbox id MAILTRAP_INBOXID").to.exist; | ||
|
||
// Verify that the email arrived | ||
cy.request({ | ||
method: "GET", | ||
url: `https://mailtrap.io/api/accounts/${accountId}/inboxes/${inboxId}/messages`, | ||
auth: { | ||
bearer: token, | ||
}, | ||
}).should((response) => { | ||
expect(response.status).to.be.ok; | ||
expect(response.body).to.be.an("array"); | ||
let actual = response.body.map((e) => ({ | ||
subject: e.subject, | ||
from_email: e.from_email, | ||
to_email: e.to_email, | ||
})); | ||
expect(actual).to.deep.include.members([ | ||
{ | ||
subject: Cypress.env("MAILTRAP_SUBJECT"), | ||
from_email: "[email protected]", | ||
to_email: "[email protected]", | ||
// Send email through PHP | ||
let subject = `Cypress ${crypto.randomUUID()}`; | ||
cy.request({ | ||
method: "GET", | ||
url: "localhost/mail-test.php", | ||
qs: { | ||
subject: subject, | ||
}, | ||
}); | ||
|
||
// Verify that the email arrived | ||
cy.request({ | ||
method: "GET", | ||
url: `https://mailtrap.io/api/accounts/${accountId}/inboxes/${inboxId}/messages`, | ||
auth: { | ||
bearer: token, | ||
}, | ||
]); | ||
}); | ||
}); | ||
}).should((response) => { | ||
expect(response.body).to.be.an("array"); | ||
let actual = response.body.map((e) => ({ | ||
subject: e.subject, | ||
from_email: e.from_email, | ||
to_email: e.to_email, | ||
})); | ||
expect(actual).to.deep.include.members([ | ||
{ | ||
subject: subject, | ||
from_email: "[email protected]", | ||
to_email: "[email protected]", | ||
}, | ||
]); | ||
}); | ||
}, | ||
); | ||
}); |