Skip to content

Commit

Permalink
PP-7583: stripe setup cypress tests with account url structure
Browse files Browse the repository at this point in the history
Signed-off-by: Steven <steven.fountain@digital.cabinet-office.gov.uk>
  • Loading branch information
sfount committed Jan 19, 2021
1 parent f95871a commit e67a355
Show file tree
Hide file tree
Showing 16 changed files with 75 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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 () => {
Expand All @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () {
Expand Down Expand Up @@ -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 () {
Expand Down
30 changes: 0 additions & 30 deletions app/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
3 changes: 1 addition & 2 deletions app/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion app/views/stripe-setup/bank-details/index.njk
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<p class="govuk-body govuk-!-margin-bottom-6">This is the bank account payments will go into.</p>

<form id="bank-details-form" method="post"
action="/bank-details" data-validate="true">
data-validate="true">
<input id="csrf" name="csrfToken" type="hidden" value="{{ csrf }}"/>

{% set sortCodeError = false %}
Expand Down
2 changes: 1 addition & 1 deletion app/views/stripe-setup/company-number/index.njk
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
{% endif %}

<form id="company-number-form" method="post"
action="/company-number">
>
<input id="csrf" name="csrfToken" type="hidden" value="{{ csrf }}"/>

{% set companyNumberError = false %}
Expand Down
2 changes: 1 addition & 1 deletion app/views/stripe-setup/responsible-person/index.njk
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@

<p class="govuk-body">Stripe will store the responsible person’s details, not GOV.UK Pay.</p>

<form id="responsible-person-form" method="post" action="/responsible-person" class="govuk-!-margin-top-4" novalidate>
<form id="responsible-person-form" method="post" class="govuk-!-margin-top-4" novalidate>
<input id="csrf" name="csrfToken" type="hidden" value="{{ csrf }}"/>

{% call govukFieldset({
Expand Down
2 changes: 1 addition & 1 deletion app/views/stripe-setup/vat-number/index.njk
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<h1 class="govuk-heading-l govuk-!-margin-bottom-6"><label for="vat-number">What is your organisation’s VAT number?</label></h1>

<form id="vat-number-form" method="post"
action="/vat-number" novalidate>
novalidate>
<input id="csrf" name="csrfToken" type="hidden" value="{{ csrf }}"/>

{% set vatNumberError = false %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
32 changes: 17 additions & 15 deletions test/cypress/integration/stripe-setup/bank-details.cy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -20,15 +20,16 @@ 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()
])
}

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'
Expand All @@ -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', () => {
Expand Down Expand Up @@ -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) => {
Expand All @@ -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)
Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -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:')
Expand Down
19 changes: 11 additions & 8 deletions test/cypress/integration/stripe-setup/company-number.cy.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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()
Expand All @@ -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', () => {
Expand Down Expand Up @@ -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) => {
Expand All @@ -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(() => {
Expand All @@ -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')
Expand All @@ -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')
Expand All @@ -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.')
})
Expand Down
Loading

0 comments on commit e67a355

Please sign in to comment.