Skip to content

Commit

Permalink
Add test to prevent invalid email from unsubscribing
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxwellGarceau committed Dec 24, 2024
1 parent 0bc4fa9 commit 87050ef
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions tests/cypress/e2e/unsubscribe.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
describe('Unsubscribe form', () => {
let shortcodePostURL;
let blockPostPostURL;
const testEmail = '[email protected]';

before(() => {
// TODO: Initialize tests from a blank state
Expand Down Expand Up @@ -34,6 +33,8 @@ describe('Unsubscribe form', () => {
})

it('unsubscribes valid emails that were previously subscribed to a list', () => {
const testEmail = '[email protected]';

[shortcodePostURL, blockPostPostURL].forEach((url) => {
let baseUrl;

Expand Down Expand Up @@ -78,11 +79,28 @@ describe('Unsubscribe form', () => {
});

it('throws an error when unsubscribing an email that was never subscribed to a list', () => {
// Visit the mailchimp block page
// Assert unsubscribe link exists
// Visit unsubscribe link
// Unsubscribe
// Assert that the unsubscribe didn't work because the email isn't subscribed
const testEmail = '[email protected]';

[shortcodePostURL, blockPostPostURL].forEach((url) => {
// Visit the mailchimp block page
cy.visit(url);

// Assert unsubscribe link exists
cy.get('a[href*="/unsubscribe"]').should('exist');

// Visit unsubscribe link
cy.get('a[href*="/unsubscribe"]')
.invoke('removeAttr', 'target') // Prevent opening in new window so that Cypress can test
.click();

// Unsubscribe
cy.get('#email-address').type(testEmail);
cy.get('input[type="submit"]').click();

// Assert that the unsubscribe didn't work because the email isn't subscribed
cy.get('.errorText').should('contain', 'this email is not subscribed');

});
});

it('does not display an unsubscribe link when the unsubscribe option is disabled', () => {
Expand Down

0 comments on commit 87050ef

Please sign in to comment.