Skip to content

Commit

Permalink
Merge pull request #2268 from ministryofjustice/IPB-1047/fix-qa-bugs
Browse files Browse the repository at this point in the history
QA bug fixes for amending prison establishment
  • Loading branch information
kth13 authored Jul 3, 2024
2 parents 74ebd24 + f96e2e5 commit 93d869a
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 15 deletions.
5 changes: 0 additions & 5 deletions integration_tests/integration/amend-referral.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -888,11 +888,6 @@ context('Amend a referral', () => {
cy.contains(`Update Jenny Jones's prison establishment`)
})

it('shows the existing reason for referral in the form', () => {
cy.login(`/probation-practitioner/referrals/${sentReferral.id}/amend-prison-establishment`)
cy.get('#amend-prison-establishment').should('have.value', 'Aylesbury (HMYOI)')
})

it('redirects to referral details on submission', () => {
cy.login(`/probation-practitioner/referrals/${sentReferral.id}/amend-prison-establishment`)
cy.get('#amend-prison-establishment').type('Brinsford (HMP & YOI)')
Expand Down
2 changes: 2 additions & 0 deletions server/models/referralPrisonEstablishment.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export default interface ReferralPrisonEstablishment {
personCustodyPrisonId: string
oldPrisonEstablishment: string
newPrisonEstablishment: string
}

export interface AmendPrisonEstablishmentUpdate extends ReferralPrisonEstablishment {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,28 @@ describe(AmendPrisonEstablishmentForm, () => {
describe('when prison establishment is passed', () => {
it('returns a paramsForUpdate with the reasonForReferral', async () => {
const request = TestUtils.createRequest({
'amend-prison-establishment': `Bronzefield (HMP & YOI)`,
'amend-prison-establishment': `COW`,
'reason-for-change': 'some reason',
})
const data = await new AmendPrisonEstablishmentForm(request).data()
const data = await new AmendPrisonEstablishmentForm(
request,
[
{
id: 'PBI',
description: 'Peterborough (HMP & YOI)',
},
{
id: 'COW',
description: 'Cookham Wood (HMYOI)',
},
],
'PBI'
).data()

expect(data.paramsForUpdate?.personCustodyPrisonId).toEqual(`Bronzefield (HMP & YOI)`)
expect(data.paramsForUpdate?.personCustodyPrisonId).toEqual(`COW`)
expect(data.paramsForUpdate?.reasonForChange).toEqual('some reason')
expect(data.paramsForUpdate?.oldPrisonEstablishment).toEqual('Peterborough (HMP & YOI)')
expect(data.paramsForUpdate?.newPrisonEstablishment).toEqual('Cookham Wood (HMYOI)')
})
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,14 @@ import { FormData } from '../../../utils/forms/formData'
import FormUtils from '../../../utils/formUtils'
import { FormValidationError } from '../../../utils/formValidationError'
import { AmendPrisonEstablishmentUpdate } from '../../../models/referralPrisonEstablishment'
import PrisonAndSecuredChildAgency from '../../../models/prisonAndSecureChildAgency'

export default class AmendPrisonEstablishmentForm {
constructor(private readonly request: Request) {}
constructor(
private readonly request: Request,
readonly prisonAndSecureChildAgency: PrisonAndSecuredChildAgency[] = [],
readonly oldPrisonEstablishment: string | null = null
) {}

async data(): Promise<FormData<AmendPrisonEstablishmentUpdate>> {
const validationResult = await FormUtils.runValidations({
Expand All @@ -28,6 +33,8 @@ export default class AmendPrisonEstablishmentForm {
paramsForUpdate: {
personCustodyPrisonId: this.request.body['amend-prison-establishment'],
reasonForChange: this.request.body['reason-for-change'],
oldPrisonEstablishment: this.getPrisonName(this.oldPrisonEstablishment),
newPrisonEstablishment: this.getPrisonName(this.request.body['amend-prison-establishment']),
},
error: null,
}
Expand All @@ -53,4 +60,11 @@ export default class AmendPrisonEstablishmentForm {
})),
}
}

private getPrisonName(prisonId: string | null): string {
return (
this.prisonAndSecureChildAgency.find(prisonAndSecuredChildAgency => prisonAndSecuredChildAgency.id === prisonId)
?.description || ''
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('AmendPrisonEstablishmentPresenter', () => {
const presenter = new AmendPrisonEstablishmentPresenter(referral)

expect(presenter.text.title).toEqual(`Update Alex River's prison establishment`)
expect(presenter.text.reasonForChangeHeading).toEqual('what is the reason for changing the prison?')
expect(presenter.text.reasonForChangeHeading).toEqual('What is the reason for changing the prison?')
expect(presenter.backLinkUrl).toEqual(`/probation-practitioner/referrals/${referral.id}/details`)
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class AmendPrisonEstablishmentPresenter {

readonly text = {
title: `Update ${this.referral.referral.serviceUser.firstName} ${this.referral.referral.serviceUser.lastName}'s prison establishment`,
reasonForChangeHeading: 'what is the reason for changing the prison?',
reasonForChangeHeading: 'What is the reason for changing the prison?',
submitLocationInput: {
label: `What is the correct prison establishment for ${this.referral.referral.serviceUser?.firstName}?`,
hint: `Start typing then choose prison name from the list.`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ export default class AmendPrisonEstablishmentView {
return {
text: prisonAndSecureChildAgency.description,
value: prisonAndSecureChildAgency.id,
selected: this.presenter.referral.referral.personCustodyPrisonId
? this.presenter.referral.referral.personCustodyPrisonId === prisonAndSecureChildAgency.id
: false,
selected: false,
}
})

Expand Down
6 changes: 5 additions & 1 deletion server/routes/amendAReferral/amendAReferralController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,11 @@ export default class AmendAReferralController {
)

if (req.method === 'POST') {
const form = await new AmendPrisonEstablishmentForm(req).data()
const form = await new AmendPrisonEstablishmentForm(
req,
prisonAndSecureChildAgency,
sentReferral.referral.personCustodyPrisonId
).data()

if (!form.error) {
await this.interventionsService.updatePrisonEstablishment(accessToken, referralId, form.paramsForUpdate)
Expand Down

0 comments on commit 93d869a

Please sign in to comment.