Skip to content

Commit

Permalink
Merge pull request #725 from ministryofjustice/feature/1670-add-pdu-d…
Browse files Browse the repository at this point in the history
…tr-field

Introduce optional local authority field on duty to refer page
  • Loading branch information
libuk authored Nov 3, 2023
2 parents 773694c + 286db01 commit c82ff4e
Show file tree
Hide file tree
Showing 14 changed files with 245 additions and 28 deletions.
2 changes: 2 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import room from './integration_tests/mockApis/room'
import tokenVerification from './integration_tests/mockApis/tokenVerification'
import turnaround from './integration_tests/mockApis/turnaround'
import user from './integration_tests/mockApis/user'
import referenceData from './integration_tests/mockApis/referenceData'
import schemaValidator from './integration_tests/tasks/schemaValidator'
import accessibilityViolations from './integration_tests/tasks/accessibilityViolations'
import { resetStubs } from './wiremock'
Expand Down Expand Up @@ -61,6 +62,7 @@ export default defineConfig({
...bookingSearch,
...bedspaceSearch,
...accessibilityViolations,
...referenceData,
})
},
baseUrl: 'http://localhost:3007',
Expand Down
5 changes: 2 additions & 3 deletions cypress_shared/fixtures/applicationData.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
"releaseDate-year": "2123",
"releaseDate-month": "9",
"releaseDate-day": "2"

},
"accommodation-required-from-date": {
"accommodationRequiredFromDate": "2123-09-16",
Expand Down Expand Up @@ -281,8 +280,8 @@
"date": "2022-04-12",
"date-year": "2022",
"date-month": "4",
"date-day": "12"

"date-day": "12",
"localAuthorityAreaName": "Barking and Dagenham"
},
"crs-submitted": {
"crsSubmitted": "yes"
Expand Down
6 changes: 5 additions & 1 deletion cypress_shared/fixtures/applicationTranslatedDocument.json
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,11 @@
"id": "accommodation-referral-details",
"content": [
{ "Has the Duty to Refer (DTR) / National Offender Pathway (NOP) been submitted?": "Yes" },
{ "DTR / NOP reference number": "ABC123", "Date DTR / NOP was submitted": "12 April 2022" },
{
"DTR / NOP reference number": "ABC123",
"Date DTR / NOP was submitted": "12 April 2022",
"What is the local authority (optional)?": "Barking and Dagenham"
},
{ "Has a referral to Commissioned Rehabilitative Services (CRS) been submitted?": "Yes" },
{ "Have other accommodation options been considered?": "Yes - Other accommodation details" }
]
Expand Down
10 changes: 9 additions & 1 deletion cypress_shared/helpers/apply.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {
acctAlertFactory,
adjudicationFactory,
documentFactory,
localAuthorityFactory,
oasysSectionsFactory,
oasysSelectionFactory,
} from '../../server/testutils/factories'
Expand Down Expand Up @@ -729,6 +730,13 @@ export default class ApplyHelper {
}

private completeAccommodationReferralDetails() {
let localAuthority

if (this.environment === 'integration') {
localAuthority = localAuthorityFactory.build({ name: 'Barking and Dagenham' })
cy.task('stubLocalAuthorities', [localAuthority])
}

// Given I click on the accommodation referral details task
Page.verifyOnPage(TaskListPage, this.application).clickTask('accommodation-referral-details')

Expand All @@ -742,7 +750,7 @@ export default class ApplyHelper {

if (hasSubmittedDtr(this.application)) {
const dtrDetailsPage = new DtrDetailsPage(this.application)
dtrDetailsPage.completeForm()
dtrDetailsPage.completeForm(localAuthority?.name)
dtrDetailsPage.clickSubmit()
this.pages.accommodationReferralDetails.push(dtrDetailsPage)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ export default class DtrDetailsPage extends ApplyPage {
)
}

completeForm() {
completeForm(localAuthorityName?: string) {
this.completeDateInputsFromPageBody('date')
this.completeTextInputFromPageBody('reference')
this.getSelectInputByIdAndSelectAnEntry('localAuthorityAreaName', localAuthorityName || 'Barking and Dagenham')
}
}
21 changes: 21 additions & 0 deletions integration_tests/mockApis/referenceData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { LocalAuthorityArea } from '../../server/@types/shared/models/LocalAuthorityArea'
import { stubFor } from '../../wiremock'

const stubLocalAuthorities = (localAuthorities: Array<LocalAuthorityArea>) =>
stubFor({
request: {
method: 'GET',
url: '/reference-data/local-authority-areas',
},
response: {
status: 200,
headers: {
'Content-Type': 'application/json;charset=UTF-8',
},
jsonBody: localAuthorities,
},
})

export default {
stubLocalAuthorities,
}
4 changes: 4 additions & 0 deletions server/@types/ui/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
TemporaryAccommodationAssessment as Assessment,
Booking,
Document,
LocalAuthorityArea,
OASysSection,
OASysSections,
Person,
Expand Down Expand Up @@ -245,6 +246,9 @@ export type DataServices = Partial<{
userService: {
getUserById: (callConfig: CallConfig, id: string) => Promise<User>
}
referenceDataService: {
getLocalAuthorities: (CallConfig: CallConfig) => Promise<Array<LocalAuthorityArea>>
}
}>

export interface GroupedAssessments {
Expand Down
8 changes: 6 additions & 2 deletions server/controllers/apply/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ import PeopleController from './peopleController'
import type { Services } from '../../services'

export const controllers = (services: Services) => {
const { applicationService, personService } = services
const { applicationService, personService, referenceDataService } = services
const applicationsController = new ApplicationsController(applicationService, personService)
const pagesController = new PagesController(applicationService, { personService, applicationService })
const pagesController = new PagesController(applicationService, {
personService,
applicationService,
referenceDataService,
})
const offencesController = new OffencesController(personService)
const documentsController = new DocumentsController(personService)
const peopleController = new PeopleController(personService)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { applicationFactory } from '../../../../testutils/factories'
import { createMock } from '@golevelup/ts-jest'
import { applicationFactory, localAuthorityFactory } from '../../../../testutils/factories'
import { dateAndTimeInputsAreValidDates, dateIsBlank, dateIsInFuture } from '../../../../utils/dateUtils'
import { itShouldHaveNextValue, itShouldHavePreviousValue } from '../../../shared-examples'
import { CallConfig } from '../../../../data/restClient'
import { ReferenceDataService } from '../../../../services'
import DtrDetails from './dtrDetails'

jest.mock('../../../../utils/dateUtils', () => {
Expand All @@ -14,14 +17,21 @@ jest.mock('../../../../utils/dateUtils', () => {
}
})

const body = { reference: 'ABC123', 'date-year': '2022', 'date-month': '7', 'date-day': '23' }
const localAuthorities = localAuthorityFactory.buildList(3)
const body = {
reference: 'ABC123',
'date-year': '2022',
'date-month': '7',
'date-day': '23',
localAuthorityAreaName: localAuthorities[0].name,
}

describe('DtrDetails', () => {
const application = applicationFactory.build()

describe('body', () => {
it('sets the body', () => {
const page = new DtrDetails(body, application)
const page = new DtrDetails(body, application, localAuthorities)

expect(page.body).toEqual({
...body,
Expand All @@ -30,16 +40,16 @@ describe('DtrDetails', () => {
})
})

itShouldHavePreviousValue(new DtrDetails({}, application), 'dtr-submitted')
itShouldHaveNextValue(new DtrDetails({}, application), 'crs-submitted')
itShouldHavePreviousValue(new DtrDetails({}, application, localAuthorities), 'dtr-submitted')
itShouldHaveNextValue(new DtrDetails({}, application, localAuthorities), 'crs-submitted')

describe('errors', () => {
it('returns an empty object if the DTR details are populated', () => {
;(dateIsBlank as jest.Mock).mockReturnValue(false)
;(dateAndTimeInputsAreValidDates as jest.Mock).mockReturnValue(true)
;(dateIsInFuture as jest.Mock).mockReturnValue(false)

const page = new DtrDetails(body, application)
const page = new DtrDetails(body, application, localAuthorities)
expect(page.errors()).toEqual({})
})

Expand All @@ -48,7 +58,7 @@ describe('DtrDetails', () => {
;(dateAndTimeInputsAreValidDates as jest.Mock).mockReturnValue(true)
;(dateIsInFuture as jest.Mock).mockReturnValue(false)

const page = new DtrDetails({ ...body, reference: undefined }, application)
const page = new DtrDetails({ ...body, reference: undefined }, application, localAuthorities)
expect(page.errors()).toEqual({
reference: 'You must specify the DTR / NOP reference number',
})
Expand All @@ -59,7 +69,7 @@ describe('DtrDetails', () => {
;(dateAndTimeInputsAreValidDates as jest.Mock).mockReturnValue(true)
;(dateIsInFuture as jest.Mock).mockReturnValue(false)

const page = new DtrDetails(body, application)
const page = new DtrDetails(body, application, localAuthorities)
expect(page.errors()).toEqual({
date: 'You must specify the date DTR / NOP was submitted',
})
Expand All @@ -70,7 +80,7 @@ describe('DtrDetails', () => {
;(dateAndTimeInputsAreValidDates as jest.Mock).mockReturnValue(false)
;(dateIsInFuture as jest.Mock).mockReturnValue(false)

const page = new DtrDetails(body, application)
const page = new DtrDetails(body, application, localAuthorities)
expect(page.errors()).toEqual({
date: 'You must specify a valid date DTR / NOP was submitted',
})
Expand All @@ -81,20 +91,80 @@ describe('DtrDetails', () => {
;(dateAndTimeInputsAreValidDates as jest.Mock).mockReturnValue(true)
;(dateIsInFuture as jest.Mock).mockReturnValue(true)

const page = new DtrDetails(body, application)
const page = new DtrDetails(body, application, localAuthorities)
expect(page.errors()).toEqual({
date: 'The date DTR / NOP was submitted must not be in the future',
})
})
})

describe('response', () => {
it('returns a translated version of the response', () => {
const page = new DtrDetails(body, application)
expect(page.response()).toEqual({
'DTR / NOP reference number': 'ABC123',
'Date DTR / NOP was submitted': '23 July 2022',
describe('when local authority is selected', () => {
it('returns a translated version of the response', () => {
const page = new DtrDetails(body, application, localAuthorities)
expect(page.response()).toEqual({
'DTR / NOP reference number': 'ABC123',
'Date DTR / NOP was submitted': '23 July 2022',
'What is the local authority (optional)?': localAuthorities[0].name,
})
})
})

describe('when local authority is not selected', () => {
it('returns placeholder copy for local authority', () => {
const page = new DtrDetails({ ...body, localAuthorityAreaName: null }, application, localAuthorities)
expect(page.response()).toEqual({
'DTR / NOP reference number': 'ABC123',
'Date DTR / NOP was submitted': '23 July 2022',
'What is the local authority (optional)?': 'No local authority selected',
})
})
})
})

describe('initialize', () => {
describe('when fetch for local authorities is successful', () => {
it('populates the body with a list of local authorities', async () => {
const callConfig = { token: 'some-token' } as CallConfig
const getLocalAuthoritiesMock = jest.fn().mockResolvedValue(localAuthorities)
const referenceDataService = createMock<ReferenceDataService>({
getLocalAuthorities: getLocalAuthoritiesMock,
})

await DtrDetails.initialize({}, application, callConfig, { referenceDataService })

expect(getLocalAuthoritiesMock).toHaveBeenCalledWith(callConfig)
})
})

describe('when fetch for local authorities is unsuccessful', () => {
it('returns an empty list of local authorities', async () => {
const callConfig = { token: 'some-token' } as CallConfig
const getLocalAuthoritiesMock = jest.fn().mockImplementation(() => {
throw new Error()
})
const referenceDataService = createMock<ReferenceDataService>({
getLocalAuthorities: getLocalAuthoritiesMock,
})

const page = await DtrDetails.initialize({}, application, callConfig, { referenceDataService })

expect(page.getLocalAuthorities()).toEqual([])
})
})
})

describe('getLocalAuthorities', () => {
it('returns a list of local authorities', async () => {
const callConfig = { token: 'some-token' } as CallConfig
const getLocalAuthoritiesMock = jest.fn().mockResolvedValue(localAuthorities)
const referenceDataService = createMock<ReferenceDataService>({
getLocalAuthorities: getLocalAuthoritiesMock,
})

const page = await DtrDetails.initialize({}, application, callConfig, { referenceDataService })

expect(page.getLocalAuthorities()).toEqual(localAuthorities)
})
})
})
Loading

0 comments on commit c82ff4e

Please sign in to comment.