Skip to content

Commit

Permalink
PP-12444 cypress test responsible person / government entity tasks (#…
Browse files Browse the repository at this point in the history
…4379)

cypress test responsible person / government entity tasks

- cypress tests for the responsible person and government entity simplified account stripe on-boarding tasks
- stripe client updated to correctly override the host value for Stripe file operations
- prevent users from accessing the government entity upload task without completing all other on-boarding steps
  • Loading branch information
nlsteers authored Dec 9, 2024
1 parent 6e35109 commit 187ba8f
Show file tree
Hide file tree
Showing 10 changed files with 694 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ async function post (req, res, next) {
summary: [{ text: 'Error uploading file to stripe. Try uploading a file with one of the following types: pdf, jpeg, png', href: '#government-entity-document' }]
})
}
next(err)
return next(err)
}
req.flash('messages', { state: 'success', icon: '✓', heading: 'Service connected to Stripe', body: 'This service can now take payments' })
res.redirect(formatSimplifiedAccountPathsFor(paths.simplifiedAccount.settings.stripeDetails.index, req.service.externalId, req.account.type))
Expand Down
9 changes: 8 additions & 1 deletion app/errors.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ class ExpiredInviteError extends DomainError {
class TaskAlreadyCompletedError extends DomainError {
}

/**
* Thrown when trying to visit a task page when the requisite tasks have not been completed
*/
class TaskAccessedOutOfSequenceError extends DomainError {
}

module.exports = {
NotAuthenticatedError,
UserAccountDisabledError,
Expand All @@ -109,5 +115,6 @@ module.exports = {
ExpiredInviteError,
GatewayTimeoutError,
GatewayTimeoutForAllServicesSearchError,
TaskAlreadyCompletedError
TaskAlreadyCompletedError,
TaskAccessedOutOfSequenceError
}
9 changes: 8 additions & 1 deletion app/middleware/error-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ const {
InvalidConfigurationError,
ExpiredInviteError,
GatewayTimeoutError,
GatewayTimeoutForAllServicesSearchError, TaskAlreadyCompletedError
GatewayTimeoutForAllServicesSearchError,
TaskAlreadyCompletedError,
TaskAccessedOutOfSequenceError
} = require('../errors')
const paths = require('../paths')
const { renderErrorView, response } = require('../utils/response')
Expand Down Expand Up @@ -78,6 +80,11 @@ module.exports = function errorHandler (err, req, res, next) {
return renderErrorView(req, res, 'This invitation is no longer valid', 410)
}

if (err instanceof TaskAccessedOutOfSequenceError) {
logger.info(`TaskAccessedOutOfSequenceError handled: ${err.message}. Redirecting`)
return res.redirect(formatSimplifiedAccountPathsFor(paths.simplifiedAccount.settings.stripeDetails.index, req.service.externalId, req.account.type))
}

if (err instanceof TaskAlreadyCompletedError) {
logger.info(`TaskAlreadyCompletedError handled: ${err.message}. Rendering error page`)
res.status(302)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
const { TaskAlreadyCompletedError } = require('../../errors')
const { TaskAlreadyCompletedError, TaskAccessedOutOfSequenceError } = require('@root/errors')
const {
stripeDetailsTasks,
canStartGovernmentEntityDocument
} = require('@utils/simplified-account/settings/stripe-details/tasks')

module.exports = function checkTaskCompletion (task) {
return function (req, res, next) {
const stripeTaskProgress = req.account.connectorGatewayAccountStripeProgress
if (stripeTaskProgress[task]) {
next(new TaskAlreadyCompletedError(`Attempted to access task page after completion [task: ${task}]`))
next(new TaskAlreadyCompletedError(`Attempted to access task page after completion [task: ${task}, serviceExternalId: ${req.service.externalId}]`))
}
if (task === stripeDetailsTasks.governmentEntityDocument.name && !canStartGovernmentEntityDocument(stripeTaskProgress)) {
next(new TaskAccessedOutOfSequenceError(`Attempted to access task page before completing requisite tasks [task: ${task}, serviceExternalId: ${req.service.externalId}]`))
}
next()
}
Expand Down
5 changes: 3 additions & 2 deletions app/services/clients/stripe/stripe.client.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
'use strict'

const ProxyAgent = require('https-proxy-agent')

const StripeBankAccount = require('./StripeBankAccount.class')
Expand All @@ -11,6 +9,7 @@ const StripeOrganisationDetails = require('./StripeOrganisationDetails.class')

// Constants
const STRIPE_HOST = process.env.STRIPE_HOST
const STRIPE_FILES_HOST = process.env.STRIPE_FILES_HOST
const STRIPE_PORT = process.env.STRIPE_PORT
const STRIPE_PROTOCOL = process.env.STRIPE_PROTOCOL

Expand Down Expand Up @@ -124,6 +123,8 @@ module.exports = {
type: fileType
},
purpose: 'identity_document'
}, STRIPE_FILES_HOST && {
host: STRIPE_FILES_HOST
})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@ const orderTasks = (target) => {
return orderedTasks
}

const canStartGovernmentEntityDocument = (gatewayAccountStripeProgress) => {
return Object.entries(gatewayAccountStripeProgress)
.every(([key, value]) => key === stripeDetailsTasks.governmentEntityDocument.name ? value !== true : value === true)
}

/**
* @typedef {Object} friendlyStripeTasks
* @property {string} href - formatted path for task
Expand Down Expand Up @@ -95,5 +100,6 @@ const friendlyStripeTasks = (account, service) => {

module.exports = {
friendlyStripeTasks,
stripeDetailsTasks
stripeDetailsTasks,
canStartGovernmentEntityDocument
}
Loading

0 comments on commit 187ba8f

Please sign in to comment.