From 6482761bf409e75c592af013270428e952de7dab Mon Sep 17 00:00:00 2001 From: "ola.tomoloju" Date: Wed, 1 Nov 2023 14:02:05 +0000 Subject: [PATCH] PP-10451 Handle gateway timeout error during transactions download. 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. --- app/controllers/invite-user.controller.js | 4 +++- .../invite-user.controller.test.js | 23 +++++++++++++++++++ app/views/team-members/team-member-invite.njk | 4 ++-- .../demo-payment/mock-cards-stripe.cy.js | 6 ++--- .../invite-users.controller.ft.test.js | 22 ------------------ test/ui/invite-user.ui.test.js | 4 ++-- 6 files changed, 33 insertions(+), 30 deletions(-) diff --git a/app/controllers/invite-user.controller.js b/app/controllers/invite-user.controller.js index 0c978b3ca4..44c03ff02a 100644 --- a/app/controllers/invite-user.controller.js +++ b/app/controllers/invite-user.controller.js @@ -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) diff --git a/app/controllers/invite-user.controller.test.js b/app/controllers/invite-user.controller.test.js index 0c292be909..a6995fa695 100644 --- a/app/controllers/invite-user.controller.test.js +++ b/app/controllers/invite-user.controller.test.js @@ -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': 'valid@example.com', + '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`) + }) }) diff --git a/app/views/team-members/team-member-invite.njk b/app/views/team-members/team-member-invite.njk index cd63a29429..67e18f47c6 100644 --- a/app/views/team-members/team-member-invite.njk +++ b/app/views/team-members/team-member-invite.njk @@ -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
Cannot refund payments
@@ -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
Cannot refund payments
diff --git a/test/cypress/integration/demo-payment/mock-cards-stripe.cy.js b/test/cypress/integration/demo-payment/mock-cards-stripe.cy.js index 72206035e6..e6984ce97c 100644 --- a/test/cypress/integration/demo-payment/mock-cards-stripe.cy.js +++ b/test/cypress/integration/demo-payment/mock-cards-stripe.cy.js @@ -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) diff --git a/test/integration/invite-users.controller.ft.test.js b/test/integration/invite-users.controller.ft.test.js index 9f1b0b1b32..2d546e26dc 100644 --- a/test/integration/invite-users.controller.ft.test.js +++ b/test/integration/invite-users.controller.ft.test.js @@ -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': 'invitee@example.com', - '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) - }) }) }) diff --git a/test/ui/invite-user.ui.test.js b/test/ui/invite-user.ui.test.js index 3ca589c8ff..44a3d9110b 100644 --- a/test/ui/invite-user.ui.test.js +++ b/test/ui/invite-user.ui.test.js @@ -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') }) @@ -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')