diff --git a/cypress/e2e/send-mail-with-php.mailtrap.cy.ts b/cypress/e2e/send-mail-with-php.mailtrap.cy.ts index 5036f1e..7f75a7b 100644 --- a/cypress/e2e/send-mail-with-php.mailtrap.cy.ts +++ b/cypress/e2e/send-mail-with-php.mailtrap.cy.ts @@ -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: "baikal@example.com", - to_email: "to@example.com", + // 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: "baikal@example.com", + to_email: "to@example.com", + }, + ]); + }); + }, + ); });