From d086643ac01167204f681ba5d9d56ca8575cb027 Mon Sep 17 00:00:00 2001 From: muhme Date: Sun, 19 May 2024 09:52:41 +0200 Subject: [PATCH 1/3] 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. --- .../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..2732285586b0b 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, 'There is not just one mail, you may need to check the SMTP configuration').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..d31a910c4ab2c 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, 'There is not just one mail, you may need to check the SMTP configuration').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..68f88787b7a55 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, 'There are not two mails, you may need to check the SMTP configuration').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, 'There are not two mails, you may need to check the SMTP configuration').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, 'There are not two mails, you may need to check the SMTP configuration').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, 'There are not two mails, you may need to check the SMTP configuration').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, 'There are not two mails, you may need to check the SMTP configuration').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, 'There are not two mails, you may need to check the SMTP configuration').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..8e0ed61e9e6ab 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, 'There is not just one mail, you may need to check the SMTP configuration').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, 'There is not just one mail, you may need to check the SMTP configuration').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, 'There should be no mail').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..f7d92683a51cd 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, 'There is not just one mail, you may need to check the SMTP configuration').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, 'There is not just one mail, you may need to check the SMTP configuration').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, 'There should be no mails').to.equal(0); }); }); From e6d3d0f3c2214b27d7f00969fc29b1502ac2ad75 Mon Sep 17 00:00:00 2001 From: muhme Date: Fri, 14 Jun 2024 17:09:18 +0200 Subject: [PATCH 2/3] Remove custom failure msg from mail cnt assertion --- .../components/com_config/Application.cy.js | 3 +-- .../integration/api/com_contact/Contacts.cy.js | 2 +- .../site/components/com_privacy/Request.cy.js | 12 ++++++------ .../site/components/com_users/Remind.cy.js | 6 +++--- .../site/components/com_users/Reset.cy.js | 6 +++--- 5 files changed, 14 insertions(+), 15 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 2732285586b0b..099f800586f27 100644 --- a/tests/System/integration/administrator/components/com_config/Application.cy.js +++ b/tests/System/integration/administrator/components/com_config/Application.cy.js @@ -23,8 +23,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'); - - expect(mails.length, 'There is not just one mail, you may need to check the SMTP configuration').to.equal(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 d31a910c4ab2c..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) => { - expect(mails.length, 'There is not just one mail, you may need to check the SMTP configuration').to.equal(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 68f88787b7a55..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.'); - expect(mails.length, 'There are not two mails, you may need to check the SMTP configuration').to.equal(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.'); - expect(mails.length, 'There are not two mails, you may need to check the SMTP configuration').to.equal(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.'); - expect(mails.length, 'There are not two mails, you may need to check the SMTP configuration').to.equal(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.'); - expect(mails.length, 'There are not two mails, you may need to check the SMTP configuration').to.equal(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,7 +75,7 @@ describe('Test in frontend that the privacy request view', () => { cy.get('.controls > .btn').click(); cy.task('getMails').then((mails) => { - expect(mails.length, 'There are not two mails, you may need to check the SMTP configuration').to.equal(2); + expect(mails.length).to.equal(2); const str = mails[1].body; const firstSplit = str.split('URL: ')[1]; @@ -94,7 +94,7 @@ describe('Test in frontend that the privacy request view', () => { cy.get('.controls > .btn').click(); cy.task('getMails').then((mails) => { - expect(mails.length, 'There are not two mails, you may need to check the SMTP configuration').to.equal(2); + 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 8e0ed61e9e6ab..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.'); - expect(mails.length, 'There is not just one mail, you may need to check the SMTP configuration').to.equal(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.'); - expect(mails.length, 'There is not just one mail, you may need to check the SMTP configuration').to.equal(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.'); - expect(mails.length, 'There should be no mail').to.equal(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 f7d92683a51cd..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.'); - expect(mails.length, 'There is not just one mail, you may need to check the SMTP configuration').to.equal(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.'); - expect(mails.length, 'There is not just one mail, you may need to check the SMTP configuration').to.equal(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.'); - expect(mails.length, 'There should be no mails').to.equal(0); + expect(mails.length).to.equal(0); }); }); From 286bd6d6d92796f96e8732bf05c97ac58ce95f8f Mon Sep 17 00:00:00 2001 From: Allon Moritz Date: Thu, 20 Jun 2024 15:00:49 +0200 Subject: [PATCH 3/3] Update tests/System/integration/administrator/components/com_config/Application.cy.js --- .../administrator/components/com_config/Application.cy.js | 1 + 1 file changed, 1 insertion(+) 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 099f800586f27..4a9be2772a950 100644 --- a/tests/System/integration/administrator/components/com_config/Application.cy.js +++ b/tests/System/integration/administrator/components/com_config/Application.cy.js @@ -23,6 +23,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'); + 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'));