Skip to content

Commit

Permalink
Retry mail test automation to address flakiness (#146)
Browse files Browse the repository at this point in the history
Co-authored-by: Cyrill Kulka <[email protected]>
  • Loading branch information
2 people authored and MrAlucardDante committed Dec 30, 2023
1 parent e6bd948 commit 1a8553c
Showing 1 changed file with 48 additions and 48 deletions.
96 changes: 48 additions & 48 deletions cypress/e2e/send-mail-with-php.mailtrap.cy.ts
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]",
},
]);
});
},
);
});

0 comments on commit 1a8553c

Please sign in to comment.