Skip to content

Commit

Permalink
PP-10451 Handle gateway timeout error during transactions download.
Browse files Browse the repository at this point in the history
This change is for the single service transaction search and not the all services functionality.
Converting test scenarios as Cypress Tests for 400, 500 and 504 responses and removing nock mocking logic.
Download of transactions list by clicking the download link was de-scoped, so no tests were written for the download functionality.
  • Loading branch information
olatomgds committed Nov 1, 2023
1 parent fa9d21f commit 6482761
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 30 deletions.
4 changes: 3 additions & 1 deletion app/controllers/invite-user.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ async function invite (req, res, next) {
lodash.set(req, 'session.pageData', { invitee })
res.redirect(303, formatServicePathsFor(paths.service.teamMembers.invite, externalServiceId))
} else if (!role) {
next(new Error(`Cannot identify role from user input ${roleId}`))
req.flash('genericError', 'Select the team member’s permission level')
lodash.set(req, 'session.pageData', { invitee })
res.redirect(303, formatServicePathsFor(paths.service.teamMembers.invite, externalServiceId))
} else {
try {
await userService.createInviteToJoinService(invitee, senderId, externalServiceId, role.name)
Expand Down
23 changes: 23 additions & 0 deletions app/controllers/invite-user.controller.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,27 @@ describe('invite user controller', () => {
sinon.assert.calledWith(req.flash, 'genericError', 'Enter a valid email address')
sinon.assert.calledWith(res.redirect, 303, `/service/${externalServiceId}/team-members/invite`)
})

it('should error if a role is not recognised', async () => {
const externalServiceId = 'some-external-service-id'
const unknownRoleId = '999'
const req = {
user: { externalId: 'some-ext-id', serviceIds: ['1'] },
body: {
'invitee-email': '[email protected]',
'role-input': unknownRoleId
},
service: {
externalId: externalServiceId
},
flash: sinon.stub()
}
const res = {
redirect: sinon.stub()
}

await inviteUserController.invite(req, res)
sinon.assert.calledWith(req.flash, 'genericError', 'Select the team member’s permission level')
sinon.assert.calledWith(res.redirect, 303, `/service/${externalServiceId}/team-members/invite`)
})
})
4 changes: 2 additions & 2 deletions app/views/team-members/team-member-invite.njk
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ Invite a new team member - GOV.UK Pay
label: {
classes: "govuk-label--s"
},
checked: true,
checked: false,
hint: {
html: "View transactions<br>
Cannot refund payments<br>
Expand Down Expand Up @@ -155,7 +155,7 @@ Invite a new team member - GOV.UK Pay
label: {
classes: "govuk-label--s"
},
checked: true,
checked: false,
hint: {
html: "View transactions<br>
Cannot refund payments<br>
Expand Down
6 changes: 3 additions & 3 deletions test/cypress/integration/demo-payment/mock-cards-stripe.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ function setupYourPspStubs (opts = {}) {
gatewayAccountId,
gatewayAccountExternalId,
type: 'test',
paymentProvider: 'stripe'
paymentProvider: 'stripe',
})

const stripeAccountSetup = stripeAccountSetupStubs.getGatewayAccountStripeSetupSuccess({
gatewayAccountId
gatewayAccountId,
})

const stubs = [
user,
gatewayAccountByExternalId,
stripeAccountSetup
stripeAccountSetup,
]

cy.task('setupStubs', stubs)
Expand Down
22 changes: 0 additions & 22 deletions test/integration/invite-users.controller.ft.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,27 +85,5 @@ describe('invite user controller', function () {
})
.end(done)
})

it('should error on unknown role externalId', function (done) {
const unknownRoleId = '999'

const app = session.getAppWithLoggedInUser(getApp(), userInSession)

supertest(app)
.post(formatServicePathsFor(paths.service.teamMembers.invite, EXTERNAL_SERVICE_ID))
.set('Accept', 'application/json')
.set('Content-Type', 'application/x-www-form-urlencoded')
.set('x-request-id', 'bob')
.send({
'invitee-email': '[email protected]',
'role-input': unknownRoleId,
csrfToken: csrf().create('123')
})
.expect(500)
.expect((res) => {
expect(res.body.message).to.equal('There is a problem with the payments platform. Please contact the support team.')
})
.end(done)
})
})
})
4 changes: 2 additions & 2 deletions test/ui/invite-user.ui.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('Invite a team member view', function () {
body.should.containSelector('#role-input-3')
.withAttribute('type', 'radio')
.withAttribute('value', '4')
.withAttribute('checked')
.withNoAttribute('checked')
body.should.not.containSelector('#role-input-4')
body.should.not.containSelector('#role-input-5')
})
Expand Down Expand Up @@ -72,7 +72,7 @@ describe('Invite a team member view', function () {
body.should.containSelector('#role-input-3')
.withAttribute('type', 'radio')
.withAttribute('value', '4')
.withAttribute('checked')
.withNoAttribute('checked')
body.should.containSelector('#role-input-4')
.withAttribute('type', 'radio')
.withAttribute('value', '5')
Expand Down

0 comments on commit 6482761

Please sign in to comment.