Skip to content

Commit

Permalink
CAS-525: PDU as first class field (#1036)
Browse files Browse the repository at this point in the history
* Rename test suite to match method

* Add pdu id as first-class field

Probation practitioner's PDU is now send as probationDeliveryUnitId when
submitting the application
  • Loading branch information
froddd authored Aug 12, 2024
1 parent 1610cd7 commit 3721b16
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 2 deletions.
2 changes: 1 addition & 1 deletion server/controllers/apply/applicationsController.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ describe('applicationsController', () => {
})
})

describe('submit', () => {
describe('confirm', () => {
it('renders the application submission confirmation page', async () => {
const requestHandler = applicationsController.confirm()
await requestHandler(request, response, next)
Expand Down
1 change: 1 addition & 0 deletions server/utils/applications/getApplicationData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ describe('getApplicationSubmissionData', () => {
hasHistoryOfArson: false,
isConcerningArsonBehaviour: true,
prisonReleaseTypes: ['Fixed-term recall', 'Parole'],
probationDeliveryUnitId: applicationDataJson['contact-details']['probation-practitioner'].pdu.id,
})
})
})
2 changes: 2 additions & 0 deletions server/utils/applications/getApplicationData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
isRegisteredSexOffenderFromApplication,
needsAccessiblePropertyFromApplication,
personReleaseDateFromApplication,
probationDeliveryUnitIdFromApplication,
releaseTypesFromApplication,
} from './reportDataFromApplication'

Expand Down Expand Up @@ -49,5 +50,6 @@ export const getApplicationSubmissionData = (application: Application): SubmitAp
hasHistoryOfArson: hasHistoryOfArsonFromApplication(application),
isConcerningArsonBehaviour: isConcerningArsonBehaviourFromApplication(application),
prisonReleaseTypes: releaseTypesFromApplication(application),
probationDeliveryUnitId: probationDeliveryUnitIdFromApplication(application),
}
}
28 changes: 27 additions & 1 deletion server/utils/applications/reportDataFromApplication.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ import {
isRegisteredSexOffenderFromApplication,
needsAccessiblePropertyFromApplication,
personReleaseDateFromApplication,
probationDeliveryUnitIdFromApplication,
releaseTypesFromApplication,
} from './reportDataFromApplication'
import { applicationFactory } from '../../testutils/factories'
import { applicationFactory, pduFactory } from '../../testutils/factories'
import { SessionDataError } from '../errors'

describe('reportDataFromApplication', () => {
Expand Down Expand Up @@ -374,4 +375,29 @@ describe('reportDataFromApplication', () => {
expect(releaseTypesFromApplication(application)).toEqual([])
})
})

describe('probationDeliveryUnitIdFromApplication', () => {
it("returns the probation practitioner's PDU id", () => {
const pdu = pduFactory.build()
const application = applicationFactory.build({
data: {
'contact-details': {
'probation-practitioner': {
pdu,
},
},
},
})

expect(probationDeliveryUnitIdFromApplication(application)).toEqual(pdu.id)
})

it("throws an error if the probation practitioner's PDU is not present", () => {
const application = applicationFactory.build()

expect(() => probationDeliveryUnitIdFromApplication(application)).toThrow(
new SessionDataError('No probation practitioner PDU'),
)
})
})
})
11 changes: 11 additions & 0 deletions server/utils/applications/reportDataFromApplication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,16 @@ const releaseTypesFromApplication = (application: Application): Array<string> =>
return releaseTypesData.map(key => releaseTypes[key].abbr)
}

const probationDeliveryUnitIdFromApplication = (application: Application): string => {
const pduId = (application.data as Record<string, unknown>)?.['contact-details']?.['probation-practitioner']?.pdu?.id

if (!pduId) {
throw new SessionDataError('No probation practitioner PDU')
}

return pduId
}

export {
dutyToReferSubmissionDateFromApplication,
dutyToReferLocalAuthorityAreaNameFromApplication,
Expand All @@ -190,4 +200,5 @@ export {
hasHistoryOfArsonFromApplication,
isConcerningArsonBehaviourFromApplication,
releaseTypesFromApplication,
probationDeliveryUnitIdFromApplication,
}

0 comments on commit 3721b16

Please sign in to comment.