From ab10cc23f528e4d0c59e991464ab2742da073440 Mon Sep 17 00:00:00 2001 From: Stephen Daly Date: Thu, 14 Jan 2021 15:54:16 +0000 Subject: [PATCH] PP-7583 Move email notifications routes Change email notifications routes to use the new account URL structure. --- .secrets.baseline | 4 +-- app/paths.js | 24 +++++++-------- app/routes.js | 30 +++++++++---------- app/utils/nav-builder.js | 2 +- .../collection-email-mode.njk | 2 +- app/views/email-notifications/confirm.njk | 4 +-- .../confirmation-email-toggle.njk | 2 +- app/views/email-notifications/edit.njk | 4 +-- app/views/email-notifications/index.njk | 6 ++-- app/views/email-notifications/off-confirm.njk | 2 +- .../refund-email-toggle.njk | 2 +- app/views/settings/index.njk | 8 ++--- .../settings/email-notifications.cy.test.js | 18 ++++++----- 13 files changed, 55 insertions(+), 53 deletions(-) diff --git a/.secrets.baseline b/.secrets.baseline index 85f147503b..c2c7942a8c 100644 --- a/.secrets.baseline +++ b/.secrets.baseline @@ -3,7 +3,7 @@ "files": "package-lock.json", "lines": null }, - "generated_at": "2021-01-14T14:42:33Z", + "generated_at": "2021-01-14T15:18:01Z", "plugins_used": [ { "name": "AWSKeyDetector" @@ -72,7 +72,7 @@ "hashed_secret": "ece65afda87c1c6120602c9a3b66890308d7e53c", "is_secret": false, "is_verified": false, - "line_number": 62, + "line_number": 74, "type": "Secret Keyword" } ], diff --git a/app/paths.js b/app/paths.js index f18b86bad7..6af4a24e2f 100644 --- a/app/paths.js +++ b/app/paths.js @@ -16,6 +16,18 @@ module.exports = { applePay: '/digital-wallet/apple-pay', googlePay: '/digital-wallet/google-pay' }, + emailNotifications: { + index: '/email-notifications', + indexRefundTabEnabled: '/email-notifications-refund', + edit: '/email-notifications/edit', + confirm: '/email-notifications/confirm', + update: '/email-notifications/update', + off: '/email-notifications/off', + on: '/email-notifications/on', + collection: '/email-settings-collection', + confirmation: '/email-settings-confirmation', + refund: '/email-settings-refund' + }, paymentTypes: { index: '/payment-types' }, @@ -82,18 +94,6 @@ module.exports = { revoke: '/api-keys/revoke', update: '/api-keys/update' }, - emailNotifications: { - index: '/email-notifications', - indexRefundTabEnabled: '/email-notifications-refund', - edit: '/email-notifications/edit', - confirm: '/email-notifications/confirm', - update: '/email-notifications/update', - off: '/email-notifications/off', - on: '/email-notifications/on', - collection: '/email-settings-collection', - confirmation: '/email-settings-confirmation', - refund: '/email-settings-refund' - }, serviceSwitcher: { index: '/my-services', switch: '/my-services/switch', diff --git a/app/routes.js b/app/routes.js index 02f3ea50a0..7eab539511 100644 --- a/app/routes.js +++ b/app/routes.js @@ -88,12 +88,13 @@ const stripeSetupDashboardRedirectController = require('./controllers/stripe-set const { healthcheck, registerUser, user, dashboard, selfCreateService, transactions, credentials, apiKeys, serviceSwitcher, teamMembers, staticPaths, inviteValidation, editServiceName, merchantDetails, - notificationCredentials, emailNotifications: emailNotifications, toggleMotoMaskCardNumberAndSecurityCode, prototyping, paymentLinks, + notificationCredentials, toggleMotoMaskCardNumberAndSecurityCode, prototyping, paymentLinks, requestToGoLive, policyPages, stripeSetup, stripe, settings, yourPsp, allServiceTransactions, payouts } = paths const { digitalWallet, + emailNotifications, paymentTypes, toggle3ds, toggleBillingAddress @@ -177,7 +178,6 @@ module.exports.bind = function (app) { ...lodash.values(credentials), ...lodash.values(notificationCredentials), ...lodash.values(apiKeys), - ...lodash.values(emailNotifications), ...lodash.values(editServiceName), ...lodash.values(serviceSwitcher), ...lodash.values(teamMembers), @@ -253,19 +253,19 @@ module.exports.bind = function (app) { account.post(digitalWallet.googlePay, permission('payment-types:update'), paymentMethodIsCard, digitalWalletController.postGooglePay) // EMAIL - app.get(emailNotifications.index, permission('email-notification-template:read'), getAccount, getEmailNotification, paymentMethodIsCard, emailNotificationsController.index) - app.get(emailNotifications.indexRefundTabEnabled, permission('email-notification-template:read'), getAccount, getEmailNotification, paymentMethodIsCard, emailNotificationsController.indexRefundTabEnabled) - app.get(emailNotifications.edit, permission('email-notification-paragraph:update'), getAccount, getEmailNotification, paymentMethodIsCard, emailNotificationsController.edit) - app.post(emailNotifications.confirm, permission('email-notification-paragraph:update'), getAccount, getEmailNotification, paymentMethodIsCard, emailNotificationsController.confirm) - app.post(emailNotifications.update, permission('email-notification-paragraph:update'), getAccount, getEmailNotification, paymentMethodIsCard, emailNotificationsController.update) - app.get(emailNotifications.collection, permission('email-notification-template:read'), getAccount, getEmailNotification, paymentMethodIsCard, emailNotificationsController.collectionEmailIndex) - app.post(emailNotifications.collection, permission('email-notification-toggle:update'), getAccount, getEmailNotification, paymentMethodIsCard, emailNotificationsController.collectionEmailUpdate) - app.get(emailNotifications.confirmation, permission('email-notification-template:read'), getAccount, getEmailNotification, paymentMethodIsCard, emailNotificationsController.confirmationEmailIndex) - app.post(emailNotifications.confirmation, permission('email-notification-toggle:update'), getAccount, getEmailNotification, paymentMethodIsCard, emailNotificationsController.confirmationEmailUpdate) - app.post(emailNotifications.off, permission('email-notification-toggle:update'), getAccount, getEmailNotification, paymentMethodIsCard, emailNotificationsController.confirmationEmailOff) - app.post(emailNotifications.on, permission('email-notification-toggle:update'), getAccount, getEmailNotification, paymentMethodIsCard, emailNotificationsController.confirmationEmailOn) - app.get(emailNotifications.refund, permission('email-notification-template:read'), getAccount, getEmailNotification, paymentMethodIsCard, emailNotificationsController.refundEmailIndex) - app.post(emailNotifications.refund, permission('email-notification-toggle:update'), getAccount, getEmailNotification, paymentMethodIsCard, emailNotificationsController.refundEmailUpdate) + account.get(emailNotifications.index, permission('email-notification-template:read'), getEmailNotification, paymentMethodIsCard, emailNotificationsController.index) + account.get(emailNotifications.indexRefundTabEnabled, permission('email-notification-template:read'), getEmailNotification, paymentMethodIsCard, emailNotificationsController.indexRefundTabEnabled) + account.get(emailNotifications.edit, permission('email-notification-paragraph:update'), getEmailNotification, paymentMethodIsCard, emailNotificationsController.edit) + account.post(emailNotifications.confirm, permission('email-notification-paragraph:update'), getEmailNotification, paymentMethodIsCard, emailNotificationsController.confirm) + account.post(emailNotifications.update, permission('email-notification-paragraph:update'), getEmailNotification, paymentMethodIsCard, emailNotificationsController.update) + account.get(emailNotifications.collection, permission('email-notification-template:read'), getEmailNotification, paymentMethodIsCard, emailNotificationsController.collectionEmailIndex) + account.post(emailNotifications.collection, permission('email-notification-toggle:update'), getEmailNotification, paymentMethodIsCard, emailNotificationsController.collectionEmailUpdate) + account.get(emailNotifications.confirmation, permission('email-notification-template:read'), getEmailNotification, paymentMethodIsCard, emailNotificationsController.confirmationEmailIndex) + account.post(emailNotifications.confirmation, permission('email-notification-toggle:update'), getEmailNotification, paymentMethodIsCard, emailNotificationsController.confirmationEmailUpdate) + account.post(emailNotifications.off, permission('email-notification-toggle:update'), getEmailNotification, paymentMethodIsCard, emailNotificationsController.confirmationEmailOff) + account.post(emailNotifications.on, permission('email-notification-toggle:update'), getEmailNotification, paymentMethodIsCard, emailNotificationsController.confirmationEmailOn) + account.get(emailNotifications.refund, permission('email-notification-template:read'), getEmailNotification, paymentMethodIsCard, emailNotificationsController.refundEmailIndex) + account.post(emailNotifications.refund, permission('email-notification-toggle:update'), getEmailNotification, paymentMethodIsCard, emailNotificationsController.refundEmailUpdate) // SERVICE SWITCHER app.get(serviceSwitcher.index, myServicesController.getIndex) diff --git a/app/utils/nav-builder.js b/app/utils/nav-builder.js index b8c7557aea..662e99e7a7 100644 --- a/app/utils/nav-builder.js +++ b/app/utils/nav-builder.js @@ -11,7 +11,7 @@ const mainSettingsPaths = [ paths.account.digitalWallet, paths.account.toggle3ds, paths.account.toggleBillingAddress, - paths.emailNotifications, + paths.account.emailNotifications, paths.toggleMotoMaskCardNumberAndSecurityCode ] diff --git a/app/views/email-notifications/collection-email-mode.njk b/app/views/email-notifications/collection-email-mode.njk index a36f1b5882..99717869e0 100644 --- a/app/views/email-notifications/collection-email-mode.njk +++ b/app/views/email-notifications/collection-email-mode.njk @@ -20,7 +20,7 @@ {% include "includes/settings-read-only.njk" %} {% endif %} -
+ {{ diff --git a/app/views/email-notifications/confirm.njk b/app/views/email-notifications/confirm.njk index 8977fec1ae..9c18a11f51 100644 --- a/app/views/email-notifications/confirm.njk +++ b/app/views/email-notifications/confirm.njk @@ -19,7 +19,7 @@ Confirm email notifications - {{currentService.name}} {{currentGatewayAccount.fu {% include "./email-confirmation-body.njk" %} - + @@ -32,7 +32,7 @@ Confirm email notifications - {{currentService.name}} {{currentGatewayAccount.fu } }) }} -

Cancel

+

Cancel

{% endblock %} diff --git a/app/views/email-notifications/confirmation-email-toggle.njk b/app/views/email-notifications/confirmation-email-toggle.njk index 01e34c1072..c8f959c2bc 100644 --- a/app/views/email-notifications/confirmation-email-toggle.njk +++ b/app/views/email-notifications/confirmation-email-toggle.njk @@ -20,7 +20,7 @@ {% include "includes/settings-read-only.njk" %} {% endif %} -
+
diff --git a/app/views/email-notifications/edit.njk b/app/views/email-notifications/edit.njk index 00d6b5f7a6..8bc13fe1dd 100644 --- a/app/views/email-notifications/edit.njk +++ b/app/views/email-notifications/edit.njk @@ -46,7 +46,7 @@ Change email notifications template - {{currentService.name}} {{currentGatewayAc
  • use redirects or tracking links
  • - + {{ @@ -74,7 +74,7 @@ Change email notifications template - {{currentService.name}} {{currentGatewayAc } }) }} -

    Cancel

    +

    Cancel

    {% endblock %} diff --git a/app/views/email-notifications/index.njk b/app/views/email-notifications/index.njk index 0ed2e4f0ce..c35488e1f4 100644 --- a/app/views/email-notifications/index.njk +++ b/app/views/email-notifications/index.njk @@ -43,13 +43,13 @@
  • - + Refund email
  • {% else %}
  • - + Confirmation email
  • @@ -73,7 +73,7 @@ {% if permissions.email_notification_toggle_update %} {{ govukButton({ - href: routes.emailNotifications.edit, + href: formatAccountPathsFor(routes.account.emailNotifications.edit, currentGatewayAccount.external_id), text: "Add a custom paragraph", attributes: { id: "add-custom-paragraph-link" diff --git a/app/views/email-notifications/off-confirm.njk b/app/views/email-notifications/off-confirm.njk index 162b982219..ee883fa62d 100644 --- a/app/views/email-notifications/off-confirm.njk +++ b/app/views/email-notifications/off-confirm.njk @@ -20,7 +20,7 @@ }) }} -
    + {{ govukButton({ text: 'Turn off email notifications', diff --git a/app/views/email-notifications/refund-email-toggle.njk b/app/views/email-notifications/refund-email-toggle.njk index e6c90f6fd7..4f7ebd02d4 100644 --- a/app/views/email-notifications/refund-email-toggle.njk +++ b/app/views/email-notifications/refund-email-toggle.njk @@ -20,7 +20,7 @@ {% include "includes/settings-read-only.njk" %} {% endif %} - +
    diff --git a/app/views/settings/index.njk b/app/views/settings/index.njk index 643dbf5659..af94e65ef6 100644 --- a/app/views/settings/index.njk +++ b/app/views/settings/index.njk @@ -153,7 +153,7 @@ classes: 'govuk-!-width-one-quarter', items: [ { - href: routes.emailNotifications.collection, + href: formatAccountPathsFor(routes.account.emailNotifications.collection, currentGatewayAccount.external_id), classes: 'govuk-link--no-visited-state email-notifications-toggle-collection', text: 'Change' if permissions.toggle_billing_address_update else 'View', visuallyHiddenText: 'enter an email address settings' @@ -174,7 +174,7 @@ classes: 'govuk-!-width-one-quarter', items: [ { - href: routes.emailNotifications.confirmation, + href: formatAccountPathsFor(routes.account.emailNotifications.confirmation, currentGatewayAccount.external_id), classes: 'govuk-link--no-visited-state email-notifications-toggle-confirmation', text: 'Change' if permissions.toggle_billing_address_update else 'View', visuallyHiddenText: 'payment confirmation emails settings' @@ -195,7 +195,7 @@ classes: 'govuk-!-width-one-quarter', items: [ { - href: routes.emailNotifications.refund, + href: formatAccountPathsFor(routes.account.emailNotifications.refund, currentGatewayAccount.external_id), classes: 'govuk-link--no-visited-state email-notifications-toggle-refund', text: 'Change' if permissions.toggle_billing_address_update else 'View', visuallyHiddenText: 'refund emails settings' @@ -206,7 +206,7 @@ ] }) }} -

    See templates and add a custom paragraph.

    +

    See templates and add a custom paragraph.

    {% if allowMoto %}

    Security

    diff --git a/test/cypress/integration/settings/email-notifications.cy.test.js b/test/cypress/integration/settings/email-notifications.cy.test.js index cc89d162d6..cbcacdde87 100644 --- a/test/cypress/integration/settings/email-notifications.cy.test.js +++ b/test/cypress/integration/settings/email-notifications.cy.test.js @@ -1,10 +1,17 @@ const userStubs = require('../../stubs/user-stubs') const gatewayAccountStubs = require('../../stubs/gateway-account-stubs') -function setupStubs (userExternalId, gatewayAccountId, serviceName, role) { +const settingsUrl = `/settings` +const userExternalId = 'cd0fa54cf3b7408a80ae2f1b93e7c16e' +const gatewayAccountId = 42 +const gatewayAccountExternalId = 'a-valid-external-id' +const serviceName = 'Test Service' + +function setupStubs (role) { cy.task('setupStubs', [ userStubs.getUserSuccess({ userExternalId, gatewayAccountId, serviceName, role }), gatewayAccountStubs.getGatewayAccountSuccess({ gatewayAccountId }), + gatewayAccountStubs.getGatewayAccountByExternalIdSuccess({ gatewayAccountId, gatewayAccountExternalId }), gatewayAccountStubs.getAccountAuthSuccess({ gatewayAccountId }), gatewayAccountStubs.patchConfirmationEmailToggleSuccess({ gatewayAccountId }), gatewayAccountStubs.patchRefundEmailToggleSuccess({ gatewayAccountId }), @@ -13,15 +20,10 @@ function setupStubs (userExternalId, gatewayAccountId, serviceName, role) { } describe('Settings', () => { - const settingsUrl = `/settings` - const userExternalId = 'cd0fa54cf3b7408a80ae2f1b93e7c16e' - const gatewayAccountId = 42 - const serviceName = 'Test Service' - describe('For an admin user', () => { beforeEach(() => { cy.setEncryptedCookies(userExternalId, gatewayAccountId) - setupStubs(userExternalId, gatewayAccountId, serviceName) + setupStubs() cy.visit(settingsUrl) }) @@ -134,7 +136,7 @@ describe('Settings', () => { } ] } - setupStubs(userExternalId, gatewayAccountId, serviceName, role) + setupStubs(role) cy.visit(settingsUrl) })