Skip to content

Commit

Permalink
PP-7843 Stop selecting default option on permission level radios
Browse files Browse the repository at this point in the history
  • Loading branch information
hjvoid committed Oct 19, 2023
1 parent f829aaa commit 130db85
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 28 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
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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 130db85

Please sign in to comment.