Skip to content

Commit

Permalink
Merge pull request #2488 from alphagov/PP-7583-move-email-notifications
Browse files Browse the repository at this point in the history
PP-7583 Move email notifications routes
  • Loading branch information
stephencdaly authored Jan 14, 2021
2 parents f689509 + ab10cc2 commit b5cc508
Show file tree
Hide file tree
Showing 13 changed files with 55 additions and 53 deletions.
4 changes: 2 additions & 2 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -72,7 +72,7 @@
"hashed_secret": "ece65afda87c1c6120602c9a3b66890308d7e53c",
"is_secret": false,
"is_verified": false,
"line_number": 62,
"line_number": 74,
"type": "Secret Keyword"
}
],
Expand Down
24 changes: 12 additions & 12 deletions app/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
},
Expand Down Expand Up @@ -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',
Expand Down
30 changes: 15 additions & 15 deletions app/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion app/utils/nav-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const mainSettingsPaths = [
paths.account.digitalWallet,
paths.account.toggle3ds,
paths.account.toggleBillingAddress,
paths.emailNotifications,
paths.account.emailNotifications,
paths.toggleMotoMaskCardNumberAndSecurityCode
]

Expand Down
2 changes: 1 addition & 1 deletion app/views/email-notifications/collection-email-mode.njk
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
{% include "includes/settings-read-only.njk" %}
{% endif %}

<form id="collection-email-form" method="post" action="{{routes.emailNotifications.collection}}">
<form id="collection-email-form" method="post">
<input id="csrf" name="csrfToken" type="hidden" value="{{csrf}}"/>

{{
Expand Down
4 changes: 2 additions & 2 deletions app/views/email-notifications/confirm.njk
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Confirm email notifications - {{currentService.name}} {{currentGatewayAccount.fu
{% include "./email-confirmation-body.njk" %}
</div>

<form method="post" action="{{routes.emailNotifications.update}}">
<form method="post" action="{{ formatAccountPathsFor(routes.account.emailNotifications.update, currentGatewayAccount.external_id) }}">
<input id="csrf" name="csrfToken" type="hidden" value="{{csrf}}"/>
<input type="hidden" value="{{customEmailText}}" name="custom-email-text" class="qa-custom-p" />

Expand All @@ -32,7 +32,7 @@ Confirm email notifications - {{currentService.name}} {{currentGatewayAccount.fu
}
})
}}
<p class="govuk-body"><a class="govuk-link govuk-link--no-visited-state" href="{{routes.emailNotifications.index}}">Cancel</a></p>
<p class="govuk-body"><a class="govuk-link govuk-link--no-visited-state" href="{{ formatAccountPathsFor(routes.account.emailNotifications.index, currentGatewayAccount.external_id) }}">Cancel</a></p>
</form>
</div>
{% endblock %}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
{% include "includes/settings-read-only.njk" %}
{% endif %}

<form id="confirmation-email-form" method="post" action="{{routes.emailNotifications.confirmation}}">
<form id="confirmation-email-form" method="post">
<input id="csrf" name="csrfToken" type="hidden" value="{{csrf}}"/>
<div class="govuk-form-group">
<fieldset class="govuk-fieldset" aria-describedby="email-confirmation-enabled-hint">
Expand Down
4 changes: 2 additions & 2 deletions app/views/email-notifications/edit.njk
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Change email notifications template - {{currentService.name}} {{currentGatewayAc
<li>use redirects or tracking links</li>
</ul>

<form method="post" action="{{routes.emailNotifications.confirm}}" data-validate>
<form method="post" action="{{ formatAccountPathsFor(routes.account.emailNotifications.confirm, currentGatewayAccount.external_id) }}" data-validate>
<input id="csrf" name="csrfToken" type="hidden" value="{{csrf}}"/>

{{
Expand Down Expand Up @@ -74,7 +74,7 @@ Change email notifications template - {{currentService.name}} {{currentGatewayAc
}
})
}}
<p class="govuk-body"><a class="govuk-link govuk-link--no-visited-state" href="{{routes.emailNotifications.index}}">Cancel</a></p>
<p class="govuk-body"><a class="govuk-link govuk-link--no-visited-state" href="{{ formatAccountPathsFor(routes.account.emailNotifications.index, currentGatewayAccount.external_id) }}">Cancel</a></p>
</form>
</div>
{% endblock %}
6 changes: 3 additions & 3 deletions app/views/email-notifications/index.njk
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@
</a>
</li>
<li class="govuk-tabs__list-item">
<a id="refund-tab" class="govuk-tabs__tab govuk-tabs__tab" href="{{ routes.emailNotifications.indexRefundTabEnabled }}">
<a id="refund-tab" class="govuk-tabs__tab govuk-tabs__tab" href="{{ formatAccountPathsFor(routes.account.emailNotifications.indexRefundTabEnabled, currentGatewayAccount.external_id) }}">
Refund email
</a>
</li>
{% else %}
<li class="govuk-tabs__list-item">
<a class="govuk-tabs__tab" href="{{ routes.emailNotifications.index }}">
<a class="govuk-tabs__tab" href="{{ formatAccountPathsFor(routes.account.emailNotifications.index, currentGatewayAccount.external_id) }}">
Confirmation email
</a>
</li>
Expand All @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion app/views/email-notifications/off-confirm.njk
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
})
}}

<form method="post" action="{{routes.emailNotifications.off}}">
<form method="post" action="{{ formatAccountPathsFor(routes.account.emailNotifications.off, currentGatewayAccount.external_id) }}">
<input id="csrf" name="csrfToken" type="hidden" value="{{csrf}}"/>
{{ govukButton({
text: 'Turn off email notifications',
Expand Down
2 changes: 1 addition & 1 deletion app/views/email-notifications/refund-email-toggle.njk
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
{% include "includes/settings-read-only.njk" %}
{% endif %}

<form id="refund-email-form" method="post" action="{{routes.emailNotifications.refund}}">
<form id="refund-email-form" method="post" action="{{ formatAccountPathsFor(routes.account.emailNotifications.refund, currentGatewayAccount.external_id) }}">
<input id="csrf" name="csrfToken" type="hidden" value="{{csrf}}"/>
<div class="govuk-form-group">
<fieldset class="govuk-fieldset" aria-describedby="email-confirmation-enabled-hint">
Expand Down
8 changes: 4 additions & 4 deletions app/views/settings/index.njk
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'
Expand All @@ -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'
Expand All @@ -206,7 +206,7 @@
]
})
}}
<p class="govuk-body"><a class="govuk-link" href="{{routes.emailNotifications.index}}" id="templates-link">See templates and add a custom paragraph.</a></p>
<p class="govuk-body"><a class="govuk-link" href="{{ formatAccountPathsFor(routes.account.emailNotifications.index, currentGatewayAccount.external_id) }}" id="templates-link">See templates and add a custom paragraph.</a></p>

{% if allowMoto %}
<h1 id="moto-mask-security-settings-heading" class="govuk-heading-m govuk-!-margin-top-8">Security</h1>
Expand Down
18 changes: 10 additions & 8 deletions test/cypress/integration/settings/email-notifications.cy.test.js
Original file line number Diff line number Diff line change
@@ -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 }),
Expand All @@ -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)
})
Expand Down Expand Up @@ -134,7 +136,7 @@ describe('Settings', () => {
}
]
}
setupStubs(userExternalId, gatewayAccountId, serviceName, role)
setupStubs(role)

cy.visit(settingsUrl)
})
Expand Down

0 comments on commit b5cc508

Please sign in to comment.