From 19a563bc6a82c1102411bdc37431abed287f9cd1 Mon Sep 17 00:00:00 2001 From: witzig Date: Sun, 28 May 2017 00:11:30 +0200 Subject: [PATCH] Remaining e2e subscription tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit @bures, I’m not too happy with switchToList(). Suggestions? If we keep it, it should probably be added to every useCase. --- setup/sql/mailtrain-test.sql | 173 +++++++++++++++++++++-- test/e2e/lib/config.js | 37 ++++- test/e2e/page-objects/subscription.js | 32 ++++- test/e2e/tests/subscription.js | 195 +++++++++++++++++++++++++- 4 files changed, 410 insertions(+), 27 deletions(-) diff --git a/setup/sql/mailtrain-test.sql b/setup/sql/mailtrain-test.sql index 8ae97db9..11dc6681 100644 --- a/setup/sql/mailtrain-test.sql +++ b/setup/sql/mailtrain-test.sql @@ -69,7 +69,6 @@ CREATE TABLE `campaigns` ( `html_prepared` longtext, `text` longtext, `status` tinyint(4) unsigned NOT NULL DEFAULT '1', - `tracking_disabled` tinyint(4) unsigned NOT NULL DEFAULT '0', `scheduled` timestamp NULL DEFAULT NULL, `status_change` timestamp NULL DEFAULT NULL, `delivered` int(11) unsigned NOT NULL DEFAULT '0', @@ -80,6 +79,8 @@ CREATE TABLE `campaigns` ( `bounced` int(1) unsigned NOT NULL DEFAULT '0', `complained` int(1) unsigned NOT NULL DEFAULT '0', `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `open_tracking_disabled` tinyint(4) unsigned NOT NULL DEFAULT '0', + `click_tracking_disabled` tinyint(4) unsigned NOT NULL DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY `cid` (`cid`), KEY `name` (`name`(191)), @@ -93,8 +94,8 @@ CREATE TABLE `confirmations` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `cid` varchar(255) CHARACTER SET ascii NOT NULL, `list` int(11) unsigned NOT NULL, - `email` varchar(255) NOT NULL, - `opt_in_ip` varchar(100) DEFAULT NULL, + `action` varchar(100) NOT NULL, + `ip` varchar(100) DEFAULT NULL, `data` text NOT NULL, `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`), @@ -193,11 +194,17 @@ CREATE TABLE `lists` ( `subscribers` int(11) unsigned DEFAULT '0', `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `public_subscribe` tinyint(1) unsigned NOT NULL DEFAULT '1', + `unsubscription_mode` int(11) unsigned NOT NULL DEFAULT '0', PRIMARY KEY (`id`), UNIQUE KEY `cid` (`cid`), KEY `name` (`name`(191)) -) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4; -INSERT INTO `lists` (`id`, `cid`, `default_form`, `name`, `description`, `subscribers`, `created`, `public_subscribe`) VALUES (1,'Hkj1vCoJb',NULL,'01 Testlist - Public Subscribe','',0,NOW(),1); +) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4; +INSERT INTO `lists` (`id`, `cid`, `default_form`, `name`, `description`, `subscribers`, `created`, `public_subscribe`, `unsubscription_mode`) VALUES (1,'Hkj1vCoJb',0,'#1 (one-step, no form)','',0,NOW(),1,0); +INSERT INTO `lists` (`id`, `cid`, `default_form`, `name`, `description`, `subscribers`, `created`, `public_subscribe`, `unsubscription_mode`) VALUES (2,'SktV4HDZ-',NULL,'#2 (one-step, with form)','',0,NOW(),1,1); +INSERT INTO `lists` (`id`, `cid`, `default_form`, `name`, `description`, `subscribers`, `created`, `public_subscribe`, `unsubscription_mode`) VALUES (3,'BkdvNBw-W',NULL,'#3 (two-step, no form)','',0,NOW(),1,2); +INSERT INTO `lists` (`id`, `cid`, `default_form`, `name`, `description`, `subscribers`, `created`, `public_subscribe`, `unsubscription_mode`) VALUES (4,'rJMKVrDZ-',NULL,'#4 (two-step, with form)','',0,NOW(),1,3); +INSERT INTO `lists` (`id`, `cid`, `default_form`, `name`, `description`, `subscribers`, `created`, `public_subscribe`, `unsubscription_mode`) VALUES (5,'SJgoNSw-W',NULL,'#5 (manual unsubscribe)','',0,NOW(),1,4); +INSERT INTO `lists` (`id`, `cid`, `default_form`, `name`, `description`, `subscribers`, `created`, `public_subscribe`, `unsubscription_mode`) VALUES (6,'HyveEPvWW',NULL,'#6 non-public','',0,NOW(),0,0); CREATE TABLE `queued` ( `campaign` int(11) unsigned NOT NULL, `list` int(11) unsigned NOT NULL, @@ -269,7 +276,7 @@ CREATE TABLE `settings` ( `value` text NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `key` (`key`) -) ENGINE=InnoDB AUTO_INCREMENT=112 DEFAULT CHARSET=utf8mb4; +) ENGINE=InnoDB AUTO_INCREMENT=114 DEFAULT CHARSET=utf8mb4; INSERT INTO `settings` (`id`, `key`, `value`) VALUES (1,'smtp_hostname','localhost'); INSERT INTO `settings` (`id`, `key`, `value`) VALUES (2,'smtp_port','5587'); INSERT INTO `settings` (`id`, `key`, `value`) VALUES (3,'smtp_encryption','NONE'); @@ -286,7 +293,7 @@ INSERT INTO `settings` (`id`, `key`, `value`) VALUES (13,'default_from','My Awes INSERT INTO `settings` (`id`, `key`, `value`) VALUES (14,'default_address','admin@example.com'); INSERT INTO `settings` (`id`, `key`, `value`) VALUES (15,'default_subject','Test message'); INSERT INTO `settings` (`id`, `key`, `value`) VALUES (16,'default_homepage','https://mailtrain.org'); -INSERT INTO `settings` (`id`, `key`, `value`) VALUES (17,'db_schema_version','27'); +INSERT INTO `settings` (`id`, `key`, `value`) VALUES (17,'db_schema_version','29'); INSERT INTO `settings` (`id`, `key`, `value`) VALUES (46,'ua_code',''); INSERT INTO `settings` (`id`, `key`, `value`) VALUES (47,'shoutout',''); INSERT INTO `settings` (`id`, `key`, `value`) VALUES (54,'mail_transport','smtp'); @@ -361,6 +368,146 @@ CREATE TABLE `subscription__1` ( KEY `latest_click` (`latest_click`), KEY `created` (`created`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; +CREATE TABLE `subscription__2` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `cid` varchar(255) CHARACTER SET ascii NOT NULL, + `email` varchar(255) CHARACTER SET utf8 NOT NULL DEFAULT '', + `opt_in_ip` varchar(100) DEFAULT NULL, + `opt_in_country` varchar(2) DEFAULT NULL, + `tz` varchar(100) CHARACTER SET ascii DEFAULT NULL, + `imported` int(11) unsigned DEFAULT NULL, + `status` tinyint(4) unsigned NOT NULL DEFAULT '1', + `is_test` tinyint(4) unsigned NOT NULL DEFAULT '0', + `status_change` timestamp NULL DEFAULT NULL, + `latest_open` timestamp NULL DEFAULT NULL, + `latest_click` timestamp NULL DEFAULT NULL, + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `first_name` varchar(255) DEFAULT NULL, + `last_name` varchar(255) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `email` (`email`), + UNIQUE KEY `cid` (`cid`), + KEY `status` (`status`), + KEY `first_name` (`first_name`(191)), + KEY `last_name` (`last_name`(191)), + KEY `subscriber_tz` (`tz`), + KEY `is_test` (`is_test`), + KEY `latest_open` (`latest_open`), + KEY `latest_click` (`latest_click`), + KEY `created` (`created`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; +CREATE TABLE `subscription__3` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `cid` varchar(255) CHARACTER SET ascii NOT NULL, + `email` varchar(255) CHARACTER SET utf8 NOT NULL DEFAULT '', + `opt_in_ip` varchar(100) DEFAULT NULL, + `opt_in_country` varchar(2) DEFAULT NULL, + `tz` varchar(100) CHARACTER SET ascii DEFAULT NULL, + `imported` int(11) unsigned DEFAULT NULL, + `status` tinyint(4) unsigned NOT NULL DEFAULT '1', + `is_test` tinyint(4) unsigned NOT NULL DEFAULT '0', + `status_change` timestamp NULL DEFAULT NULL, + `latest_open` timestamp NULL DEFAULT NULL, + `latest_click` timestamp NULL DEFAULT NULL, + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `first_name` varchar(255) DEFAULT NULL, + `last_name` varchar(255) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `email` (`email`), + UNIQUE KEY `cid` (`cid`), + KEY `status` (`status`), + KEY `first_name` (`first_name`(191)), + KEY `last_name` (`last_name`(191)), + KEY `subscriber_tz` (`tz`), + KEY `is_test` (`is_test`), + KEY `latest_open` (`latest_open`), + KEY `latest_click` (`latest_click`), + KEY `created` (`created`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; +CREATE TABLE `subscription__4` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `cid` varchar(255) CHARACTER SET ascii NOT NULL, + `email` varchar(255) CHARACTER SET utf8 NOT NULL DEFAULT '', + `opt_in_ip` varchar(100) DEFAULT NULL, + `opt_in_country` varchar(2) DEFAULT NULL, + `tz` varchar(100) CHARACTER SET ascii DEFAULT NULL, + `imported` int(11) unsigned DEFAULT NULL, + `status` tinyint(4) unsigned NOT NULL DEFAULT '1', + `is_test` tinyint(4) unsigned NOT NULL DEFAULT '0', + `status_change` timestamp NULL DEFAULT NULL, + `latest_open` timestamp NULL DEFAULT NULL, + `latest_click` timestamp NULL DEFAULT NULL, + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `first_name` varchar(255) DEFAULT NULL, + `last_name` varchar(255) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `email` (`email`), + UNIQUE KEY `cid` (`cid`), + KEY `status` (`status`), + KEY `first_name` (`first_name`(191)), + KEY `last_name` (`last_name`(191)), + KEY `subscriber_tz` (`tz`), + KEY `is_test` (`is_test`), + KEY `latest_open` (`latest_open`), + KEY `latest_click` (`latest_click`), + KEY `created` (`created`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; +CREATE TABLE `subscription__5` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `cid` varchar(255) CHARACTER SET ascii NOT NULL, + `email` varchar(255) CHARACTER SET utf8 NOT NULL DEFAULT '', + `opt_in_ip` varchar(100) DEFAULT NULL, + `opt_in_country` varchar(2) DEFAULT NULL, + `tz` varchar(100) CHARACTER SET ascii DEFAULT NULL, + `imported` int(11) unsigned DEFAULT NULL, + `status` tinyint(4) unsigned NOT NULL DEFAULT '1', + `is_test` tinyint(4) unsigned NOT NULL DEFAULT '0', + `status_change` timestamp NULL DEFAULT NULL, + `latest_open` timestamp NULL DEFAULT NULL, + `latest_click` timestamp NULL DEFAULT NULL, + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `first_name` varchar(255) DEFAULT NULL, + `last_name` varchar(255) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `email` (`email`), + UNIQUE KEY `cid` (`cid`), + KEY `status` (`status`), + KEY `first_name` (`first_name`(191)), + KEY `last_name` (`last_name`(191)), + KEY `subscriber_tz` (`tz`), + KEY `is_test` (`is_test`), + KEY `latest_open` (`latest_open`), + KEY `latest_click` (`latest_click`), + KEY `created` (`created`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; +CREATE TABLE `subscription__6` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `cid` varchar(255) CHARACTER SET ascii NOT NULL, + `email` varchar(255) CHARACTER SET utf8 NOT NULL DEFAULT '', + `opt_in_ip` varchar(100) DEFAULT NULL, + `opt_in_country` varchar(2) DEFAULT NULL, + `tz` varchar(100) CHARACTER SET ascii DEFAULT NULL, + `imported` int(11) unsigned DEFAULT NULL, + `status` tinyint(4) unsigned NOT NULL DEFAULT '1', + `is_test` tinyint(4) unsigned NOT NULL DEFAULT '0', + `status_change` timestamp NULL DEFAULT NULL, + `latest_open` timestamp NULL DEFAULT NULL, + `latest_click` timestamp NULL DEFAULT NULL, + `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, + `first_name` varchar(255) DEFAULT NULL, + `last_name` varchar(255) DEFAULT NULL, + PRIMARY KEY (`id`), + UNIQUE KEY `email` (`email`), + UNIQUE KEY `cid` (`cid`), + KEY `status` (`status`), + KEY `first_name` (`first_name`(191)), + KEY `last_name` (`last_name`(191)), + KEY `subscriber_tz` (`tz`), + KEY `is_test` (`is_test`), + KEY `latest_open` (`latest_open`), + KEY `latest_click` (`latest_click`), + KEY `created` (`created`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; CREATE TABLE `templates` ( `id` int(11) unsigned NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL DEFAULT '', @@ -422,14 +569,14 @@ INSERT INTO `tzoffset` (`tz`, `offset`) VALUES ('africa/blantyre',120); INSERT INTO `tzoffset` (`tz`, `offset`) VALUES ('africa/brazzaville',60); INSERT INTO `tzoffset` (`tz`, `offset`) VALUES ('africa/bujumbura',120); INSERT INTO `tzoffset` (`tz`, `offset`) VALUES ('africa/cairo',120); -INSERT INTO `tzoffset` (`tz`, `offset`) VALUES ('africa/casablanca',60); +INSERT INTO `tzoffset` (`tz`, `offset`) VALUES ('africa/casablanca',0); INSERT INTO `tzoffset` (`tz`, `offset`) VALUES ('africa/ceuta',120); INSERT INTO `tzoffset` (`tz`, `offset`) VALUES ('africa/conakry',0); INSERT INTO `tzoffset` (`tz`, `offset`) VALUES ('africa/dakar',0); INSERT INTO `tzoffset` (`tz`, `offset`) VALUES ('africa/dar_es_salaam',180); INSERT INTO `tzoffset` (`tz`, `offset`) VALUES ('africa/djibouti',180); INSERT INTO `tzoffset` (`tz`, `offset`) VALUES ('africa/douala',60); -INSERT INTO `tzoffset` (`tz`, `offset`) VALUES ('africa/el_aaiun',60); +INSERT INTO `tzoffset` (`tz`, `offset`) VALUES ('africa/el_aaiun',0); INSERT INTO `tzoffset` (`tz`, `offset`) VALUES ('africa/freetown',0); INSERT INTO `tzoffset` (`tz`, `offset`) VALUES ('africa/gaborone',120); INSERT INTO `tzoffset` (`tz`, `offset`) VALUES ('africa/harare',120); @@ -603,7 +750,7 @@ INSERT INTO `tzoffset` (`tz`, `offset`) VALUES ('america/rio_branco',-300); INSERT INTO `tzoffset` (`tz`, `offset`) VALUES ('america/rosario',-180); INSERT INTO `tzoffset` (`tz`, `offset`) VALUES ('america/santarem',-180); INSERT INTO `tzoffset` (`tz`, `offset`) VALUES ('america/santa_isabel',-420); -INSERT INTO `tzoffset` (`tz`, `offset`) VALUES ('america/santiago',-180); +INSERT INTO `tzoffset` (`tz`, `offset`) VALUES ('america/santiago',-240); INSERT INTO `tzoffset` (`tz`, `offset`) VALUES ('america/santo_domingo',-240); INSERT INTO `tzoffset` (`tz`, `offset`) VALUES ('america/sao_paulo',-180); INSERT INTO `tzoffset` (`tz`, `offset`) VALUES ('america/scoresbysund',0); @@ -788,8 +935,8 @@ INSERT INTO `tzoffset` (`tz`, `offset`) VALUES ('canada/pacific',-420); INSERT INTO `tzoffset` (`tz`, `offset`) VALUES ('canada/saskatchewan',-360); INSERT INTO `tzoffset` (`tz`, `offset`) VALUES ('canada/yukon',-420); INSERT INTO `tzoffset` (`tz`, `offset`) VALUES ('cet',120); -INSERT INTO `tzoffset` (`tz`, `offset`) VALUES ('chile/continental',-180); -INSERT INTO `tzoffset` (`tz`, `offset`) VALUES ('chile/easterisland',-300); +INSERT INTO `tzoffset` (`tz`, `offset`) VALUES ('chile/continental',-240); +INSERT INTO `tzoffset` (`tz`, `offset`) VALUES ('chile/easterisland',-360); INSERT INTO `tzoffset` (`tz`, `offset`) VALUES ('cst6cdt',-300); INSERT INTO `tzoffset` (`tz`, `offset`) VALUES ('cuba',-240); INSERT INTO `tzoffset` (`tz`, `offset`) VALUES ('eet',180); @@ -936,7 +1083,7 @@ INSERT INTO `tzoffset` (`tz`, `offset`) VALUES ('pacific/auckland',720); INSERT INTO `tzoffset` (`tz`, `offset`) VALUES ('pacific/bougainville',660); INSERT INTO `tzoffset` (`tz`, `offset`) VALUES ('pacific/chatham',765); INSERT INTO `tzoffset` (`tz`, `offset`) VALUES ('pacific/chuuk',600); -INSERT INTO `tzoffset` (`tz`, `offset`) VALUES ('pacific/easter',-300); +INSERT INTO `tzoffset` (`tz`, `offset`) VALUES ('pacific/easter',-360); INSERT INTO `tzoffset` (`tz`, `offset`) VALUES ('pacific/efate',660); INSERT INTO `tzoffset` (`tz`, `offset`) VALUES ('pacific/enderbury',780); INSERT INTO `tzoffset` (`tz`, `offset`) VALUES ('pacific/fakaofo',780); diff --git a/test/e2e/lib/config.js b/test/e2e/lib/config.js index a9d191be..223d2103 100644 --- a/test/e2e/lib/config.js +++ b/test/e2e/lib/config.js @@ -13,15 +13,46 @@ module.exports = { } }, lists: { - one: { + l1: { id: 1, cid: 'Hkj1vCoJb', publicSubscribe: 1, - unsubscriptionMode: 0 + unsubscriptionMode: 0, // (one-step, no form) + }, + l2: { + id: 2, + cid: 'SktV4HDZ-', + publicSubscribe: 1, + unsubscriptionMode: 1, // (one-step, with form) + }, + l3: { + id: 3, + cid: 'BkdvNBw-W', + publicSubscribe: 1, + unsubscriptionMode: 2, // (two-step, no form) + }, + l4: { + id: 4, + cid: 'rJMKVrDZ-', + publicSubscribe: 1, + unsubscriptionMode: 3, // (two-step, with form) + }, + l5: { + id: 5, + cid: 'SJgoNSw-W', + publicSubscribe: 1, + unsubscriptionMode: 4, // (manual unsubscribe) + }, + l6: { + id: 6, + cid: 'HyveEPvWW', + publicSubscribe: 0, + unsubscriptionMode: 0, // (one-step, no form) } }, settings: { - 'service-url' : 'http://localhost:' + config.www.port + '/', + 'service-url': 'http://localhost:' + config.www.port + '/', + 'admin-email': 'admin@example.com', 'default-homepage': 'https://mailtrain.org', 'smtp-hostname': config.testserver.host, 'smtp-port': config.testserver.port, diff --git a/test/e2e/page-objects/subscription.js b/test/e2e/page-objects/subscription.js index 1d431b49..6d3d98d9 100644 --- a/test/e2e/page-objects/subscription.js +++ b/test/e2e/page-objects/subscription.js @@ -19,6 +19,11 @@ module.exports = list => ({ } }), + webSubscribeNonPublic: web({ + url: `/subscription/${list.cid}`, + textsToWaitFor: ['The list does not allow public subscriptions'], + }), + webConfirmSubscriptionNotice: web({ url: `/subscription/${list.cid}/confirm-subscription-notice`, textsToWaitFor: ['We need to confirm your email address'] @@ -118,15 +123,34 @@ module.exports = list => ({ } }), - /* - webUnsubscribe: web({ // FIXME + webUnsubscribe: web({ elementsToWaitFor: ['submitButton'], + textsToWaitFor: ['Unsubscribe'], elements: { submitButton: 'a[href="#submit"]' } }), -*/ + webConfirmUnsubscriptionNotice: web({ + url: `/subscription/${list.cid}/confirm-unsubscription-notice`, + textsToWaitFor: ['We need to confirm your email address'] + }), + + mailConfirmUnsubscription: mail({ + elementsToWaitFor: ['confirmLink'], + textsToWaitFor: ['Please Confirm Unsubscription'], + elements: { + confirmLink: `a[href^="${config.settings['service-url']}subscription/confirm/unsubscribe/"]` + } + }), + + webManualUnsubscribeNotice: web({ + url: `/subscription/${list.cid}/manual-unsubscribe-notice`, + elementsToWaitFor: ['contactLink'], + textsToWaitFor: ['Online Unsubscription Is Not Possible', config.settings['admin-email']], + elements: { + contactLink: `a[href^="mailto:${config.settings['admin-email']}"]` + } + }), }); - diff --git a/test/e2e/tests/subscription.js b/test/e2e/tests/subscription.js index dabdc914..7e2ab262 100644 --- a/test/e2e/tests/subscription.js +++ b/test/e2e/tests/subscription.js @@ -4,8 +4,13 @@ const config = require('../lib/config'); const { useCase, step, precondition, driver } = require('../lib/mocha-e2e'); const shortid = require('shortid'); const expect = require('chai').expect; +const createPage = require('../page-objects/subscription'); -const page = require('../page-objects/subscription')(config.lists.one); +let page = createPage(config.lists.l1); + +function switchToList(list) { + page = createPage(config.lists[list]); +} function generateEmail() { return 'keep.' + shortid.generate() + '@mailtrain.org'; @@ -116,9 +121,17 @@ suite('Subscription use-cases', () => { }); - useCase('Subscription to a non-public list'); + useCase('Subscription to a non-public list', async () => { + switchToList('l6'); + + await step('User navigates to list subscription page and sees message that this list does not allow public subscriptions.', async () => { + await page.webSubscribeNonPublic.navigate(); + }); + }); useCase('Change profile info', async () => { + switchToList('l1'); + const subscription = await subscriptionExistsPrecondition({ email: generateEmail(), firstName: 'John', @@ -236,13 +249,181 @@ suite('Subscription use-cases', () => { }); }); - useCase('Unsubscription from list #2 (one-step, with form).'); + useCase('Unsubscription from list #2 (one-step, with form).', async () => { + switchToList('l2'); - useCase('Unsubscription from list #3 (two-step, no form).'); + const subscription = await subscriptionExistsPrecondition({ + email: generateEmail() + }); - useCase('Unsubscription from list #4 (two-step, with form).'); + await step('User clicks the unsubscribe button.', async () => { + await page.mailSubscriptionConfirmed.click('unsubscribeLink'); + }); - useCase('Unsubscription from list #5 (manual unsubscribe).'); + await step('Systems shows a form to unsubscribe.', async () => { + await page.webUnsubscribe.waitUntilVisibleAfterRefresh(); + }); + + await step('User confirms unsubscribe and clicks the unsubscribe button.', async () => { + await page.webUnsubscribe.submit(); + }); + + await step('System shows a notice that confirms unsubscription.', async () => { + await page.webUnsubscribedNotice.waitUntilVisibleAfterRefresh(); + }); + + await step('System sends an email that confirms unsubscription.', async () => { + await page.mailUnsubscriptionConfirmed.fetchMail(subscription.email); + }); + }); + + useCase('Unsubscription from list #3 (two-step, no form).', async () => { + switchToList('l3'); + + const subscription = await subscriptionExistsPrecondition({ + email: generateEmail() + }); + + await step('User clicks the unsubscribe button.', async () => { + await page.mailSubscriptionConfirmed.click('unsubscribeLink'); + }); + + await step('System shows a notice that further instructions are in the email.', async () => { + await page.webConfirmUnsubscriptionNotice.waitUntilVisibleAfterRefresh(); + }); + + await step('System sends an email with a link to confirm unsubscription.', async () => { + await page.mailConfirmUnsubscription.fetchMail(subscription.email); + }); + + await step('User clicks the confirm unsubscribe button in the email.', async () => { + await page.mailConfirmUnsubscription.click('confirmLink'); + }); + + await step('System shows a notice that confirms unsubscription.', async () => { + await page.webUnsubscribedNotice.waitUntilVisibleAfterRefresh(); + }); + + await step('System sends an email that confirms unsubscription.', async () => { + await page.mailUnsubscriptionConfirmed.fetchMail(subscription.email); + }); + }); + + useCase('Unsubscription from list #4 (two-step, with form).', async () => { + switchToList('l4'); + + const subscription = await subscriptionExistsPrecondition({ + email: generateEmail() + }); + + await step('User clicks the unsubscribe button.', async () => { + await page.mailSubscriptionConfirmed.click('unsubscribeLink'); + }); + + await step('Systems shows a form to unsubscribe.', async () => { + await page.webUnsubscribe.waitUntilVisibleAfterRefresh(); + }); + + await step('User confirms unsubscribe and clicks the unsubscribe button.', async () => { + await page.webUnsubscribe.submit(); + }); + + await step('System shows a notice that further instructions are in the email.', async () => { + await page.webConfirmUnsubscriptionNotice.waitUntilVisibleAfterRefresh(); + }); + + await step('System sends an email with a link to confirm unsubscription.', async () => { + await page.mailConfirmUnsubscription.fetchMail(subscription.email); + }); + + await step('User clicks the confirm unsubscribe button in the email.', async () => { + await page.mailConfirmUnsubscription.click('confirmLink'); + }); + + await step('System shows a notice that confirms unsubscription.', async () => { + await page.webUnsubscribedNotice.waitUntilVisibleAfterRefresh(); + }); + + await step('System sends an email that confirms unsubscription.', async () => { + await page.mailUnsubscriptionConfirmed.fetchMail(subscription.email); + }); + }); + + useCase('Unsubscription from list #5 (manual unsubscribe).', async () => { + switchToList('l5'); + + await subscriptionExistsPrecondition({ + email: generateEmail() + }); + + await step('User clicks the unsubscribe button.', async () => { + await page.mailSubscriptionConfirmed.click('unsubscribeLink'); + }); + + await step('Systems shows a notice that online unsubscription is not possible.', async () => { + await page.webManualUnsubscribeNotice.waitUntilVisibleAfterRefresh(); + }); + }); + + useCase('Resubscription.', async () => { + switchToList('l1'); + + const subscription = await subscriptionExistsPrecondition({ + email: generateEmail(), + firstName: 'John', + lastName: 'Doe' + }); + + await step('User clicks the unsubscribe button.', async () => { + await page.mailSubscriptionConfirmed.click('unsubscribeLink'); + }); + + await step('System shows a notice that confirms unsubscription.', async () => { + await page.webUnsubscribedNotice.waitUntilVisibleAfterRefresh(); + }); + + await step('System sends an email that confirms unsubscription.', async () => { + await page.mailUnsubscriptionConfirmed.fetchMail(subscription.email); + }); + + await step('User clicks the resubscribe button.', async () => { + await page.mailUnsubscriptionConfirmed.click('resubscribeLink'); + }); + + await step('Systems shows the subscription form. The form contains data entered during initial subscription.', async () => { + await page.webSubscribe.waitUntilVisibleAfterRefresh(); + expect(await page.webSubscribe.getValue('emailInput')).to.equal(subscription.email); + expect(await page.webSubscribe.getValue('firstNameInput')).to.equal(subscription.firstName); + expect(await page.webSubscribe.getValue('lastNameInput')).to.equal(subscription.lastName); + }); + + await step('User submits the subscription form.', async () => { + await page.webSubscribe.submit(); + }); + + await step('System shows a notice that further instructions are in the email.', async () => { + await page.webConfirmSubscriptionNotice.waitUntilVisibleAfterRefresh(); + }); + + await step('System sends an email with a link to confirm the subscription.', async () => { + await page.mailConfirmSubscription.fetchMail(subscription.email); + }); + + await step('User clicks confirm subscription in the email', async () => { + await page.mailConfirmSubscription.click('confirmLink'); + }); + + await step('System shows a notice that subscription has been confirmed.', async () => { + await page.webSubscribedNotice.waitUntilVisibleAfterRefresh(); + }); + + await step('System sends an email with subscription confirmation. The manage and unsubscribe links are identical with the initial subscription.', async () => { + await page.mailSubscriptionConfirmed.fetchMail(subscription.email); + const unsubscribeLink = await page.mailSubscriptionConfirmed.getHref('unsubscribeLink'); + const manageLink = await page.mailSubscriptionConfirmed.getHref('manageLink'); + expect(subscription.unsubscribeLink).to.equal(unsubscribeLink); + expect(subscription.manageLink).to.equal(manageLink); + }); + }); - useCase('Resubscription.'); // This one is supposed to check that values pre-filled in resubscription (i.e. the re-subscribe link in unsubscription confirmation) are the same as the ones used before. });