Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PP-7843 Stop selecting default option on permission level radios #4148

Merged
merged 3 commits into from
Oct 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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': '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`)
})
})
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.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
"chai-arrays": "2.2.0",
"chai-as-promised": "7.1.1",
"cheerio": "1.0.0-rc.12",
"chokidar-cli": "latest",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be * (what it is on master), not latest.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doh...Missed that!

"chokidar-cli": "*",
"csrf": "^3.1.0",
"cypress": "^12.16.0",
"dotenv": "16.3.1",
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': '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)
})
})
})
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