From f95871aa4a2b19d2c62389677a47639f7be8e71b Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 19 Jan 2021 13:26:17 +0000 Subject: [PATCH 1/2] PP-7583: move stripe setup pages over to account URL structure Update both the controllers for the pages and the redirect utility that pieces all of the stripe setup steps togher. Move the live dashboard redirect that is given to services when they've gone live (by support) out of the nested account paths as it belongs to the service. Once the account URL structure is in place, this can likely be removed and replaced with a simple link to the new live account that's been created. --- .../add-psp-account-details/get.controller.js | 10 ++-- .../get.controller.test.js | 9 ++-- .../bank-details/post.controller.js | 3 +- .../bank-details/post.controller.test.js | 5 +- .../company-number/post.controller.js | 3 +- .../responsible-person/post.controller.js | 3 +- .../post.controller.test.js | 7 +-- .../vat-number/post.controller.js | 3 +- app/paths.js | 52 +++++++++++++++---- app/routes.js | 20 +++---- .../_stripe-account-setup-banner.njk | 2 +- test/integration/add-psp-details.ft.test.js | 3 +- 12 files changed, 77 insertions(+), 43 deletions(-) diff --git a/app/controllers/stripe-setup/add-psp-account-details/get.controller.js b/app/controllers/stripe-setup/add-psp-account-details/get.controller.js index b14da84aad..029eb8d2f8 100644 --- a/app/controllers/stripe-setup/add-psp-account-details/get.controller.js +++ b/app/controllers/stripe-setup/add-psp-account-details/get.controller.js @@ -1,6 +1,7 @@ 'use strict' const paths = require('../../../paths') +const formatAccountPathsFor = require('../../../utils/format-account-paths-for') const { response, renderErrorView } = require('../../../utils/response') module.exports = async (req, res) => { @@ -9,15 +10,16 @@ module.exports = async (req, res) => { } const stripeAccountSetup = req.account.connectorGatewayAccountStripeProgress + const accountExternalId = req.account.external_id if (!stripeAccountSetup.bankAccount) { - res.redirect(303, paths.stripeSetup.bankDetails) + res.redirect(303, formatAccountPathsFor(paths.account.stripeSetup.bankDetails, accountExternalId)) } else if (!stripeAccountSetup.responsiblePerson) { - res.redirect(303, paths.stripeSetup.responsiblePerson) + res.redirect(303, formatAccountPathsFor(paths.account.stripeSetup.responsiblePerson, accountExternalId)) } else if (!stripeAccountSetup.vatNumber) { - res.redirect(303, paths.stripeSetup.vatNumber) + res.redirect(303, formatAccountPathsFor(paths.account.stripeSetup.vatNumber, accountExternalId)) } else if (!stripeAccountSetup.companyNumber) { - res.redirect(303, paths.stripeSetup.companyNumber) + res.redirect(303, formatAccountPathsFor(paths.account.stripeSetup.companyNumber, accountExternalId)) } else { response(req, res, 'stripe-setup/go-live-complete') } diff --git a/app/controllers/stripe-setup/add-psp-account-details/get.controller.test.js b/app/controllers/stripe-setup/add-psp-account-details/get.controller.test.js index 0adadb1c96..026e4c69d6 100644 --- a/app/controllers/stripe-setup/add-psp-account-details/get.controller.test.js +++ b/app/controllers/stripe-setup/add-psp-account-details/get.controller.test.js @@ -19,6 +19,7 @@ describe('get controller', () => { req = { account: { gateway_account_id: 'gatewayId', + external_id: 'a-valid-external-id', connectorGatewayAccountStripeProgress: {} }, correlationId: 'requestId' @@ -34,13 +35,13 @@ describe('get controller', () => { it('should redirect to bank account setup page', async () => { req.account.connectorGatewayAccountStripeProgress.bankAccount = false getController(req, res) - sinon.assert.calledWith(res.redirect, 303, paths.stripeSetup.bankDetails) + sinon.assert.calledWith(res.redirect, 303, `/account/a-valid-external-id/${paths.account.stripeSetup.bankDetails}`) }) it('should redirect to responsible person page', async () => { req.account.connectorGatewayAccountStripeProgress.bankAccount = true getController(req, res) - sinon.assert.calledWith(res.redirect, 303, paths.stripeSetup.responsiblePerson) + sinon.assert.calledWith(res.redirect, 303, `/account/a-valid-external-id/${paths.account.stripeSetup.responsiblePerson}`) }) it('should redirect to VAT number page', async () => { @@ -49,7 +50,7 @@ describe('get controller', () => { responsiblePerson: true } getController(req, res) - sinon.assert.calledWith(res.redirect, 303, paths.stripeSetup.vatNumber) + sinon.assert.calledWith(res.redirect, 303, `/account/a-valid-external-id/${paths.account.stripeSetup.vatNumber}`) }) it('should redirect to company registration number page', async () => { @@ -59,7 +60,7 @@ describe('get controller', () => { vatNumber: true } getController(req, res) - sinon.assert.calledWith(res.redirect, 303, paths.stripeSetup.companyNumber) + sinon.assert.calledWith(res.redirect, 303, `/account/a-valid-external-id/${paths.account.stripeSetup.companyNumber}`) }) it('should render go live complete page when all steps are completed', async () => { diff --git a/app/controllers/stripe-setup/bank-details/post.controller.js b/app/controllers/stripe-setup/bank-details/post.controller.js index 1387abf8fc..147c2b5489 100644 --- a/app/controllers/stripe-setup/bank-details/post.controller.js +++ b/app/controllers/stripe-setup/bank-details/post.controller.js @@ -9,6 +9,7 @@ const { updateBankAccount } = require('../../../services/clients/stripe/stripe.c const { ConnectorClient } = require('../../../services/clients/connector.client') const connector = new ConnectorClient(process.env.CONNECTOR_URL) const paths = require('../../../paths') +const formatAccountPathsFor = require('../../../utils/format-account-paths-for') const fieldValidationChecks = require('../../../browsered/field-validation-checks') // Constants @@ -38,7 +39,7 @@ module.exports = (req, res) => { return connector.setStripeAccountSetupFlag(req.account.gateway_account_id, 'bank_account', req.correlationId) }) .then(() => { - return res.redirect(303, paths.stripe.addPspAccountDetails) + return res.redirect(303, formatAccountPathsFor(paths.account.stripe.addPspAccountDetails, req.account && req.account.external_id)) }) .catch(error => { // check if it is Stripe related error diff --git a/app/controllers/stripe-setup/bank-details/post.controller.test.js b/app/controllers/stripe-setup/bank-details/post.controller.test.js index 91b6cc2d19..9d7d3689bf 100644 --- a/app/controllers/stripe-setup/bank-details/post.controller.test.js +++ b/app/controllers/stripe-setup/bank-details/post.controller.test.js @@ -19,7 +19,8 @@ describe('Bank details post controller', () => { req = { correlationId: 'correlation-id', account: { - gateway_account_id: '1' + gateway_account_id: '1', + external_id: 'a-valid-external-id' }, body: { 'account-number': rawAccountNumber, @@ -52,7 +53,7 @@ describe('Bank details post controller', () => { bank_account_number: sanitisedAccountNumber }) sinon.assert.calledWith(setStripeAccountSetupFlagMock, req.account.gateway_account_id, 'bank_account', req.correlationId) - sinon.assert.calledWith(res.redirect, 303, paths.stripe.addPspAccountDetails) + sinon.assert.calledWith(res.redirect, 303, `/account/a-valid-external-id/${paths.account.stripe.addPspAccountDetails}`) }) it('should render error page when Stripe returns unknown error', async () => { diff --git a/app/controllers/stripe-setup/company-number/post.controller.js b/app/controllers/stripe-setup/company-number/post.controller.js index 7f43670e6c..d810593d90 100644 --- a/app/controllers/stripe-setup/company-number/post.controller.js +++ b/app/controllers/stripe-setup/company-number/post.controller.js @@ -9,6 +9,7 @@ const companyNumberValidations = require('./company-number-validations') const { ConnectorClient } = require('../../../services/clients/connector.client') const connector = new ConnectorClient(process.env.CONNECTOR_URL) const paths = require('../../../paths') +const formatAccountPathsFor = require('../../../utils/format-account-paths-for') // Constants const COMPANY_NUMBER_DECLARATION_FIELD = 'company-number-declaration' @@ -34,7 +35,7 @@ module.exports = async (req, res) => { await updateCompany(res.locals.stripeAccount.stripeAccountId, stripeCompanyBody) await connector.setStripeAccountSetupFlag(req.account.gateway_account_id, 'company_number', req.correlationId) - return res.redirect(303, paths.stripe.addPspAccountDetails) + return res.redirect(303, formatAccountPathsFor(paths.account.stripe.addPspAccountDetails, req.account && req.account.external_id)) } catch (error) { logger.error(`[${req.correlationId}] Error submitting "Company registration number" details, error = `, error) return renderErrorView(req, res, 'Please try again or contact support team') diff --git a/app/controllers/stripe-setup/responsible-person/post.controller.js b/app/controllers/stripe-setup/responsible-person/post.controller.js index 5748d41b9d..e77238ba00 100644 --- a/app/controllers/stripe-setup/responsible-person/post.controller.js +++ b/app/controllers/stripe-setup/responsible-person/post.controller.js @@ -4,6 +4,7 @@ const lodash = require('lodash') const ukPostcode = require('uk-postcode') const paths = require('../../../paths') +const formatAccountPathsFor = require('../../../utils/format-account-paths-for') const logger = require('../../../utils/logger')(__filename) const { response, renderErrorView } = require('../../../utils/response') const { @@ -110,7 +111,7 @@ module.exports = async function (req, res) { await updatePerson(stripeAccountId, person.id, buildStripePerson(formFields)) await connector.setStripeAccountSetupFlag(req.account.gateway_account_id, 'responsible_person', req.correlationId) - return res.redirect(303, paths.stripe.addPspAccountDetails) + return res.redirect(303, formatAccountPathsFor(paths.account.stripe.addPspAccountDetails, req.account && req.account.external_id)) } catch (error) { logger.error(`[requestId=${req.correlationId}] Error creating responsible person with Stripe - ${error.message}`) return renderErrorView(req, res, 'Please try again or contact support team') diff --git a/app/controllers/stripe-setup/responsible-person/post.controller.test.js b/app/controllers/stripe-setup/responsible-person/post.controller.test.js index 27c3ba106e..1931c97dc2 100644 --- a/app/controllers/stripe-setup/responsible-person/post.controller.test.js +++ b/app/controllers/stripe-setup/responsible-person/post.controller.test.js @@ -64,7 +64,8 @@ describe('Responsible person POST controller', () => { req = { correlationId: 'correlation-id', account: { - gateway_account_id: '1' + gateway_account_id: '1', + external_id: 'a-valid-external-id' } } res = { @@ -108,7 +109,7 @@ describe('Responsible person POST controller', () => { dob_year: dobYearNormalised }) sinon.assert.calledWith(setStripeAccountSetupFlagMock, req.account.gateway_account_id, 'responsible_person', req.correlationId) - sinon.assert.calledWith(res.redirect, 303, paths.stripe.addPspAccountDetails) + sinon.assert.calledWith(res.redirect, 303, `/account/a-valid-external-id/${paths.account.stripe.addPspAccountDetails}`) }) it('should call Stripe with normalised details (no second address line), then connector, then redirect to add details redirect route', async function () { @@ -137,7 +138,7 @@ describe('Responsible person POST controller', () => { dob_year: dobYearNormalised }) sinon.assert.calledWith(setStripeAccountSetupFlagMock, req.account.gateway_account_id, 'responsible_person', req.correlationId) - sinon.assert.calledWith(res.redirect, 303, paths.stripe.addPspAccountDetails) + sinon.assert.calledWith(res.redirect, 303, `/account/a-valid-external-id/${paths.account.stripe.addPspAccountDetails}`) }) it('should render error when Stripe returns error, not call connector, and not redirect', async function () { diff --git a/app/controllers/stripe-setup/vat-number/post.controller.js b/app/controllers/stripe-setup/vat-number/post.controller.js index f3996374a6..f5bbe1e5c6 100644 --- a/app/controllers/stripe-setup/vat-number/post.controller.js +++ b/app/controllers/stripe-setup/vat-number/post.controller.js @@ -9,6 +9,7 @@ const vatNumberValidations = require('./vat-number-validations') const { ConnectorClient } = require('../../../services/clients/connector.client') const connector = new ConnectorClient(process.env.CONNECTOR_URL) const paths = require('../../../paths') +const formatAccountPathsFor = require('../../../utils/format-account-paths-for') // Constants const VAT_NUMBER_FIELD = 'vat-number' @@ -31,7 +32,7 @@ module.exports = async (req, res) => { await updateCompany(res.locals.stripeAccount.stripeAccountId, stripeCompanyBody) await connector.setStripeAccountSetupFlag(req.account.gateway_account_id, 'vat_number', req.correlationId) - return res.redirect(303, paths.stripe.addPspAccountDetails) + return res.redirect(303, formatAccountPathsFor(paths.account.stripe.addPspAccountDetails, req.account && req.account.external_id)) } catch (error) { logger.error(`[${req.correlationId}] Error submitting "VAT number" details, error = `, error) return renderErrorView(req, res, 'Please try again or contact support team') diff --git a/app/paths.js b/app/paths.js index 3da989002b..5ea2e463ba 100644 --- a/app/paths.js +++ b/app/paths.js @@ -94,8 +94,50 @@ module.exports = { index: '/your-psp', flex: '/your-psp/flex', worldpay3dsFlex: '/your-psp/worldpay-3ds-flex' + }, + apiKeys: { + index: '/api-keys', + revoked: '/api-keys/revoked', + create: '/api-keys/create', + revoke: '/api-keys/revoke', + update: '/api-keys/update' + }, + paymentLinks: { + start: '/create-payment-link', + information: '/create-payment-link/information', + webAddress: '/create-payment-link/web-address', + reference: '/create-payment-link/reference', + amount: '/create-payment-link/amount', + review: '/create-payment-link/review', + addMetadata: '/create-payment-link/add-reporting-column', + editMetadata: '/create-payment-link/add-reporting-column/:metadataKey', + deleteMetadata: '/create-payment-link/add-reporting-column/:metadataKey/delete', + manage: { + index: '/create-payment-link/manage', + edit: '/create-payment-link/manage/edit/:productExternalId', + disable: '/create-payment-link/manage/disable/:productExternalId', + delete: '/create-payment-link/manage/delete/:productExternalId', + editInformation: '/create-payment-link/manage/edit/information/:productExternalId', + editReference: '/create-payment-link/manage/edit/reference/:productExternalId', + editAmount: '/create-payment-link/manage/edit/amount/:productExternalId', + addMetadata: '/create-payment-link/manage/:productExternalId/add-reporting-column', + editMetadata: '/create-payment-link/manage/:productExternalId/add-reporting-column/:metadataKey', + deleteMetadata: '/create-payment-link/manage/:productExternalId/add-reporting-column/:metadataKey/delete' + } + }, + stripeSetup: { + bankDetails: '/bank-details', + responsiblePerson: '/responsible-person', + vatNumber: '/vat-number', + companyNumber: '/company-number' + }, + stripe: { + addPspAccountDetails: '/stripe/add-psp-account-details' } }, + redirects: { + stripeSetupLiveDashboardRedirect: '/service/:externalServiceId/dashboard/live' + }, transactions: { index: '/transactions', download: '/transactions/download', @@ -197,16 +239,6 @@ module.exports = { policyPages: { download: '/policy/download/:key' }, - stripeSetup: { - bankDetails: '/bank-details', - responsiblePerson: '/responsible-person', - vatNumber: '/vat-number', - companyNumber: '/company-number', - stripeSetupLink: '/service/:externalServiceId/dashboard/live' - }, - stripe: { - addPspAccountDetails: '/stripe/add-psp-account-details' - }, payouts: { list: '/payments-to-your-bank-account' } diff --git a/app/routes.js b/app/routes.js index 3b04e2da4b..21c198b0ab 100644 --- a/app/routes.js +++ b/app/routes.js @@ -89,8 +89,8 @@ const { healthcheck, registerUser, user, dashboard, selfCreateService, transactions, credentials, serviceSwitcher, teamMembers, staticPaths, inviteValidation, editServiceName, merchantDetails, notificationCredentials, - requestToGoLive, policyPages, stripeSetup, stripe, - allServiceTransactions, payouts + requestToGoLive, policyPages, + allServiceTransactions, payouts, redirects } = paths const { apiKeys, @@ -103,7 +103,9 @@ const { toggle3ds, toggleBillingAddress, toggleMotoMaskCardNumberAndSecurityCode, - yourPsp + yourPsp, + stripeSetup, + stripe } = paths.account // Exports @@ -261,7 +263,7 @@ module.exports.bind = function (app) { app.post(merchantDetails.edit, permission('merchant-details:update'), merchantDetailsController.postEdit) // Service live account dashboard link - app.get(stripeSetup.stripeSetupLink, stripeSetupDashboardRedirectController.get) + app.get(redirects.stripeSetupLiveDashboardRedirect, stripeSetupDashboardRedirectController.get) // ---------------------------- // GATEWAY ACCOUNT LEVEL ROUTES @@ -423,16 +425,6 @@ module.exports.bind = function (app) { account.post(requestToGoLive.agreement, permission('go-live-stage:update'), requestToGoLiveAgreementController.post) // Stripe setup - app.get(stripeSetup.bankDetails, permission('stripe-bank-details:update'), getAccount, paymentMethodIsCard, restrictToLiveStripeAccount, checkBankDetailsNotSubmitted, getStripeAccount, stripeSetupBankDetailsController.get) - app.post(stripeSetup.bankDetails, permission('stripe-bank-details:update'), getAccount, paymentMethodIsCard, restrictToLiveStripeAccount, checkBankDetailsNotSubmitted, getStripeAccount, stripeSetupBankDetailsController.post) - app.get(stripeSetup.responsiblePerson, permission('stripe-responsible-person:update'), getAccount, paymentMethodIsCard, restrictToLiveStripeAccount, getStripeAccount, checkResponsiblePersonNotSubmitted, stripeSetupResponsiblePersonController.get) - app.post(stripeSetup.responsiblePerson, permission('stripe-responsible-person:update'), getAccount, paymentMethodIsCard, restrictToLiveStripeAccount, getStripeAccount, checkResponsiblePersonNotSubmitted, stripeSetupResponsiblePersonController.post) - app.get(stripeSetup.vatNumber, permission('stripe-vat-number-company-number:update'), getAccount, paymentMethodIsCard, restrictToLiveStripeAccount, checkVatNumberNotSubmitted, stripeSetupVatNumberController.get) - app.post(stripeSetup.vatNumber, permission('stripe-vat-number-company-number:update'), getAccount, paymentMethodIsCard, restrictToLiveStripeAccount, getStripeAccount, checkVatNumberNotSubmitted, stripeSetupVatNumberController.post) - app.get(stripeSetup.companyNumber, permission('stripe-vat-number-company-number:update'), getAccount, paymentMethodIsCard, restrictToLiveStripeAccount, checkCompanyNumberNotSubmitted, stripeSetupCompanyNumberController.get) - app.post(stripeSetup.companyNumber, permission('stripe-vat-number-company-number:update'), getAccount, paymentMethodIsCard, restrictToLiveStripeAccount, getStripeAccount, checkCompanyNumberNotSubmitted, stripeSetupCompanyNumberController.post) - app.get(stripe.addPspAccountDetails, permission('stripe-account-details:update'), getAccount, paymentMethodIsCard, restrictToLiveStripeAccount, stripeSetupAddPspAccountDetailsController.get) - account.get(stripeSetup.bankDetails, permission('stripe-bank-details:update'), paymentMethodIsCard, restrictToLiveStripeAccount, checkBankDetailsNotSubmitted, getStripeAccount, stripeSetupBankDetailsController.get) account.post(stripeSetup.bankDetails, permission('stripe-bank-details:update'), paymentMethodIsCard, restrictToLiveStripeAccount, checkBankDetailsNotSubmitted, getStripeAccount, stripeSetupBankDetailsController.post) account.get(stripeSetup.responsiblePerson, permission('stripe-responsible-person:update'), paymentMethodIsCard, restrictToLiveStripeAccount, getStripeAccount, checkResponsiblePersonNotSubmitted, stripeSetupResponsiblePersonController.get) diff --git a/app/views/dashboard/_stripe-account-setup-banner.njk b/app/views/dashboard/_stripe-account-setup-banner.njk index c283d1213f..3c0c0673ac 100644 --- a/app/views/dashboard/_stripe-account-setup-banner.njk +++ b/app/views/dashboard/_stripe-account-setup-banner.njk @@ -51,7 +51,7 @@ govukButton({ text: 'Add details', classes: 'govuk-!-margin-bottom-0', - href: routes.stripe.addPspAccountDetails, + href: formatAccountPathsFor(routes.account.stripe.addPspAccountDetails, currentGatewayAccount.external_id), attributes: { id: "add-account-details" } diff --git a/test/integration/add-psp-details.ft.test.js b/test/integration/add-psp-details.ft.test.js index d7a392d924..8f20ba2496 100644 --- a/test/integration/add-psp-details.ft.test.js +++ b/test/integration/add-psp-details.ft.test.js @@ -33,6 +33,7 @@ describe('Add stripe psp details route', function () { .get(`/v1/frontend/accounts/${GATEWAY_ACCOUNT_ID}`) .reply(200, validGatewayAccountResponse({ gateway_account_id: GATEWAY_ACCOUNT_ID, + external_id: 'a-valid-external-id', payment_provider: 'stripe', type: 'live' })) @@ -50,7 +51,7 @@ describe('Add stripe psp details route', function () { it('should load the "Go live complete" page', async () => { const res = await supertest(app) - .get(paths.stripe.addPspAccountDetails) + .get(`/account/a-valid-external-id/${paths.account.stripe.addPspAccountDetails}`) const $ = cheerio.load(res.text) expect(res.statusCode).to.equal(200) expect($('h1').text()).to.contain('Go live complete') From e67a355d49b1e6aa8c91985555ef5fc7b3559d47 Mon Sep 17 00:00:00 2001 From: Steven Date: Tue, 19 Jan 2021 15:35:15 +0000 Subject: [PATCH 2/2] PP-7583: stripe setup cypress tests with account url structure Signed-off-by: Steven --- .../get.controller.test.js | 8 ++--- .../bank-details/post.controller.test.js | 2 +- .../post.controller.test.js | 4 +-- app/paths.js | 30 ----------------- app/routes.js | 3 +- app/views/stripe-setup/bank-details/index.njk | 2 +- .../stripe-setup/company-number/index.njk | 2 +- .../stripe-setup/responsible-person/index.njk | 2 +- app/views/stripe-setup/vat-number/index.njk | 2 +- .../dashboard-stripe-add-details.cy.test.js | 6 ++-- .../stripe-setup/bank-details.cy.test.js | 32 ++++++++++--------- .../stripe-setup/company-number.cy.test.js | 19 ++++++----- .../responsible-person.cy.test.js | 17 ++++++---- .../stripe-setup/vat-number.cy.test.js | 21 ++++++------ test/cypress/stubs/user-stubs.js | 4 +-- test/integration/add-psp-details.ft.test.js | 12 ++++--- 16 files changed, 75 insertions(+), 91 deletions(-) diff --git a/app/controllers/stripe-setup/add-psp-account-details/get.controller.test.js b/app/controllers/stripe-setup/add-psp-account-details/get.controller.test.js index 026e4c69d6..e0ab5ba0a3 100644 --- a/app/controllers/stripe-setup/add-psp-account-details/get.controller.test.js +++ b/app/controllers/stripe-setup/add-psp-account-details/get.controller.test.js @@ -35,13 +35,13 @@ describe('get controller', () => { it('should redirect to bank account setup page', async () => { req.account.connectorGatewayAccountStripeProgress.bankAccount = false getController(req, res) - sinon.assert.calledWith(res.redirect, 303, `/account/a-valid-external-id/${paths.account.stripeSetup.bankDetails}`) + sinon.assert.calledWith(res.redirect, 303, `/account/a-valid-external-id${paths.account.stripeSetup.bankDetails}`) }) it('should redirect to responsible person page', async () => { req.account.connectorGatewayAccountStripeProgress.bankAccount = true getController(req, res) - sinon.assert.calledWith(res.redirect, 303, `/account/a-valid-external-id/${paths.account.stripeSetup.responsiblePerson}`) + sinon.assert.calledWith(res.redirect, 303, `/account/a-valid-external-id${paths.account.stripeSetup.responsiblePerson}`) }) it('should redirect to VAT number page', async () => { @@ -50,7 +50,7 @@ describe('get controller', () => { responsiblePerson: true } getController(req, res) - sinon.assert.calledWith(res.redirect, 303, `/account/a-valid-external-id/${paths.account.stripeSetup.vatNumber}`) + sinon.assert.calledWith(res.redirect, 303, `/account/a-valid-external-id${paths.account.stripeSetup.vatNumber}`) }) it('should redirect to company registration number page', async () => { @@ -60,7 +60,7 @@ describe('get controller', () => { vatNumber: true } getController(req, res) - sinon.assert.calledWith(res.redirect, 303, `/account/a-valid-external-id/${paths.account.stripeSetup.companyNumber}`) + sinon.assert.calledWith(res.redirect, 303, `/account/a-valid-external-id${paths.account.stripeSetup.companyNumber}`) }) it('should render go live complete page when all steps are completed', async () => { diff --git a/app/controllers/stripe-setup/bank-details/post.controller.test.js b/app/controllers/stripe-setup/bank-details/post.controller.test.js index 9d7d3689bf..43e9f0b9ad 100644 --- a/app/controllers/stripe-setup/bank-details/post.controller.test.js +++ b/app/controllers/stripe-setup/bank-details/post.controller.test.js @@ -53,7 +53,7 @@ describe('Bank details post controller', () => { bank_account_number: sanitisedAccountNumber }) sinon.assert.calledWith(setStripeAccountSetupFlagMock, req.account.gateway_account_id, 'bank_account', req.correlationId) - sinon.assert.calledWith(res.redirect, 303, `/account/a-valid-external-id/${paths.account.stripe.addPspAccountDetails}`) + sinon.assert.calledWith(res.redirect, 303, `/account/a-valid-external-id${paths.account.stripe.addPspAccountDetails}`) }) it('should render error page when Stripe returns unknown error', async () => { diff --git a/app/controllers/stripe-setup/responsible-person/post.controller.test.js b/app/controllers/stripe-setup/responsible-person/post.controller.test.js index 1931c97dc2..81c621a994 100644 --- a/app/controllers/stripe-setup/responsible-person/post.controller.test.js +++ b/app/controllers/stripe-setup/responsible-person/post.controller.test.js @@ -109,7 +109,7 @@ describe('Responsible person POST controller', () => { dob_year: dobYearNormalised }) sinon.assert.calledWith(setStripeAccountSetupFlagMock, req.account.gateway_account_id, 'responsible_person', req.correlationId) - sinon.assert.calledWith(res.redirect, 303, `/account/a-valid-external-id/${paths.account.stripe.addPspAccountDetails}`) + sinon.assert.calledWith(res.redirect, 303, `/account/a-valid-external-id${paths.account.stripe.addPspAccountDetails}`) }) it('should call Stripe with normalised details (no second address line), then connector, then redirect to add details redirect route', async function () { @@ -138,7 +138,7 @@ describe('Responsible person POST controller', () => { dob_year: dobYearNormalised }) sinon.assert.calledWith(setStripeAccountSetupFlagMock, req.account.gateway_account_id, 'responsible_person', req.correlationId) - sinon.assert.calledWith(res.redirect, 303, `/account/a-valid-external-id/${paths.account.stripe.addPspAccountDetails}`) + sinon.assert.calledWith(res.redirect, 303, `/account/a-valid-external-id${paths.account.stripe.addPspAccountDetails}`) }) it('should render error when Stripe returns error, not call connector, and not redirect', async function () { diff --git a/app/paths.js b/app/paths.js index 5ea2e463ba..982a573110 100644 --- a/app/paths.js +++ b/app/paths.js @@ -95,36 +95,6 @@ module.exports = { flex: '/your-psp/flex', worldpay3dsFlex: '/your-psp/worldpay-3ds-flex' }, - apiKeys: { - index: '/api-keys', - revoked: '/api-keys/revoked', - create: '/api-keys/create', - revoke: '/api-keys/revoke', - update: '/api-keys/update' - }, - paymentLinks: { - start: '/create-payment-link', - information: '/create-payment-link/information', - webAddress: '/create-payment-link/web-address', - reference: '/create-payment-link/reference', - amount: '/create-payment-link/amount', - review: '/create-payment-link/review', - addMetadata: '/create-payment-link/add-reporting-column', - editMetadata: '/create-payment-link/add-reporting-column/:metadataKey', - deleteMetadata: '/create-payment-link/add-reporting-column/:metadataKey/delete', - manage: { - index: '/create-payment-link/manage', - edit: '/create-payment-link/manage/edit/:productExternalId', - disable: '/create-payment-link/manage/disable/:productExternalId', - delete: '/create-payment-link/manage/delete/:productExternalId', - editInformation: '/create-payment-link/manage/edit/information/:productExternalId', - editReference: '/create-payment-link/manage/edit/reference/:productExternalId', - editAmount: '/create-payment-link/manage/edit/amount/:productExternalId', - addMetadata: '/create-payment-link/manage/:productExternalId/add-reporting-column', - editMetadata: '/create-payment-link/manage/:productExternalId/add-reporting-column/:metadataKey', - deleteMetadata: '/create-payment-link/manage/:productExternalId/add-reporting-column/:metadataKey/delete' - } - }, stripeSetup: { bankDetails: '/bank-details', responsiblePerson: '/responsible-person', diff --git a/app/routes.js b/app/routes.js index 21c198b0ab..b39efe4d4e 100644 --- a/app/routes.js +++ b/app/routes.js @@ -193,9 +193,8 @@ module.exports.bind = function (app) { ...lodash.values(user.profile), ...lodash.values(requestToGoLive), ...lodash.values(policyPages), - ...lodash.values(stripeSetup), - ...lodash.values(stripe), ...lodash.values(payouts), + ...lodash.values(redirects), paths.feedback ] // Extract all the authenticated paths as a single array diff --git a/app/views/stripe-setup/bank-details/index.njk b/app/views/stripe-setup/bank-details/index.njk index 4a21b9c88f..dcd8b4d8b6 100644 --- a/app/views/stripe-setup/bank-details/index.njk +++ b/app/views/stripe-setup/bank-details/index.njk @@ -29,7 +29,7 @@

This is the bank account payments will go into.

+ data-validate="true"> {% set sortCodeError = false %} diff --git a/app/views/stripe-setup/company-number/index.njk b/app/views/stripe-setup/company-number/index.njk index c398aef241..f607ba1384 100644 --- a/app/views/stripe-setup/company-number/index.njk +++ b/app/views/stripe-setup/company-number/index.njk @@ -27,7 +27,7 @@ {% endif %} + > {% set companyNumberError = false %} diff --git a/app/views/stripe-setup/responsible-person/index.njk b/app/views/stripe-setup/responsible-person/index.njk index 0c07e1778c..6976acaca9 100644 --- a/app/views/stripe-setup/responsible-person/index.njk +++ b/app/views/stripe-setup/responsible-person/index.njk @@ -73,7 +73,7 @@

Stripe will store the responsible person’s details, not GOV.UK Pay.

- + {% call govukFieldset({ diff --git a/app/views/stripe-setup/vat-number/index.njk b/app/views/stripe-setup/vat-number/index.njk index da3d2ebf13..0a0a42d2f8 100644 --- a/app/views/stripe-setup/vat-number/index.njk +++ b/app/views/stripe-setup/vat-number/index.njk @@ -22,7 +22,7 @@

+ novalidate> {% set vatNumberError = false %} diff --git a/test/cypress/integration/dashboard/dashboard-stripe-add-details.cy.test.js b/test/cypress/integration/dashboard/dashboard-stripe-add-details.cy.test.js index db8bc71b96..2db56684fe 100644 --- a/test/cypress/integration/dashboard/dashboard-stripe-add-details.cy.test.js +++ b/test/cypress/integration/dashboard/dashboard-stripe-add-details.cy.test.js @@ -7,13 +7,15 @@ const stripeAccountSetupStubs = require('../../stubs/stripe-account-setup-stub') const stripeAccountStubs = require('../../stubs/stripe-account-stubs') describe('The Stripe psp details banner', () => { - const gatewayAccountId = 22 + const gatewayAccountId = '22' + const gatewayAccountExternalId = 'a-valid-external-id' const userExternalId = 'cd0fa54cf3b7408a80ae2f1b93e7c16e' beforeEach(() => { cy.setEncryptedCookies(userExternalId, gatewayAccountId) cy.task('setupStubs', [ - userStubs.getUserSuccess({ userExternalId, gatewayAccountId }), + userStubs.getUserSuccess({ userExternalId, gatewayAccountId, gatewayAccountExternalId }), gatewayAccountStubs.getGatewayAccountSuccess({ gatewayAccountId, type: 'live', paymentProvider: 'stripe' }), + gatewayAccountStubs.getGatewayAccountByExternalIdSuccess({ gatewayAccountId, gatewayAccountExternalId, type: 'live', paymentProvider: 'stripe' }), transactionsSummaryStubs.getDashboardStatistics(), stripeAccountSetupStubs.getGatewayAccountStripeSetupSuccess({ gatewayAccountId, diff --git a/test/cypress/integration/stripe-setup/bank-details.cy.test.js b/test/cypress/integration/stripe-setup/bank-details.cy.test.js index e22996f645..ff4a875b9a 100644 --- a/test/cypress/integration/stripe-setup/bank-details.cy.test.js +++ b/test/cypress/integration/stripe-setup/bank-details.cy.test.js @@ -6,7 +6,7 @@ const transactionSummaryStubs = require('../../stubs/transaction-summary-stubs') const stripeAccountSetupStubs = require('../../stubs/stripe-account-setup-stub') const stripeAccountStubs = require('../../stubs/stripe-account-stubs') -function setupStubs (userExternalId, gatewayAccountId, bankAccount, type = 'live', paymentProvider = 'stripe') { +function setupStubs (userExternalId, gatewayAccountId, gatewayAccountExternalId, bankAccount, type = 'live', paymentProvider = 'stripe') { let stripeSetupStub if (Array.isArray(bankAccount)) { @@ -20,7 +20,7 @@ function setupStubs (userExternalId, gatewayAccountId, bankAccount, type = 'live cy.task('setupStubs', [ userStubs.getUserSuccess({ userExternalId, gatewayAccountId }), - gatewayAccountStubs.getGatewayAccountSuccess({ gatewayAccountId, type, paymentProvider }), + gatewayAccountStubs.getGatewayAccountByExternalIdSuccess({ gatewayAccountId, gatewayAccountExternalId, type, paymentProvider }), stripeSetupStub, stripeAccountStubs.getStripeAccountSuccess(gatewayAccountId, 'acct_123example123'), transactionSummaryStubs.getDashboardStatistics() @@ -28,7 +28,8 @@ function setupStubs (userExternalId, gatewayAccountId, bankAccount, type = 'live } describe('Stripe setup: bank details page', () => { - const gatewayAccountId = 42 + const gatewayAccountId = '42' + const gatewayAccountExternalId = 'a-valid-external-id' const userExternalId = 'userExternalId' const accountNumber = '00012345' const sortCode = '108800' @@ -40,8 +41,8 @@ describe('Stripe setup: bank details page', () => { describe('Bank details page is shown', () => { beforeEach(() => { - setupStubs(userExternalId, gatewayAccountId, false) - cy.visit('/bank-details') + setupStubs(userExternalId, gatewayAccountId, gatewayAccountExternalId, false) + cy.visit('/account/a-valid-external-id/bank-details') }) it('should display page correctly', () => { @@ -75,9 +76,9 @@ describe('Stripe setup: bank details page', () => { describe('Bank account flag already true', () => { it('should redirect to Dashboard with an error message when on Bank details page', () => { - setupStubs(userExternalId, gatewayAccountId, true) + setupStubs(userExternalId, gatewayAccountId, gatewayAccountExternalId, true) - cy.visit('/bank-details') + cy.visit('/account/a-valid-external-id/bank-details') cy.get('h1').should('contain', 'Dashboard') cy.location().should((location) => { @@ -88,9 +89,9 @@ describe('Stripe setup: bank details page', () => { }) it('should redirect to Dashboard with an error message when submitting Bank details page', () => { - setupStubs(userExternalId, gatewayAccountId, [false, true], 'live', 'stripe') + setupStubs(userExternalId, gatewayAccountId, gatewayAccountExternalId, [false, true], 'live', 'stripe') - cy.visit('/bank-details') + cy.visit('/account/a-valid-external-id/bank-details') cy.get('input#account-number[name="account-number"]').type(accountNumber) cy.get('input#sort-code[name="sort-code"]').type(sortCode) @@ -107,9 +108,9 @@ describe('Stripe setup: bank details page', () => { describe('Not a Stripe gateway account', () => { it('should show a 404 error when gateway account is not Stripe', () => { - setupStubs(userExternalId, gatewayAccountId, true, 'live', 'sandbox') + setupStubs(userExternalId, gatewayAccountId, gatewayAccountExternalId, true, 'live', 'sandbox') - cy.visit('/bank-details', { + cy.visit('/account/a-valid-external-id/bank-details', { failOnStatusCode: false }) cy.get('h1').should('contain', 'Page not found') @@ -118,9 +119,9 @@ describe('Stripe setup: bank details page', () => { describe('Not a live gateway account', () => { it('should show a 404 error when gateway account is not live', () => { - setupStubs(userExternalId, gatewayAccountId, false, 'test', 'sandbox') + setupStubs(userExternalId, gatewayAccountId, gatewayAccountExternalId, false, 'test', 'sandbox') - cy.visit('/bank-details', { + cy.visit('/account/a-valid-external-id/bank-details', { failOnStatusCode: false }) cy.get('h1').should('contain', 'Page not found') @@ -131,10 +132,11 @@ describe('Stripe setup: bank details page', () => { it('should show a permission error when the user does not have enough permissions', () => { cy.task('setupStubs', [ userStubs.getUserWithNoPermissions(userExternalId, gatewayAccountId), - gatewayAccountStubs.getGatewayAccountSuccess({ gatewayAccountId, type: 'live', paymentProvider: 'stripe' }) + gatewayAccountStubs.getGatewayAccountByExternalIdSuccess({ gatewayAccountId, gatewayAccountExternalId, type: 'live', paymentProvider: 'stripe' }), + stripeAccountSetupStubs.getGatewayAccountStripeSetupSuccess({ gatewayAccountId, bankAccount: false }) ]) - cy.visit('/bank-details', { + cy.visit('/account/a-valid-external-id/bank-details', { failOnStatusCode: false }) cy.get('h1').should('contain', 'An error occurred:') diff --git a/test/cypress/integration/stripe-setup/company-number.cy.test.js b/test/cypress/integration/stripe-setup/company-number.cy.test.js index b3fa4cb3d7..96a6193e07 100644 --- a/test/cypress/integration/stripe-setup/company-number.cy.test.js +++ b/test/cypress/integration/stripe-setup/company-number.cy.test.js @@ -6,6 +6,8 @@ const transactionSummaryStubs = require('../../stubs/transaction-summary-stubs') const stripeAccountSetupStubs = require('../../stubs/stripe-account-setup-stub') const stripeAccountStubs = require('../../stubs/stripe-account-stubs') +const GATEWAY_ACCOUNT_EXTERNAL_ID = 'a-valid-external-id' + function setupStubs (userExternalId, gatewayAccountId, companyNumber, type = 'live', paymentProvider = 'stripe') { let stripeSetupStub @@ -20,7 +22,7 @@ function setupStubs (userExternalId, gatewayAccountId, companyNumber, type = 'li cy.task('setupStubs', [ userStubs.getUserSuccess({ userExternalId, gatewayAccountId }), - gatewayAccountStubs.getGatewayAccountSuccess({ gatewayAccountId, type, paymentProvider }), + gatewayAccountStubs.getGatewayAccountByExternalIdSuccess({ gatewayAccountId, gatewayAccountExternalId: GATEWAY_ACCOUNT_EXTERNAL_ID, type, paymentProvider }), stripeSetupStub, stripeAccountStubs.getStripeAccountSuccess(gatewayAccountId, 'acct_123example123'), transactionSummaryStubs.getDashboardStatistics() @@ -37,7 +39,7 @@ describe('Stripe setup: company number page', () => { setupStubs(userExternalId, gatewayAccountId, false) cy.setEncryptedCookies(userExternalId, gatewayAccountId, {}) - cy.visit('/company-number') + cy.visit('/account/a-valid-external-id/company-number') }) it('should display page correctly', () => { @@ -109,7 +111,7 @@ describe('Stripe setup: company number page', () => { it('should redirect to Dashboard with an error message when displaying the page', () => { setupStubs(userExternalId, gatewayAccountId, true) - cy.visit('/company-number') + cy.visit('/account/a-valid-external-id/company-number') cy.get('h1').should('contain', 'Dashboard') cy.location().should((location) => { @@ -122,7 +124,7 @@ describe('Stripe setup: company number page', () => { it('should redirect to Dashboard with an error message when submitting the form', () => { setupStubs(userExternalId, gatewayAccountId, [false, true]) - cy.visit('/company-number') + cy.visit('/account/a-valid-external-id/company-number') cy.get('#company-number-form').should('exist') .within(() => { @@ -149,7 +151,7 @@ describe('Stripe setup: company number page', () => { it('should show a 404 error when gateway account is not Stripe', () => { setupStubs(userExternalId, gatewayAccountId, [false, true], 'live', 'sandbox') - cy.visit('/company-number', { + cy.visit('/account/a-valid-external-id/company-number', { failOnStatusCode: false }) cy.get('h1').should('contain', 'Page not found') @@ -164,7 +166,7 @@ describe('Stripe setup: company number page', () => { it('should show a 404 error when gateway account is not live', () => { setupStubs(userExternalId, gatewayAccountId, [false, true], 'test', 'stripe') - cy.visit('/company-number', { + cy.visit('/account/a-valid-external-id/company-number', { failOnStatusCode: false }) cy.get('h1').should('contain', 'Page not found') @@ -179,10 +181,11 @@ describe('Stripe setup: company number page', () => { it('should show a permission error when the user does not have enough permissions', () => { cy.task('setupStubs', [ userStubs.getUserWithNoPermissions(userExternalId, gatewayAccountId), - gatewayAccountStubs.getGatewayAccountSuccess({ gatewayAccountId, type: 'live', paymentProvider: 'stripe' }) + gatewayAccountStubs.getGatewayAccountByExternalIdSuccess({ gatewayAccountId, gatewayAccountExternalId: GATEWAY_ACCOUNT_EXTERNAL_ID, type: 'live', paymentProvider: 'stripe' }), + stripeAccountSetupStubs.getGatewayAccountStripeSetupSuccess({ gatewayAccountId, companyNumber: true }) ]) - cy.visit('/company-number', { failOnStatusCode: false }) + cy.visit('/account/a-valid-external-id/company-number', { failOnStatusCode: false }) cy.get('h1').should('contain', 'An error occurred:') cy.get('#errorMsg').should('contain', 'You do not have the administrator rights to perform this operation.') }) diff --git a/test/cypress/integration/stripe-setup/responsible-person.cy.test.js b/test/cypress/integration/stripe-setup/responsible-person.cy.test.js index f450eed947..35590c1bca 100644 --- a/test/cypress/integration/stripe-setup/responsible-person.cy.test.js +++ b/test/cypress/integration/stripe-setup/responsible-person.cy.test.js @@ -6,6 +6,8 @@ const transactionSummaryStubs = require('../../stubs/transaction-summary-stubs') const stripeAccountSetupStubs = require('../../stubs/stripe-account-setup-stub') const stripeAccountStubs = require('../../stubs/stripe-account-stubs') +const GATEWAY_ACCOUNT_EXTERNAL_ID = 'a-valid-external-id' + function setupStubs (userExternalId, gatewayAccountId, responsiblePerson, type = 'live', paymentProvider = 'stripe') { let stripeSetupStub @@ -20,7 +22,7 @@ function setupStubs (userExternalId, gatewayAccountId, responsiblePerson, type = cy.task('setupStubs', [ userStubs.getUserSuccess({ userExternalId, gatewayAccountId }), - gatewayAccountStubs.getGatewayAccountSuccess({ gatewayAccountId, type, paymentProvider }), + gatewayAccountStubs.getGatewayAccountByExternalIdSuccess({ gatewayAccountId, gatewayAccountExternalId: GATEWAY_ACCOUNT_EXTERNAL_ID, type, paymentProvider }), stripeSetupStub, stripeAccountStubs.getStripeAccountSuccess(gatewayAccountId, 'acct_123example123'), transactionSummaryStubs.getDashboardStatistics() @@ -52,7 +54,7 @@ describe('Stripe setup: responsible person page', () => { beforeEach(() => { setupStubs(userExternalId, gatewayAccountId, false) - cy.visit('/responsible-person') + cy.visit('/account/a-valid-external-id/responsible-person') }) it('should display form', () => { @@ -149,7 +151,7 @@ describe('Stripe setup: responsible person page', () => { beforeEach(() => { setupStubs(userExternalId, gatewayAccountId, true) - cy.visit('/responsible-person') + cy.visit('/account/a-valid-external-id/responsible-person') }) it('should redirect to dashboard with error message instead of showing form', () => { @@ -165,7 +167,7 @@ describe('Stripe setup: responsible person page', () => { beforeEach(() => { setupStubs(userExternalId, gatewayAccountId, [false, true]) - cy.visit('/responsible-person') + cy.visit('/account/a-valid-external-id/responsible-person') }) it('should redirect to dashboard with error message instead of saving details', () => { @@ -194,7 +196,7 @@ describe('Stripe setup: responsible person page', () => { beforeEach(() => { setupStubs(userExternalId, gatewayAccountId, false, 'live', 'worldpay') - cy.visit('/responsible-person', { failOnStatusCode: false }) + cy.visit('/account/a-valid-external-id/responsible-person', { failOnStatusCode: false }) }) it('should return a 404', () => { @@ -206,10 +208,11 @@ describe('Stripe setup: responsible person page', () => { beforeEach(() => { cy.task('setupStubs', [ userStubs.getUserWithNoPermissions(userExternalId, gatewayAccountId), - gatewayAccountStubs.getGatewayAccountSuccess({ gatewayAccountId, type: 'live', paymentProvider: 'stripe' }) + gatewayAccountStubs.getGatewayAccountByExternalIdSuccess({ gatewayAccountId, gatewayAccountExternalId: GATEWAY_ACCOUNT_EXTERNAL_ID, type: 'live', paymentProvider: 'stripe' }), + stripeAccountSetupStubs.getGatewayAccountStripeSetupSuccess({ gatewayAccountId, responsiblePerson: true }) ]) - cy.visit('/responsible-person', { failOnStatusCode: false }) + cy.visit('/account/a-valid-external-id/responsible-person', { failOnStatusCode: false }) }) it('should show a permission denied error', () => { diff --git a/test/cypress/integration/stripe-setup/vat-number.cy.test.js b/test/cypress/integration/stripe-setup/vat-number.cy.test.js index e86f8599f2..85a6120627 100644 --- a/test/cypress/integration/stripe-setup/vat-number.cy.test.js +++ b/test/cypress/integration/stripe-setup/vat-number.cy.test.js @@ -6,6 +6,8 @@ const transactionSummaryStubs = require('../../stubs/transaction-summary-stubs') const stripeAccountSetupStubs = require('../../stubs/stripe-account-setup-stub') const stripeAccountStubs = require('../../stubs/stripe-account-stubs') +const GATEWAY_ACCOUNT_EXTERNAL_ID = 'a-valid-external-id' + function setupStubs (userExternalId, gatewayAccountId, vatNumber, type = 'live', paymentProvider = 'stripe') { let stripeSetupStub @@ -20,7 +22,7 @@ function setupStubs (userExternalId, gatewayAccountId, vatNumber, type = 'live', cy.task('setupStubs', [ userStubs.getUserSuccess({ userExternalId, gatewayAccountId }), - gatewayAccountStubs.getGatewayAccountSuccess({ gatewayAccountId, type, paymentProvider }), + gatewayAccountStubs.getGatewayAccountByExternalIdSuccess({ gatewayAccountId, gatewayAccountExternalId: GATEWAY_ACCOUNT_EXTERNAL_ID, type, paymentProvider }), stripeSetupStub, stripeAccountStubs.getStripeAccountSuccess(gatewayAccountId, 'acct_123example123'), transactionSummaryStubs.getDashboardStatistics() @@ -28,7 +30,7 @@ function setupStubs (userExternalId, gatewayAccountId, vatNumber, type = 'live', } describe('Stripe setup: VAT number page', () => { - const gatewayAccountId = 42 + const gatewayAccountId = '42' const userExternalId = 'userExternalId' describe('Card gateway account', () => { @@ -38,7 +40,7 @@ describe('Stripe setup: VAT number page', () => { cy.setEncryptedCookies(userExternalId, gatewayAccountId, {}) - cy.visit('/vat-number') + cy.visit('/account/a-valid-external-id/vat-number') }) it('should display page correctly', () => { @@ -89,7 +91,7 @@ describe('Stripe setup: VAT number page', () => { it('should redirect to Dashboard with an error message when displaying the page', () => { setupStubs(userExternalId, gatewayAccountId, true) - cy.visit('/vat-number') + cy.visit('/account/a-valid-external-id/vat-number') cy.get('h1').should('contain', 'Dashboard') cy.location().should((location) => { @@ -102,7 +104,7 @@ describe('Stripe setup: VAT number page', () => { it('should redirect to Dashboard with an error message when submitting the form', () => { setupStubs(userExternalId, gatewayAccountId, [false, true]) - cy.visit('/vat-number') + cy.visit('/account/a-valid-external-id/vat-number') cy.get('input#vat-number[name="vat-number"]').type('GB999 9999 73') @@ -125,7 +127,7 @@ describe('Stripe setup: VAT number page', () => { it('should show a 404 error when gateway account is not Stripe', () => { setupStubs(userExternalId, gatewayAccountId, false, 'live', 'sandbox') - cy.visit('/vat-number', { + cy.visit('/account/a-valid-external-id/vat-number', { failOnStatusCode: false }) cy.get('h1').should('contain', 'Page not found') @@ -140,7 +142,7 @@ describe('Stripe setup: VAT number page', () => { it('should show a 404 error when gateway account is not live', () => { setupStubs(userExternalId, gatewayAccountId, false, 'test', 'stripe') - cy.visit('/vat-number', { + cy.visit('/account/a-valid-external-id/vat-number', { failOnStatusCode: false }) cy.get('h1').should('contain', 'Page not found') @@ -155,10 +157,11 @@ describe('Stripe setup: VAT number page', () => { it('should show a permission error when the user does not have enough permissions', () => { cy.task('setupStubs', [ userStubs.getUserWithNoPermissions(userExternalId, gatewayAccountId), - gatewayAccountStubs.getGatewayAccountSuccess({ gatewayAccountId, type: 'live', paymentProvider: 'stripe' }) + gatewayAccountStubs.getGatewayAccountByExternalIdSuccess({ gatewayAccountId, gatewayAccountExternalId: GATEWAY_ACCOUNT_EXTERNAL_ID, type: 'live', paymentProvider: 'stripe' }), + stripeAccountSetupStubs.getGatewayAccountStripeSetupSuccess({ gatewayAccountId, vatNumber: true }) ]) - cy.visit('/vat-number', { failOnStatusCode: false }) + cy.visit('/account/a-valid-external-id/vat-number', { failOnStatusCode: false }) cy.get('h1').should('contain', 'An error occurred:') cy.get('#errorMsg').should('contain', 'You do not have the administrator rights to perform this operation.') }) diff --git a/test/cypress/stubs/user-stubs.js b/test/cypress/stubs/user-stubs.js index 788cecf024..b083192555 100644 --- a/test/cypress/stubs/user-stubs.js +++ b/test/cypress/stubs/user-stubs.js @@ -44,8 +44,8 @@ function getUserSuccessWithServiceRole (opts) { return builGetUserSuccessStub(opts.userExternalId, fixtureOpts) } -function getUserWithNoPermissions (userExternalId, gatewayAccountIds) { - return getUserSuccess({ userExternalId, gatewayAccountIds, goLiveStage: 'NOT_STARTED', role: { permissions: [] } }) +function getUserWithNoPermissions (userExternalId, gatewayAccountId) { + return getUserSuccess({ userExternalId, gatewayAccountId, goLiveStage: 'NOT_STARTED', role: { permissions: [] } }) } function postUserAuthenticateSuccess (userExternalId, username, password) { diff --git a/test/integration/add-psp-details.ft.test.js b/test/integration/add-psp-details.ft.test.js index 8f20ba2496..1ad31d910a 100644 --- a/test/integration/add-psp-details.ft.test.js +++ b/test/integration/add-psp-details.ft.test.js @@ -10,8 +10,8 @@ const { validGatewayAccountResponse } = require('../fixtures/gateway-account.fix const { buildGetStripeAccountSetupResponse } = require('../fixtures/stripe-account-setup.fixtures') const connectorMock = nock(process.env.CONNECTOR_URL) -const GATEWAY_ACCOUNT_ID = 111 - +const GATEWAY_ACCOUNT_ID = '111' +const GATEWAY_ACCOUNT_EXTERNAL_ID = 'a-valid-external-id' const { getApp } = require('../../server') const { getMockSession, createAppWithSession, getUser } = require('../test-helpers/mock-session') @@ -30,10 +30,10 @@ describe('Add stripe psp details route', function () { app = createAppWithSession(getApp(), session) connectorMock - .get(`/v1/frontend/accounts/${GATEWAY_ACCOUNT_ID}`) + .get(`/v1/frontend/accounts/external-id/${GATEWAY_ACCOUNT_EXTERNAL_ID}`) .reply(200, validGatewayAccountResponse({ gateway_account_id: GATEWAY_ACCOUNT_ID, - external_id: 'a-valid-external-id', + external_id: GATEWAY_ACCOUNT_EXTERNAL_ID, payment_provider: 'stripe', type: 'live' })) @@ -50,8 +50,10 @@ describe('Add stripe psp details route', function () { }) it('should load the "Go live complete" page', async () => { + const url = `/account/a-valid-external-id${paths.account.stripe.addPspAccountDetails}` + console.log('going to url', url) const res = await supertest(app) - .get(`/account/a-valid-external-id/${paths.account.stripe.addPspAccountDetails}`) + .get(url) const $ = cheerio.load(res.text) expect(res.statusCode).to.equal(200) expect($('h1').text()).to.contain('Go live complete')