Skip to content

Commit

Permalink
Merge pull request #2489 from alphagov/PP-7583-move-mask-card-details
Browse files Browse the repository at this point in the history
PP-7583 Move mask card details settings routes
  • Loading branch information
stephencdaly authored Jan 14, 2021
2 parents b5cc508 + e5dd3c7 commit bfd8562
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 22 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-14T15:18:01Z",
"generated_at": "2021-01-14T16:22:27Z",
"plugins_used": [
{
"name": "AWSKeyDetector"
Expand Down Expand Up @@ -72,7 +72,7 @@
"hashed_secret": "ece65afda87c1c6120602c9a3b66890308d7e53c",
"is_secret": false,
"is_verified": false,
"line_number": 74,
"line_number": 78,
"type": "Secret Keyword"
}
],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict'

const paths = require('../../paths')
const formatAccountPathsFor = require('../../utils/format-account-paths-for')
const { renderErrorView } = require('../../utils/response')
const { ConnectorClient } = require('../../services/clients/connector.client')
const { correlationHeader } = require('../../utils/correlation-header')
Expand All @@ -11,12 +12,13 @@ module.exports = async function toggleMaskCardNumber (req, res) {
const correlationId = req.headers[correlationHeader] || ''
const accountId = req.account.gateway_account_id
const enableMaskCardNumber = req.body['moto-mask-card-number-input-toggle'] === 'on'
const formattedPath = formatAccountPathsFor(paths.account.toggleMotoMaskCardNumberAndSecurityCode.cardNumber, req.account && req.account.external_id)

try {
await connector.toggleMotoMaskCardNumberInput(accountId, enableMaskCardNumber, correlationId)

req.flash('generic', 'Your changes have saved')
return res.redirect(paths.toggleMotoMaskCardNumberAndSecurityCode.cardNumber)
return res.redirect(formattedPath)
} catch (error) {
return renderErrorView(req, res, false, error.errorCode)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const paths = require('../../paths')

const formatAccountPathsFor = require('../../utils/format-account-paths-for')
const { renderErrorView } = require('../../utils/response')
const { ConnectorClient } = require('../../services/clients/connector.client')
const { correlationHeader } = require('../../utils/correlation-header')
Expand All @@ -12,12 +12,13 @@ module.exports = async function toggleMaskCardSecurityCode (req, res) {
const correlationId = req.headers[correlationHeader] || ''
const accountId = req.account.gateway_account_id
const enableMaskSecurityCode = req.body['moto-mask-security-code-input-toggle'] === 'on'
const formattedPath = formatAccountPathsFor(paths.account.toggleMotoMaskCardNumberAndSecurityCode.securityCode, req.account && req.account.external_id)

try {
await connector.toggleMotoMaskSecurityCodeInput(accountId, enableMaskSecurityCode, correlationId)

req.flash('generic', 'Your changes have saved')
return res.redirect(paths.toggleMotoMaskCardNumberAndSecurityCode.securityCode)
return res.redirect(formattedPath)
} catch (error) {
return renderErrorView(req, res, false, error.errorCode)
}
Expand Down
8 changes: 4 additions & 4 deletions app/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ module.exports = {
},
toggleBillingAddress: {
index: '/billing-address'
},
toggleMotoMaskCardNumberAndSecurityCode: {
cardNumber: '/moto-hide-card-number',
securityCode: '/moto-hide-security-code'
}
},
transactions: {
Expand Down Expand Up @@ -132,10 +136,6 @@ module.exports = {
logUserIn: '/create-service/proceed-to-login',
serviceNaming: '/service/set-name'
},
toggleMotoMaskCardNumberAndSecurityCode: {
cardNumber: '/moto-hide-card-number',
securityCode: '/moto-hide-security-code'
},
healthcheck: {
path: '/healthcheck'
},
Expand Down
14 changes: 7 additions & 7 deletions app/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ const stripeSetupDashboardRedirectController = require('./controllers/stripe-set
const {
healthcheck, registerUser, user, dashboard, selfCreateService, transactions, credentials,
apiKeys, serviceSwitcher, teamMembers, staticPaths, inviteValidation, editServiceName, merchantDetails,
notificationCredentials, toggleMotoMaskCardNumberAndSecurityCode, prototyping, paymentLinks,
notificationCredentials, prototyping, paymentLinks,
requestToGoLive, policyPages, stripeSetup, stripe,
settings, yourPsp, allServiceTransactions, payouts
} = paths
Expand All @@ -97,7 +97,8 @@ const {
emailNotifications,
paymentTypes,
toggle3ds,
toggleBillingAddress
toggleBillingAddress,
toggleMotoMaskCardNumberAndSecurityCode
} = paths.account

// Exports
Expand Down Expand Up @@ -193,7 +194,6 @@ module.exports.bind = function (app) {
...lodash.values(settings),
...lodash.values(yourPsp),
...lodash.values(payouts),
...lodash.values(toggleMotoMaskCardNumberAndSecurityCode),
paths.feedback
] // Extract all the authenticated paths as a single array

Expand Down Expand Up @@ -294,10 +294,10 @@ module.exports.bind = function (app) {
account.post(toggle3ds.index, permission('toggle-3ds:update'), paymentMethodIsCard, toggle3dsController.post)

// MOTO MASK CARD NUMBER & SECURITY CODE TOGGLE
app.get(toggleMotoMaskCardNumberAndSecurityCode.cardNumber, permission('moto-mask-input:read'), getAccount, paymentMethodIsCard, toggleMotoMaskCardNumber.get)
app.post(toggleMotoMaskCardNumberAndSecurityCode.cardNumber, permission('moto-mask-input:update'), getAccount, paymentMethodIsCard, toggleMotoMaskCardNumber.post)
app.get(toggleMotoMaskCardNumberAndSecurityCode.securityCode, permission('moto-mask-input:read'), getAccount, paymentMethodIsCard, toggleMotoMaskSecurityCode.get)
app.post(toggleMotoMaskCardNumberAndSecurityCode.securityCode, permission('moto-mask-input:update'), getAccount, paymentMethodIsCard, toggleMotoMaskSecurityCode.post)
account.get(toggleMotoMaskCardNumberAndSecurityCode.cardNumber, permission('moto-mask-input:read'), paymentMethodIsCard, toggleMotoMaskCardNumber.get)
account.post(toggleMotoMaskCardNumberAndSecurityCode.cardNumber, permission('moto-mask-input:update'), paymentMethodIsCard, toggleMotoMaskCardNumber.post)
account.get(toggleMotoMaskCardNumberAndSecurityCode.securityCode, permission('moto-mask-input:read'), paymentMethodIsCard, toggleMotoMaskSecurityCode.get)
account.post(toggleMotoMaskCardNumberAndSecurityCode.securityCode, permission('moto-mask-input:update'), paymentMethodIsCard, toggleMotoMaskSecurityCode.post)

account.get(toggleBillingAddress.index, permission('toggle-billing-address:read'), toggleBillingAddressController.getIndex)
account.post(toggleBillingAddress.index, permission('toggle-billing-address:update'), toggleBillingAddressController.postIndex)
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 @@ -12,7 +12,7 @@ const mainSettingsPaths = [
paths.account.toggle3ds,
paths.account.toggleBillingAddress,
paths.account.emailNotifications,
paths.toggleMotoMaskCardNumberAndSecurityCode
paths.account.toggleMotoMaskCardNumberAndSecurityCode
]

const yourPspPaths = [
Expand Down
4 changes: 2 additions & 2 deletions app/views/settings/index.njk
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@
classes: 'govuk-!-width-one-quarter',
items: [
{
href: routes.toggleMotoMaskCardNumberAndSecurityCode.cardNumber,
href: formatAccountPathsFor(routes.account.toggleMotoMaskCardNumberAndSecurityCode.cardNumber, currentGatewayAccount.external_id),
classes: 'govuk-link--no-visited-state',
text: 'Change' if permissions.moto_mask_input_update else 'View',
visuallyHiddenText: 'Moto Secure settings'
Expand All @@ -250,7 +250,7 @@
classes: 'govuk-!-width-one-quarter',
items: [
{
href: routes.toggleMotoMaskCardNumberAndSecurityCode.securityCode,
href: formatAccountPathsFor(routes.account.toggleMotoMaskCardNumberAndSecurityCode.securityCode, currentGatewayAccount.external_id),
classes: 'govuk-link--no-visited-state',
text: 'Change' if permissions.moto_mask_input_update else 'View',
visuallyHiddenText: 'Moto Secure settings'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const gatewayAccountStubs = require('../../stubs/gateway-account-stubs')
describe('MOTO mask security section', () => {
const userExternalId = 'cd0fa54cf3b7408a80ae2f1b93e7c16e'
const gatewayAccountId = 42
const gatewayAccountExternalId = 'a-valid-external-id'
const serviceName = 'Purchase a positron projection permit'

function setupMotoStubs (opts = {}) {
Expand All @@ -30,10 +31,24 @@ describe('MOTO mask security section', () => {
user = userStubs.getUserSuccess({ userExternalId, gatewayAccountId, serviceName })
}

const gatewayAccount = gatewayAccountStubs.getGatewayAccountSuccess({ gatewayAccountId, paymentProvider: opts.gateway, allowMoto: opts.allowMoto, motoMaskCardNumber: opts.motoMaskCardNumber, motoMaskSecurityCode: opts.motoMaskSecurityCode })
const gatewayAccount = gatewayAccountStubs.getGatewayAccountSuccess({
gatewayAccountId,
paymentProvider: opts.gateway,
allowMoto: opts.allowMoto,
motoMaskCardNumber: opts.motoMaskCardNumber,
motoMaskSecurityCode: opts.motoMaskSecurityCode
})
const gatewayAccountByExternalId = gatewayAccountStubs.getGatewayAccountByExternalIdSuccess({
gatewayAccountId,
gatewayAccountExternalId,
paymentProvider: opts.gateway,
allowMoto: opts.allowMoto,
motoMaskCardNumber: opts.motoMaskCardNumber,
motoMaskSecurityCode: opts.motoMaskSecurityCode
})
const card = gatewayAccountStubs.getAcceptedCardTypesSuccess({ gatewayAccountId, updated: false, maestro: opts.maestro })

stubs.push(user, gatewayAccount, card)
stubs.push(user, gatewayAccount, gatewayAccountByExternalId, card)

cy.task('setupStubs', stubs)
}
Expand Down Expand Up @@ -99,7 +114,7 @@ describe('MOTO mask security section', () => {
setupMotoStubs({ readonly: false, allowMoto: true, motoMaskCardNumber: true })
})

it(`should show 'save chanegs' notification`, () => {
it(`should show 'save changes' notification`, () => {
cy.get('input[value="on"]').click()
cy.get('#save-moto-mask-changes').click()
cy.get('input[value="on"]').should('be.checked')
Expand Down

0 comments on commit bfd8562

Please sign in to comment.