Skip to content

Commit

Permalink
Send data for accessible property with application
Browse files Browse the repository at this point in the history
We want to add data to the MI report. This commit adds a flag for wether
the application is for an accessible property.
  • Loading branch information
libuk committed Sep 25, 2023
1 parent 7b8776d commit f04f02a
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
25 changes: 25 additions & 0 deletions server/form-pages/utils/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,31 @@ describe('utils', () => {
})
})

describe('needsAccessiblePropertyFromApplication', () => {
it('returns data for whether the application is for an accessible property from the application', () => {
const application = applicationFactory.build({
data: {
'disability-cultural-and-specific-needs': {
'property-attributes-or-adaptations': { propertyAttributesOrAdaptations: 'yes' },
},
},
})
expect(utils.needsAccessiblePropertyFromApplication(application)).toEqual(true)
})

it('throws an error when the accessible property data is not present', () => {
const application = applicationFactory.build({
data: {
'disability-cultural-and-specific-needs': {},
},
})

expect(() => utils.needsAccessiblePropertyFromApplication(application)).toThrow(
new SessionDataError('No accessible property data'),
)
})
})

describe('dateBodyProperties', () => {
it('returns date field names for use in page body properties', () => {
expect(utils.dateBodyProperties('someDate')).toEqual([
Expand Down
14 changes: 14 additions & 0 deletions server/form-pages/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,20 @@ export const dutyToReferSubmissionDateFromApplication = (application: Applicatio
return dutyToReferSubmissionDate
}

export const needsAccessiblePropertyFromApplication = (application: Application): boolean => {
const needsAccessibleProperty: string = (application.data as Record<string, unknown>)?.[
'disability-cultural-and-specific-needs'
]?.['property-attributes-or-adaptations']?.propertyAttributesOrAdaptations

if (!needsAccessibleProperty) {
throw new SessionDataError('No accessible property data')
}

if (needsAccessibleProperty === 'no') return false

return true
}

export const dateBodyProperties = (root: string) => {
return [root, `${root}-year`, `${root}-month`, `${root}-day`]
}
Expand Down
2 changes: 2 additions & 0 deletions server/utils/applications/getApplicationData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
arrivalDateFromApplication,
dutyToReferSubmissionDateFromApplication,
isDutyToReferSubmittedFromApplication,
needsAccessiblePropertyFromApplication,
} from '../../form-pages/utils'
import getSummaryDataFromApplication from './getSummaryDataFromApplication'

Expand All @@ -25,5 +26,6 @@ export const getApplicationSubmissionData = (application: Application): SubmitAp
summaryData: getSummaryDataFromApplication(application),
isDutyToReferSubmitted: isDutyToReferSubmittedFromApplication(application),
dutyToReferSubmissionDate: dutyToReferSubmissionDateFromApplication(application),
needsAccessibleProperty: needsAccessiblePropertyFromApplication(application),
}
}

0 comments on commit f04f02a

Please sign in to comment.