Skip to content

Commit

Permalink
[cypress] Fail in case of SMTP problems with a clear message (joomla#…
Browse files Browse the repository at this point in the history
…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 <allon.moritz@digital-peak.com>
  • Loading branch information
muhme and laoneo authored Jun 20, 2024
1 parent f4cb8dd commit dd08e28
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
2 changes: 1 addition & 1 deletion tests/System/integration/api/com_contact/Contacts.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 ');
Expand All @@ -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 ');
Expand All @@ -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 ');
Expand All @@ -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 ');
Expand All @@ -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];
Expand All @@ -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];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand All @@ -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'));
Expand All @@ -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);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand All @@ -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'));
Expand All @@ -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);
});
});

Expand Down

0 comments on commit dd08e28

Please sign in to comment.