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/package.json b/package.json
index fbbcd9936d..48bb7113f8 100644
--- a/package.json
+++ b/package.json
@@ -128,7 +128,7 @@
"chai-arrays": "2.2.0",
"chai-as-promised": "7.1.1",
"cheerio": "1.0.0-rc.12",
- "chokidar-cli": "latest",
+ "chokidar-cli": "*",
"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')