Skip to content

Commit

Permalink
APS-1702 Suitability search filter changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Bob Meredith committed Jan 7, 2025
1 parent 669c2fe commit 27ade91
Show file tree
Hide file tree
Showing 18 changed files with 87 additions and 166 deletions.
4 changes: 2 additions & 2 deletions e2e/steps/assess.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ export const addMatchingInformation = async (page: Page) => {

await matchingInformationPage.checkRadio('Standard AP')

const relevantRisksAndOffences = ['Accepts hate crime offenders', 'Accepts non sexual child offenders']
const relevantRisksAndOffences = ['Accepts hate crime offenders', 'Accepts non sexual child offenders', 'Is catered']
const irrelevantRisksAndOffences = [
'Accepts sex offenders',
'Is suitable for vulnerable',
Expand All @@ -153,7 +153,7 @@ export const addMatchingInformation = async (page: Page) => {
'Is arson suitable',
]

const essentialCharacteristics = ['Is catered', 'Has en suite']
const essentialCharacteristics = ['Has en suite']

const desirableCharacteristics: Array<string> = []
const irrelevantCharacteristics = ['Is step free designated', 'Is wheelchair designated', 'Is single']
Expand Down
6 changes: 0 additions & 6 deletions integration_tests/pages/match/searchPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,27 +59,21 @@ export default class SearchPage extends Page {
}

changeSearchParameters(newSearchParameters: SpaceSearchParametersUi): void {
this.clearDateInputs('startDate')
this.completeDateInputs('startDate', newSearchParameters.startDate)

this.getTextInputByIdAndClear('targetPostcodeDistrict')
this.getTextInputByIdAndEnterDetails('targetPostcodeDistrict', newSearchParameters.targetPostcodeDistrict)
cy.get('[type="checkbox"]').uncheck()

this.checkRadioByNameAndValue('requirements[apType]', newSearchParameters.requirements.apType)
this.checkRadioByNameAndValue('requirements[gender]', newSearchParameters.requirements.gender)

newSearchParameters.requirements.spaceCharacteristics.forEach(requirement => {
cy.get(`input[name="requirements[spaceCharacteristics][]"][value="${requirement}"]`).check()
})
}

shouldShowSearchParametersInInputs(newSearchParameters: SpaceSearchParametersUi): void {
this.dateInputsShouldContainDate('startDate', newSearchParameters.startDate)
this.verifyTextInputContentsById('targetPostcodeDistrict', newSearchParameters.targetPostcodeDistrict)

cy.get(`input[name="requirements[apType]"][value="${newSearchParameters.requirements.apType}"]`)
cy.get(`input[name="requirements[gender]"][value="${newSearchParameters.requirements.gender}"]`)

newSearchParameters.requirements.spaceCharacteristics.forEach(requirement => {
cy.get(`input[name="requirements[spaceCharacteristics][]"][value="${requirement}"]`).should('be.checked')
Expand Down
6 changes: 2 additions & 4 deletions integration_tests/tests/match/match.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ context('Placement Requests', () => {
targetPostcodeDistrict: placementRequest.location,
requirements: {
apTypes: [placementRequest.type],
genders: [placementRequest.gender],
spaceCharacteristics: filteredPlacementCriteria,
},
})
Expand All @@ -99,15 +98,14 @@ context('Placement Requests', () => {
expect(secondSearchRequestBody).to.contain({
applicationId: placementRequest.applicationId,
durationInDays: placementRequest.duration,
startDate: newSearchParameters.startDate,
startDate: placementRequest.expectedArrival,
targetPostcodeDistrict: newSearchParameters.targetPostcodeDistrict,
})

expect(secondSearchRequestBody.requirements.apTypes).to.contain.members([newSearchParameters.requirements.apType])
expect(secondSearchRequestBody.requirements.spaceCharacteristics).to.contain.members(
newSearchParameters.requirements.spaceCharacteristics,
)
expect(secondSearchRequestBody.requirements.genders).to.contain.members([newSearchParameters.requirements.gender])
})
})

Expand Down Expand Up @@ -296,7 +294,7 @@ context('Placement Requests', () => {

// And there is a placement request waiting for me to match
const person = personFactory.build()
const essentialCharacteristics: Array<PlacementCriteria> = ['acceptsHateCrimeOffenders']
const essentialCharacteristics: Array<PlacementCriteria> = ['isArsonDesignated']
const desirableCharacteristics: Array<PlacementCriteria> = ['isCatered', 'hasEnSuite']
const placementRequest = placementRequestDetailFactory.build({
person,
Expand Down
8 changes: 3 additions & 5 deletions server/@types/ui/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import {
Cas1PremisesBasicSummary,
Document,
FlagsEnvelope,
Gender,
Mappa,
OASysSection,
PersonAcctAlert,
Expand Down Expand Up @@ -111,7 +110,7 @@ export type TableCell =

export type TableRow = Array<TableCell>

export interface RadioItem {
export type RadioItem = {
text: string
value: string
checked?: boolean
Expand All @@ -131,9 +130,9 @@ export type CheckBoxItem =
}
behaviour?: 'exclusive'
}
| CheckBoxDivider
| Divider

export type CheckBoxDivider = { divider: string }
export type Divider = { divider: string }

export interface SelectOption {
text: string
Expand Down Expand Up @@ -385,7 +384,6 @@ export interface SpaceSearchParametersUi {
durationInDays: string
requirements: {
apType: ApType
gender: Gender
spaceCharacteristics: Array<SpaceCharacteristic>
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const defaultMatchingInformationValuesReturnValue: Partial<MatchingInformationBo
apType: 'isPIPE',
isArsonDesignated: 'essential',
isArsonSuitable: 'relevant',
isCatered: 'essential',
isCatered: 'relevant',
isSingle: 'desirable',
isSuitableForVulnerable: 'relevant',
isSuitedForSexOffenders: 'desirable',
Expand Down Expand Up @@ -83,8 +83,8 @@ describe('MatchingInformation', () => {
const page = new MatchingInformation({}, assessment)

expect(page.errors()).toEqual({
isStepFreeDesignated: 'You must specify a preference for step-free access',
hasEnSuite: 'You must specify a preference for en-suite bathroom',
isStepFreeDesignated: 'You must specify a preference for step-free',
hasEnSuite: 'You must specify a preference for en-suite',
lengthOfStayAgreed: 'You must state if you agree with the length of the stay',
})
})
Expand Down Expand Up @@ -115,18 +115,18 @@ describe('MatchingInformation', () => {

expect(page.response()).toEqual({
'What type of AP is required?': 'Enhanced Security AP (ESAP)',
'Designated arson room': 'Essential',
'Room suitable for a person with sexual offences': 'Not relevant',
'Wheelchair accessible': 'Essential',
'Suitable for sexual offences': 'Not relevant',
Wheelchair: 'Essential',
'Single room': 'Desirable',
'Step-free access': 'Desirable',
'Catering required': 'Not relevant',
'En-suite bathroom': 'Not relevant',
'Step-free': 'Desirable',
Catered: 'Not relevant',
'En-suite': 'Not relevant',
'Vulnerable to exploitation': 'Relevant',
'Sexual offences against an adult': 'Relevant',
'Sexual offences against adults': 'Relevant',
'Sexual offences against children': 'Relevant',
'Non sexual offences against children': 'Relevant',
'Hate based offences': 'Relevant',
'Arson room': 'Essential',
'Arson offences': 'Relevant',
'Do you agree with the suggested length of stay?': 'Yes',
'Information for Central Referral Unit (CRU) manager': 'Some info',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ export default class MatchingInformation implements TasklistPage {

this.placementRequirementCriteria.forEach(placementRequirementCriterion => {
if (!this.body[placementRequirementCriterion]) {
errors[placementRequirementCriterion] = `You must specify a preference for ${lowerCase(
placementCriteriaLabels[placementRequirementCriterion],
)}`
errors[placementRequirementCriterion] = `You must specify a preference for ${placementCriteriaLabels[
placementRequirementCriterion
].toLowerCase()}`
}
})

Expand Down
61 changes: 5 additions & 56 deletions server/form-pages/utils/matchingInformationUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,9 @@ describe('matchingInformationUtils', () => {
describe('defaultMatchingInformationValues', () => {
const bodyWithUndefinedValues: MatchingInformationBody = {
acceptsChildSexOffenders: undefined,
acceptsHateCrimeOffenders: undefined,
acceptsNonSexualChildOffenders: undefined,
acceptsSexOffenders: undefined,
acceptsHateCrimeOffenders: undefined,
apType: undefined,
cruInformation: undefined,
hasEnSuite: undefined,
Expand Down Expand Up @@ -109,13 +109,12 @@ describe('matchingInformationUtils', () => {

expect(defaultMatchingInformationValues(body, application)).toEqual({
acceptsChildSexOffenders: 'relevant',
acceptsHateCrimeOffenders: 'relevant',
acceptsNonSexualChildOffenders: 'relevant',
acceptsHateCrimeOffenders: 'relevant',
acceptsSexOffenders: 'relevant',
apType: 'isPIPE',
isArsonDesignated: 'essential',
isArsonSuitable: 'relevant',
isCatered: 'essential',
isCatered: 'relevant',
isSingle: 'essential',
isSuitableForVulnerable: 'relevant',
isSuitedForSexOffenders: 'essential',
Expand All @@ -128,13 +127,11 @@ describe('matchingInformationUtils', () => {
it('uses current values where they exist', () => {
const currentValues: Partial<MatchingInformationBody> = {
acceptsChildSexOffenders: 'relevant',
acceptsHateCrimeOffenders: 'relevant',
acceptsNonSexualChildOffenders: 'relevant',
acceptsSexOffenders: 'relevant',
apType: 'isPIPE',
isArsonDesignated: 'desirable',
isArsonSuitable: 'relevant',
isCatered: 'desirable',
isCatered: 'relevant',
isSingle: 'desirable',
isSuitableForVulnerable: 'relevant',
isSuitedForSexOffenders: 'desirable',
Expand Down Expand Up @@ -180,30 +177,6 @@ describe('matchingInformationUtils', () => {
})
})

describe('acceptsHateCrimeOffenders', () => {
truthyCurrentPreviousValues.forEach(value => {
it(`is set to 'relevant' when \`hateCrime\` === ['${value.join("', '")}']`, () => {
when(retrieveOptionalQuestionResponseFromFormArtifact)
.calledWith(application, DateOfOffence, 'hateCrime')
.mockReturnValue(value)

expect(defaultMatchingInformationValues(bodyWithUndefinedValues, application)).toEqual(
expect.objectContaining({ acceptsHateCrimeOffenders: 'relevant' }),
)
})
})

it("is set to 'notRelevant' when `hateCrime` === undefined", () => {
when(retrieveOptionalQuestionResponseFromFormArtifact)
.calledWith(application, DateOfOffence, 'hateCrime')
.mockReturnValue(undefined)

expect(defaultMatchingInformationValues(bodyWithUndefinedValues, application)).toEqual(
expect.objectContaining({ acceptsHateCrimeOffenders: 'notRelevant' }),
)
})
})

describe('acceptsNonSexualChildOffenders', () => {
truthyCurrentPreviousValues.forEach(value => {
it(`is set to 'relevant' when \`nonSexualOffencesAgainstChildren\` === ['${value.join("', '")}']`, () => {
Expand Down Expand Up @@ -299,38 +272,14 @@ describe('matchingInformationUtils', () => {
})
})

describe('isArsonSuitable', () => {
truthyCurrentPreviousValues.forEach(value => {
it(`is set to 'relevant' when \`arsonOffence\` === ['${value.join("', '")}']`, () => {
when(retrieveOptionalQuestionResponseFromFormArtifact)
.calledWith(application, DateOfOffence, 'arsonOffence')
.mockReturnValue(value)

expect(defaultMatchingInformationValues(bodyWithUndefinedValues, application)).toEqual(
expect.objectContaining({ isArsonSuitable: 'relevant' }),
)
})
})

it("is set to 'notRelevant' when `arsonOffence` === undefined", () => {
when(retrieveOptionalQuestionResponseFromFormArtifact)
.calledWith(application, DateOfOffence, 'arsonOffence')
.mockReturnValue(undefined)

expect(defaultMatchingInformationValues(bodyWithUndefinedValues, application)).toEqual(
expect.objectContaining({ isArsonSuitable: 'notRelevant' }),
)
})
})

describe('isCatered', () => {
it("is set to 'essential' when `catering` (self-catering) === 'no'", () => {
when(retrieveQuestionResponseFromFormArtifact)
.calledWith(application, Catering, 'catering')
.mockReturnValue('no')

expect(defaultMatchingInformationValues(bodyWithUndefinedValues, application)).toEqual(
expect.objectContaining({ isCatered: 'essential' }),
expect.objectContaining({ isCatered: 'relevant' }),
)
})

Expand Down
14 changes: 3 additions & 11 deletions server/form-pages/utils/matchingInformationUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ const defaultMatchingInformationValues = (
'relevant',
'notRelevant',
),

apType: apType(body, application),
isArsonDesignated: getValue<GetValuePlacementRequirement>(
body,
Expand All @@ -158,22 +159,13 @@ const defaultMatchingInformationValues = (
'essential',
'notRelevant',
),
isArsonSuitable: getValue<GetValueOffenceAndRisk>(
body,
'isArsonSuitable',
application,
[{ name: 'arsonOffence', page: DateOfOffence, optional: true }],
['current', 'previous'],
'relevant',
'notRelevant',
),
isCatered: getValue<GetValuePlacementRequirement>(
isCatered: getValue<GetValueOffenceAndRisk>(
body,
'isCatered',
application,
[{ name: 'catering', page: Catering }],
['no'],
'essential',
'relevant',
'notRelevant',
),
isSingle: getValue<GetValuePlacementRequirement>(
Expand Down
2 changes: 0 additions & 2 deletions server/testutils/factories/placementRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,10 @@ export const placementCriteria: Array<PlacementCriteria> = [
'acceptsSexOffenders',
'acceptsChildSexOffenders',
'acceptsNonSexualChildOffenders',
'acceptsHateCrimeOffenders',
'isWheelchairDesignated',
'isSingle',
'isStepFreeDesignated',
'isCatered',
'hasEnSuite',
'isSuitedForSexOffenders',
'isArsonSuitable',
] as const
1 change: 0 additions & 1 deletion server/testutils/factories/spaceSearchParameters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ export const spaceSearchParametersUiFactory = Factory.define<SpaceSearchParamete
requirements: {
apType: faker.helpers.arrayElement(['pipe', 'esap', 'rfap', 'mhapStJosephs', 'mhapElliottHouse']),
spaceCharacteristics: faker.helpers.arrayElements(filterOutAPTypes(placementCriteria)),
gender: faker.helpers.arrayElement(['male', 'female']),
},
...startDateInputsValues,
}
Expand Down
13 changes: 1 addition & 12 deletions server/utils/assessments/acceptanceData.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,9 @@ describe('acceptanceData', () => {
apType: 'isESAP',
isWheelchairDesignated: 'essential',
isStepFreeDesignated: 'essential',
isCatered: 'essential',
acceptsSexOffenders: 'relevant',
acceptsChildSexOffenders: 'relevant',
acceptsNonSexualChildOffenders: 'relevant',
isArsonSuitable: 'relevant',
acceptsHateCrimeOffenders: 'relevant',
isSuitableForVulnerable: 'relevant',
})

Expand All @@ -153,12 +150,9 @@ describe('acceptanceData', () => {
'isESAP',
'isWheelchairDesignated',
'isStepFreeDesignated',
'isCatered',
'acceptsSexOffenders',
'acceptsChildSexOffenders',
'acceptsNonSexualChildOffenders',
'isArsonSuitable',
'acceptsHateCrimeOffenders',
'isSuitableForVulnerable',
'isSuitedForSexOffenders',
].sort(),
Expand All @@ -170,14 +164,11 @@ describe('acceptanceData', () => {
apType: 'normal',
isWheelchairDesignated: 'desirable',
isStepFreeDesignated: 'desirable',
isCatered: 'desirable',
})

const result = criteriaFromMatchingInformation(matchingInformation)

expect(result.desirableCriteria.sort()).toEqual(
['isStepFreeDesignated', 'isWheelchairDesignated', 'isCatered'].sort(),
)
expect(result.desirableCriteria.sort()).toEqual(['isStepFreeDesignated', 'isWheelchairDesignated'].sort())
expect(result.essentialCriteria).toEqual([])
})

Expand All @@ -190,8 +181,6 @@ describe('acceptanceData', () => {
acceptsSexOffenders: 'notRelevant',
acceptsChildSexOffenders: 'notRelevant',
acceptsNonSexualChildOffenders: 'notRelevant',
isArsonSuitable: 'notRelevant',
acceptsHateCrimeOffenders: 'notRelevant',
isSuitableForVulnerable: 'notRelevant',
})

Expand Down
Loading

0 comments on commit 27ade91

Please sign in to comment.