From 2b607978931703e804cc63ed76669535fdeff946 Mon Sep 17 00:00:00 2001 From: Iqbal Ahmed Date: Fri, 15 Jan 2021 17:53:28 +0000 Subject: [PATCH] PP-7583 URL Re-structure > Demo payments with @SandorArpa - Update all 'make a demo payment' and 'prototype' link references to use the new URL structure - Update the 'paths.js' and 'routes.js' to use the new URL structure and middleware. - Use new `/account/` format. - Update all references in template 'njk' files - Update all controllers - Update functional tests. --- .../make-a-demo-payment/edit.controller.js | 2 +- .../go-to-payment.controller.js | 5 +- .../make-a-demo-payment/index.controller.js | 5 +- .../mock-card-details.controller.js | 3 +- .../disable.controller.js | 5 +- .../test-with-your-users/links.controller.js | 7 +- .../test-with-your-users/submit.controller.js | 5 +- app/paths.js | 32 ++++---- app/routes.js | 18 +---- app/views/dashboard/_links.njk | 4 +- .../dashboard/demo-payment/edit-amount.njk | 4 +- .../demo-payment/edit-description.njk | 4 +- app/views/dashboard/demo-payment/index.njk | 6 +- .../demo-payment/mock-card-details.njk | 4 +- app/views/dashboard/demo-service/confirm.njk | 4 +- app/views/dashboard/demo-service/create.njk | 4 +- app/views/dashboard/demo-service/index.njk | 6 +- .../edit.controller.ft.test.js | 26 +++++-- .../go-to-payment.controller.ft.test.js | 50 +++++++++---- .../index.controller.ft.test.js | 48 +++++++----- .../mock-card-details.controller.ft.test.js | 48 ++++++------ .../create.controller.ft.test.js | 24 ++++-- .../disable.controller.ft.test.js | 27 +++++-- .../links.controller.ft.test.js | 42 ++++++----- .../submit.controller.ft.test.js | 73 ++++++++++--------- 25 files changed, 263 insertions(+), 193 deletions(-) diff --git a/app/controllers/make-a-demo-payment/edit.controller.js b/app/controllers/make-a-demo-payment/edit.controller.js index 9d13ea32ab..63e483a4ee 100644 --- a/app/controllers/make-a-demo-payment/edit.controller.js +++ b/app/controllers/make-a-demo-payment/edit.controller.js @@ -3,7 +3,7 @@ const lodash = require('lodash') const { response } = require('../../utils/response.js') -const { editDescription } = require('../../paths').prototyping.demoPayment +const { editDescription } = require('../../paths').account.prototyping.demoPayment module.exports = (req, res) => { const pageData = lodash.get(req, 'session.pageData.makeADemoPayment', {}) diff --git a/app/controllers/make-a-demo-payment/go-to-payment.controller.js b/app/controllers/make-a-demo-payment/go-to-payment.controller.js index 5ec17421b2..7f9a3ea155 100644 --- a/app/controllers/make-a-demo-payment/go-to-payment.controller.js +++ b/app/controllers/make-a-demo-payment/go-to-payment.controller.js @@ -7,13 +7,14 @@ const paths = require('../../paths') const productsClient = require('../../services/clients/products.client.js') const productTypes = require('../../utils/product-types') const publicAuthClient = require('../../services/clients/public-auth.client') +const formatAccountPathsFor = require('../../utils/format-account-paths-for') module.exports = async function makeDemoPayment (req, res) { const gatewayAccountId = req.account.gateway_account_id const { paymentAmount, paymentDescription } = lodash.get(req, 'session.pageData.makeADemoPayment', {}) if (!paymentAmount || !paymentDescription) { - return res.redirect(paths.prototyping.demoPayment.index) + return res.redirect(formatAccountPathsFor(paths.account.prototyping.demoPayment.index, req.account.external_id)) } try { @@ -40,6 +41,6 @@ module.exports = async function makeDemoPayment (req, res) { } catch (error) { logger.error(`[requestId=${req.correlationId}] Making a demo payment failed - ${error.message}`) req.flash('genericError', 'Something went wrong. Please try again.') - res.redirect(paths.prototyping.demoPayment.index) + res.redirect(formatAccountPathsFor(paths.account.prototyping.demoPayment.index, req.account.external_id)) } } diff --git a/app/controllers/make-a-demo-payment/index.controller.js b/app/controllers/make-a-demo-payment/index.controller.js index 445c4cd9f5..22fdb945a7 100644 --- a/app/controllers/make-a-demo-payment/index.controller.js +++ b/app/controllers/make-a-demo-payment/index.controller.js @@ -6,6 +6,7 @@ const { response } = require('../../utils/response.js') const paths = require('../../paths') const { isCurrency, isAboveMaxAmount } = require('../../browsered/field-validation-checks') const { safeConvertPoundsStringToPence } = require('../../utils/currency-formatter') +const formatAccountPathsFor = require('../../utils/format-account-paths-for') const DEFAULTS = { paymentDescription: 'An example payment description', @@ -20,13 +21,13 @@ module.exports = (req, res) => { if (!paymentAmount || isCurrency(paymentAmount)) { lodash.set(req, 'session.pageData.makeADemoPayment.paymentAmount', paymentAmount) req.flash('genericError', isCurrency(paymentAmount)) - return res.redirect(paths.prototyping.demoPayment.editAmount) + return res.redirect(formatAccountPathsFor(paths.account.prototyping.demoPayment.editAmount, req.account.external_id)) } const isAboveMaxAmountError = isAboveMaxAmount(paymentAmount) if (isAboveMaxAmountError) { lodash.set(req, 'session.pageData.makeADemoPayment.paymentAmount', paymentAmount) req.flash('genericError', isAboveMaxAmountError) - return res.redirect(paths.prototyping.demoPayment.editAmount) + return res.redirect(formatAccountPathsFor(paths.account.prototyping.demoPayment.editAmount, req.account.external_id)) } if (req.body['payment-amount']) { diff --git a/app/controllers/make-a-demo-payment/mock-card-details.controller.js b/app/controllers/make-a-demo-payment/mock-card-details.controller.js index d1fae4a82e..9d2821caad 100644 --- a/app/controllers/make-a-demo-payment/mock-card-details.controller.js +++ b/app/controllers/make-a-demo-payment/mock-card-details.controller.js @@ -4,12 +4,13 @@ const lodash = require('lodash') const { response } = require('../../utils/response.js') const paths = require('../../paths') +const formatAccountPathsFor = require('../../utils/format-account-paths-for') module.exports = (req, res) => { const { paymentAmount, paymentDescription } = lodash.get(req, 'session.pageData.makeADemoPayment', {}) if (!paymentAmount || !paymentDescription) { - return res.redirect(paths.prototyping.demoPayment.index) + return res.redirect(formatAccountPathsFor(paths.account.prototyping.demoPayment.index, req.account.external_id)) } response(req, res, 'dashboard/demo-payment/mock-card-details', {}) diff --git a/app/controllers/test-with-your-users/disable.controller.js b/app/controllers/test-with-your-users/disable.controller.js index 8cfc774f31..c23c83a085 100644 --- a/app/controllers/test-with-your-users/disable.controller.js +++ b/app/controllers/test-with-your-users/disable.controller.js @@ -3,17 +3,18 @@ const logger = require('../../utils/logger')(__filename) const paths = require('../../paths') const productsClient = require('../../services/clients/products.client.js') +const formatAccountPathsFor = require('../../utils/format-account-paths-for') module.exports = (req, res) => { const gatewayAccountId = req.account.gateway_account_id productsClient.product.disable(gatewayAccountId, req.params.productExternalId) .then(() => { req.flash('generic', 'Prototype link deleted') - res.redirect(paths.prototyping.demoService.links) + res.redirect(formatAccountPathsFor(paths.account.prototyping.demoService.links, req.account.external_id)) }) .catch((err) => { logger.error(`[requestId=${req.correlationId}] Disable product failed - ${err.message}`) req.flash('genericError', 'Something went wrong when deleting the prototype link. Please try again or contact support.') - res.redirect(paths.prototyping.demoService.links) + res.redirect(formatAccountPathsFor(paths.account.prototyping.demoService.links, req.account.external_id)) }) } diff --git a/app/controllers/test-with-your-users/links.controller.js b/app/controllers/test-with-your-users/links.controller.js index 3a124f02e8..b1ed3b379a 100644 --- a/app/controllers/test-with-your-users/links.controller.js +++ b/app/controllers/test-with-your-users/links.controller.js @@ -5,13 +5,14 @@ const { response } = require('../../utils/response.js') const paths = require('../../paths') const productsClient = require('../../services/clients/products.client.js') const { renderErrorView } = require('../../utils/response.js') +const formatAccountPathsFor = require('../../../app/utils/format-account-paths-for') module.exports = (req, res) => { const params = { productsTab: true, - createPage: paths.prototyping.demoService.create, - indexPage: paths.prototyping.demoService.index, - linksPage: paths.prototyping.demoService.links + createPage: formatAccountPathsFor(paths.account.prototyping.demoService.create, req.account.external_id), + indexPage: formatAccountPathsFor(paths.account.prototyping.demoService.index, req.account.external_id), + linksPage: formatAccountPathsFor(paths.account.prototyping.demoService.links, req.account.external_id) } productsClient.product.getByGatewayAccountId(req.account.gateway_account_id) diff --git a/app/controllers/test-with-your-users/submit.controller.js b/app/controllers/test-with-your-users/submit.controller.js index 802b46db7a..e72cad2cfc 100644 --- a/app/controllers/test-with-your-users/submit.controller.js +++ b/app/controllers/test-with-your-users/submit.controller.js @@ -10,6 +10,7 @@ const productTypes = require('../../utils/product-types') const publicAuthClient = require('../../services/clients/public-auth.client') const { isCurrency, isHttps, isAboveMaxAmount } = require('../../browsered/field-validation-checks') const { penceToPounds, safeConvertPoundsStringToPence } = require('../../utils/currency-formatter') +const formatAccountPathsFor = require('../../utils/format-account-paths-for') module.exports = async (req, res) => { const gatewayAccountId = req.account.gateway_account_id @@ -29,7 +30,7 @@ module.exports = async (req, res) => { } if (lodash.get(req, 'session.flash.genericError.length')) { - return res.redirect(paths.prototyping.demoService.create) + return res.redirect(formatAccountPathsFor(paths.account.prototyping.demoService.create, req.account.external_id)) } try { @@ -59,6 +60,6 @@ module.exports = async (req, res) => { } catch (err) { logger.error(`[requestId=${req.correlationId}] Create product failed - ${err.message}`) req.flash('genericError', 'Something went wrong. Please try again or contact support.') - return res.redirect(paths.prototyping.demoService.create) + return res.redirect(formatAccountPathsFor(paths.account.prototyping.demoService.create, req.account.external_id)) } } diff --git a/app/paths.js b/app/paths.js index 6b624dee12..a2d3a6bc92 100644 --- a/app/paths.js +++ b/app/paths.js @@ -31,6 +31,22 @@ module.exports = { paymentTypes: { index: '/payment-types' }, + prototyping: { + demoService: { + index: '/test-with-your-users', + links: '/test-with-your-users/links', + create: '/test-with-your-users/create', + confirm: '/test-with-your-users/confirm', + disable: '/test-with-your-users/links/disable/:productExternalId' + }, + demoPayment: { + index: '/make-a-demo-payment', + editDescription: '/make-a-demo-payment/edit-description', + editAmount: '/make-a-demo-payment/edit-amount', + mockCardDetails: '/make-a-demo-payment/mock-card-numbers', + goToPaymentScreens: '/make-a-demo-payment/go-to-payment' + } + }, settings: { index: '/settings' }, @@ -145,22 +161,6 @@ module.exports = { staticPaths: { naxsiError: '/request-denied' }, - prototyping: { - demoService: { - index: '/test-with-your-users', - links: '/test-with-your-users/links', - create: '/test-with-your-users/create', - confirm: '/test-with-your-users/confirm', - disable: '/test-with-your-users/links/disable/:productExternalId' - }, - demoPayment: { - index: '/make-a-demo-payment', - editDescription: '/make-a-demo-payment/edit-description', - editAmount: '/make-a-demo-payment/edit-amount', - mockCardDetails: '/make-a-demo-payment/mock-card-numbers', - goToPaymentScreens: '/make-a-demo-payment/go-to-payment' - } - }, paymentLinks: { start: '/create-payment-link', information: '/create-payment-link/information', diff --git a/app/routes.js b/app/routes.js index b8fcf8c4a4..9e2bcbeb4b 100644 --- a/app/routes.js +++ b/app/routes.js @@ -88,7 +88,7 @@ const stripeSetupDashboardRedirectController = require('./controllers/stripe-set const { healthcheck, registerUser, user, dashboard, selfCreateService, transactions, credentials, serviceSwitcher, teamMembers, staticPaths, inviteValidation, editServiceName, merchantDetails, - notificationCredentials, prototyping, paymentLinks, + notificationCredentials, paymentLinks, requestToGoLive, policyPages, stripeSetup, stripe, yourPsp, allServiceTransactions, payouts } = paths @@ -97,6 +97,7 @@ const { digitalWallet, emailNotifications, paymentTypes, + prototyping, settings, toggle3ds, toggleBillingAddress, @@ -185,8 +186,6 @@ module.exports.bind = function (app) { ...lodash.values(serviceSwitcher), ...lodash.values(teamMembers), ...lodash.values(merchantDetails), - ...lodash.values(prototyping.demoPayment), - ...lodash.values(prototyping.demoService), ...lodash.values(paymentLinks), ...lodash.values(user.profile), ...lodash.values(requestToGoLive), @@ -357,19 +356,6 @@ module.exports.bind = function (app) { account.post(toggleBillingAddress.index, permission('toggle-billing-address:update'), toggleBillingAddressController.postIndex) // Prototype links - app.get(prototyping.demoService.index, permission('transactions:read'), resolveService, getAccount, restrictToSandbox, testWithYourUsersController.index) - app.get(prototyping.demoService.links, permission('transactions:read'), resolveService, getAccount, restrictToSandbox, testWithYourUsersController.links) - app.get(prototyping.demoService.create, permission('transactions:read'), resolveService, getAccount, restrictToSandbox, testWithYourUsersController.create) - app.post(prototyping.demoService.confirm, permission('transactions:read'), resolveService, getAccount, restrictToSandbox, testWithYourUsersController.submit) - app.get(prototyping.demoService.disable, permission('transactions:read'), resolveService, getAccount, restrictToSandbox, testWithYourUsersController.disable) - - app.get(prototyping.demoPayment.index, permission('transactions:read'), getAccount, restrictToSandbox, makeADemoPaymentController.index) - app.post(prototyping.demoPayment.index, permission('transactions:read'), getAccount, restrictToSandbox, makeADemoPaymentController.index) - app.get(prototyping.demoPayment.editDescription, permission('transactions:read'), getAccount, restrictToSandbox, makeADemoPaymentController.edit) - app.get(prototyping.demoPayment.editAmount, permission('transactions:read'), getAccount, restrictToSandbox, makeADemoPaymentController.edit) - app.get(prototyping.demoPayment.mockCardDetails, permission('transactions:read'), getAccount, restrictToSandbox, makeADemoPaymentController.mockCardDetails) - app.post(prototyping.demoPayment.goToPaymentScreens, permission('transactions:read'), getAccount, restrictToSandbox, makeADemoPaymentController.goToPayment) - account.get(prototyping.demoService.index, permission('transactions:read'), restrictToSandbox, testWithYourUsersController.index) account.get(prototyping.demoService.links, permission('transactions:read'), restrictToSandbox, testWithYourUsersController.links) account.get(prototyping.demoService.create, permission('transactions:read'), restrictToSandbox, testWithYourUsersController.create) diff --git a/app/views/dashboard/_links.njk b/app/views/dashboard/_links.njk index 1dcdb9b03a..548b14ead8 100644 --- a/app/views/dashboard/_links.njk +++ b/app/views/dashboard/_links.njk @@ -9,7 +9,7 @@
{% if links.demoPayment in linksToDisplay %}