From 130db853045ba2ef4295903283b544e4258a5667 Mon Sep 17 00:00:00 2001 From: Hugo Jeffreys Date: Mon, 16 Oct 2023 17:10:27 +0100 Subject: [PATCH] PP-7843 Stop selecting default option on permission level radios --- app/controllers/invite-user.controller.js | 4 +++- .../invite-user.controller.test.js | 23 +++++++++++++++++++ app/views/team-members/team-member-invite.njk | 4 ++-- package-lock.json | 2 +- .../invite-users.controller.ft.test.js | 22 ------------------ test/ui/invite-user.ui.test.js | 4 ++-- 6 files changed, 31 insertions(+), 28 deletions(-) diff --git a/app/controllers/invite-user.controller.js b/app/controllers/invite-user.controller.js index 0c978b3ca4..47ce0f31a7 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..1d2a285a10 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/package-lock.json b/package-lock.json index c8be66bd19..772cb71a0e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -64,7 +64,7 @@ "chai-arrays": "2.2.0", "chai-as-promised": "7.1.1", "cheerio": "1.0.0-rc.12", - "chokidar-cli": "*", + "chokidar-cli": "latest", "csrf": "^3.1.0", "cypress": "^12.16.0", "dotenv": "16.3.1", 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')