From dd08e285b4fb22a627ddfe2b7f5b5037875f5ea6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Heiko=20L=C3=BCbbe?= Date: Thu, 20 Jun 2024 16:24:33 +0200 Subject: [PATCH] [cypress] Fail in case of SMTP problems with a clear message (#43492) * Fail in case of SMTP problems with a clear message If the array `mail[]` is empty width length 0, the line `cy.wrap(mails).should('have.lengthOf', 1);` does not cause the test to stop in this case as the Cypress assertion inside the `.then()` has an asynchronous nature. The effect is that the test run continues and the following access to the mail fails with with a somehow incomprehensible message e.g. `TypeError: Cannot read properties of undefined (reading 'body')` Replaced it with an `expect` statement, which immediately triggers an error, and added an individual message that the SNMP configuration may need to be checked. Added two more places. * Remove custom failure msg from mail cnt assertion * Update tests/System/integration/administrator/components/com_config/Application.cy.js --------- Co-authored-by: Allon Moritz --- .../components/com_config/Application.cy.js | 2 +- .../System/integration/api/com_contact/Contacts.cy.js | 2 +- .../site/components/com_privacy/Request.cy.js | 10 ++++++---- .../integration/site/components/com_users/Remind.cy.js | 6 +++--- .../integration/site/components/com_users/Reset.cy.js | 6 +++--- 5 files changed, 14 insertions(+), 12 deletions(-) diff --git a/tests/System/integration/administrator/components/com_config/Application.cy.js b/tests/System/integration/administrator/components/com_config/Application.cy.js index 004420961815d..4a9be2772a950 100644 --- a/tests/System/integration/administrator/components/com_config/Application.cy.js +++ b/tests/System/integration/administrator/components/com_config/Application.cy.js @@ -24,7 +24,7 @@ describe('Test in backend that the application configuration', () => { cy.task('getMails').then((mails) => { cy.get('#system-message-container').should('contain.text', 'The email was sent to'); - cy.wrap(mails).should('have.lengthOf', 1); + expect(mails.length).to.equal(1); cy.wrap(mails[0].body).should('have.string', 'This is a test mail sent using'); cy.wrap(mails[0].sender).should('equal', Cypress.env('email')); cy.wrap(mails[0].receivers).should('have.property', Cypress.env('email')); diff --git a/tests/System/integration/api/com_contact/Contacts.cy.js b/tests/System/integration/api/com_contact/Contacts.cy.js index 632e7bd0e6af1..0e428f617debe 100644 --- a/tests/System/integration/api/com_contact/Contacts.cy.js +++ b/tests/System/integration/api/com_contact/Contacts.cy.js @@ -57,7 +57,7 @@ describe('Test that contacts API endpoint', () => { .should('equal', 200)); cy.task('getMails').then((mails) => { - cy.wrap(mails).should('have.lengthOf', 1); + expect(mails.length).to.equal(1); cy.wrap(mails[0].sender).should('equal', Cypress.env('email')); cy.wrap(mails[0].receivers).should('have.property', Cypress.env('email')); cy.wrap(mails[0].headers.subject).should('equal', `${Cypress.env('sitename')}: automated test subject`); diff --git a/tests/System/integration/site/components/com_privacy/Request.cy.js b/tests/System/integration/site/components/com_privacy/Request.cy.js index 6064fbee328ef..f4122ab668c11 100644 --- a/tests/System/integration/site/components/com_privacy/Request.cy.js +++ b/tests/System/integration/site/components/com_privacy/Request.cy.js @@ -12,7 +12,7 @@ describe('Test in frontend that the privacy request view', () => { cy.task('getMails').then((mails) => { cy.get('.alert-message').should('contain.text', 'Your information request has been created. Before it can be processed, you must verify this request. An email has been sent to your address with additional instructions to complete this verification.'); - cy.wrap(mails).should('have.lengthOf', 2); + expect(mails.length).to.equal(2); cy.wrap(mails[0].sender).should('equal', Cypress.env('email')); cy.wrap(mails[0].body).should('have.string', `A new information request has been submitted by ${Cypress.env('email')}.`); cy.wrap(mails[1].body).should('have.string', 'Someone has created a request to export all personal information related to this email address at '); @@ -29,7 +29,7 @@ describe('Test in frontend that the privacy request view', () => { cy.task('getMails').then((mails) => { cy.get('.alert-message').should('contain.text', 'Your information request has been created. Before it can be processed, you must verify this request. An email has been sent to your address with additional instructions to complete this verification.'); - cy.wrap(mails).should('have.lengthOf', 2); + expect(mails.length).to.equal(2); cy.wrap(mails[0].sender).should('equal', Cypress.env('email')); cy.wrap(mails[0].body).should('have.string', `A new information request has been submitted by ${Cypress.env('email')}.`); cy.wrap(mails[1].body).should('have.string', 'Someone has created a request to export all personal information related to this email address at '); @@ -44,7 +44,7 @@ describe('Test in frontend that the privacy request view', () => { cy.task('getMails').then((mails) => { cy.get('.alert-message').should('contain.text', 'Your information request has been created. Before it can be processed, you must verify this request. An email has been sent to your address with additional instructions to complete this verification.'); - cy.wrap(mails).should('have.lengthOf', 2); + expect(mails.length).to.equal(2); cy.wrap(mails[0].sender).should('equal', Cypress.env('email')); cy.wrap(mails[0].body).should('have.string', `A new information request has been submitted by ${Cypress.env('email')}.`); cy.wrap(mails[1].body).should('have.string', 'Someone has created a request to remove all personal information related to this email address at '); @@ -61,7 +61,7 @@ describe('Test in frontend that the privacy request view', () => { cy.task('getMails').then((mails) => { cy.get('.alert-message').should('contain.text', 'Your information request has been created. Before it can be processed, you must verify this request. An email has been sent to your address with additional instructions to complete this verification.'); - cy.wrap(mails).should('have.lengthOf', 2); + expect(mails.length).to.equal(2); cy.wrap(mails[0].sender).should('equal', Cypress.env('email')); cy.wrap(mails[0].body).should('have.string', `A new information request has been submitted by ${Cypress.env('email')}.`); cy.wrap(mails[1].body).should('have.string', 'Someone has created a request to remove all personal information related to this email address at '); @@ -75,6 +75,7 @@ describe('Test in frontend that the privacy request view', () => { cy.get('.controls > .btn').click(); cy.task('getMails').then((mails) => { + expect(mails.length).to.equal(2); const str = mails[1].body; const firstSplit = str.split('URL: ')[1]; @@ -93,6 +94,7 @@ describe('Test in frontend that the privacy request view', () => { cy.get('.controls > .btn').click(); cy.task('getMails').then((mails) => { + expect(mails.length).to.equal(2); const str = mails[1].body; const firstSplitURL = str.split('paste your token into the form.\n')[1]; diff --git a/tests/System/integration/site/components/com_users/Remind.cy.js b/tests/System/integration/site/components/com_users/Remind.cy.js index cfff552d39d77..102463660b064 100644 --- a/tests/System/integration/site/components/com_users/Remind.cy.js +++ b/tests/System/integration/site/components/com_users/Remind.cy.js @@ -15,7 +15,7 @@ describe('Test in frontend that the users remind view', () => { cy.task('getMails').then((mails) => { cy.get('#system-message-container').should('contain.text', 'If the email address you entered is registered on this site you will shortly receive an email with a reminder.'); - cy.wrap(mails).should('have.lengthOf', 1); + expect(mails.length).to.equal(1); cy.wrap(mails[0].body).should('have.string', 'A username reminder has been requested'); cy.wrap(mails[0].body).should('have.string', '/test-reminder'); cy.wrap(mails[0].sender).should('equal', Cypress.env('email')); @@ -34,7 +34,7 @@ describe('Test in frontend that the users remind view', () => { cy.task('getMails').then((mails) => { cy.get('#system-message-container').should('contain.text', 'If the email address you entered is registered on this site you will shortly receive an email with a reminder.'); - cy.wrap(mails).should('have.lengthOf', 1); + expect(mails.length).to.equal(1); cy.wrap(mails[0].body).should('have.string', 'A username reminder has been requested'); cy.wrap(mails[0].body).should('have.string', '/component/users/login'); cy.wrap(mails[0].sender).should('equal', Cypress.env('email')); @@ -51,7 +51,7 @@ describe('Test in frontend that the users remind view', () => { cy.task('getMails').then((mails) => { cy.get('#system-message-container').should('contain.text', 'If the email address you entered is registered on this site you will shortly receive an email with a reminder.'); - cy.wrap(mails).should('have.lengthOf', 0); + expect(mails.length).to.equal(0); }); }); }); diff --git a/tests/System/integration/site/components/com_users/Reset.cy.js b/tests/System/integration/site/components/com_users/Reset.cy.js index c70f3d50178f0..df93ce7e5f952 100644 --- a/tests/System/integration/site/components/com_users/Reset.cy.js +++ b/tests/System/integration/site/components/com_users/Reset.cy.js @@ -11,7 +11,7 @@ describe('Test in frontend that the users reset view', () => { cy.task('getMails').then((mails) => { cy.get('#system-message-container').should('contain.text', 'If the email address you entered is registered on this site you will shortly receive an email with a link to reset the password for your account.'); - cy.wrap(mails).should('have.lengthOf', 1); + expect(mails.length).to.equal(1); cy.wrap(mails[0].body).should('have.string', 'To reset your password, you will need to submit this verification code'); cy.wrap(mails[0].body).should('have.string', '/component/users/reset'); cy.wrap(mails[0].sender).should('equal', Cypress.env('email')); @@ -34,7 +34,7 @@ describe('Test in frontend that the users reset view', () => { cy.task('getMails').then((mails) => { cy.get('#system-message-container').should('contain.text', 'If the email address you entered is registered on this site you will shortly receive an email with a link to reset the password for your account.'); - cy.wrap(mails).should('have.lengthOf', 1); + expect(mails.length).to.equal(1); cy.wrap(mails[0].body).should('have.string', 'To reset your password, you will need to submit this verification code'); cy.wrap(mails[0].body).should('have.string', '/test-reset'); cy.wrap(mails[0].sender).should('equal', Cypress.env('email')); @@ -51,7 +51,7 @@ describe('Test in frontend that the users reset view', () => { cy.task('getMails').then((mails) => { cy.get('#system-message-container').should('contain.text', 'If the email address you entered is registered on this site you will shortly receive an email with a link to reset the password for your account.'); - cy.wrap(mails).should('have.lengthOf', 0); + expect(mails.length).to.equal(0); }); });