Skip to content

Commit

Permalink
Send application eligibility data 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 application
eligibility data as a first class property when submitting an
application.

If the reason matches one of the 4 reasons from the application it'll
return true, which should be always. However, to guard against future
updates, we return false if the reason is not found.
  • Loading branch information
libuk committed Sep 26, 2023
1 parent ee72dae commit 29ff94f
Show file tree
Hide file tree
Showing 4 changed files with 44 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 @@ -434,6 +434,31 @@ describe('utils', () => {
})
})

describe('isApplicationEligibleFromApplication', () => {
it('returns whether the application is eligible for CAS3 from the application', () => {
const application = applicationFactory.build({
data: {
eligibility: {
'eligibility-reason': { reason: 'homelessFromCustody' },
},
},
})
expect(utils.isApplicationEligibleFromApplication(application)).toEqual(true)
})

it('throws an error when the eligibility data is not present', () => {
const application = applicationFactory.build({
data: {
eligibility: {},
},
})

expect(() => utils.isApplicationEligibleFromApplication(application)).toThrow(
new SessionDataError('No application eligibility data'),
)
})
})

describe('dateBodyProperties', () => {
it('returns date field names for use in page body properties', () => {
expect(utils.dateBodyProperties('someDate')).toEqual([
Expand Down
16 changes: 16 additions & 0 deletions server/form-pages/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
YesOrNo,
YesOrNoWithDetail,
} from '@approved-premises/ui'
import { eligibilityReasons } from '../apply/accommodation-need/eligibility/eligibilityReason'

Check failure on line 11 in server/form-pages/utils/index.ts

View workflow job for this annotation

GitHub Actions / test

Dependency cycle via ../../../utils/decorators:3=>./form.decorator:4
import {
Adjudication,
TemporaryAccommodationApplication as Application,
Expand Down Expand Up @@ -255,6 +256,21 @@ export const needsAccessiblePropertyFromApplication = (application: Application)
return true
}

export const isApplicationEligibleFromApplication = (application: Application): boolean => {
const eligibilityReason: string = (application.data as Record<string, unknown>)?.eligibility?.['eligibility-reason']
?.reason

if (!eligibilityReason) {
throw new SessionDataError('No application eligibility data')
}

if (Object.keys(eligibilityReasons).includes(eligibilityReason)) {
return true
}

return false
}

export const dateBodyProperties = (root: string) => {
return [root, `${root}-year`, `${root}-month`, `${root}-day`]
}
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 @@ -28,6 +28,7 @@ describe('getApplicationSubmissionData', () => {
isDutyToReferSubmitted: true,
dutyToReferSubmissionDate: '2022-04-12',
needsAccessibleProperty: true,
isApplicationEligible: true,
})
})
})
2 changes: 2 additions & 0 deletions server/utils/applications/getApplicationData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
import {
arrivalDateFromApplication,
dutyToReferSubmissionDateFromApplication,
isApplicationEligibleFromApplication,
isDutyToReferSubmittedFromApplication,
needsAccessiblePropertyFromApplication,
} from '../../form-pages/utils'
Expand All @@ -27,5 +28,6 @@ export const getApplicationSubmissionData = (application: Application): SubmitAp
isDutyToReferSubmitted: isDutyToReferSubmittedFromApplication(application),
dutyToReferSubmissionDate: dutyToReferSubmissionDateFromApplication(application),
needsAccessibleProperty: needsAccessiblePropertyFromApplication(application),
isApplicationEligible: isApplicationEligibleFromApplication(application),
}
}

0 comments on commit 29ff94f

Please sign in to comment.