Skip to content

Commit

Permalink
add sed led and sled date logic
Browse files Browse the repository at this point in the history
  • Loading branch information
whitfield-mj committed Nov 3, 2023
1 parent a0b5b59 commit 5e5d66d
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 2 deletions.
2 changes: 2 additions & 0 deletions server/data/localMockData/offencesPageMock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,7 @@ export const OffencesPageMockSentences = {
nonDtoReleaseDate: '2076-01-29',
paroleEligibilityCalculatedDate: '2021-12-12',
postRecallDate: '2021-12-12',
sentenceLicenceExpiryDate: '2132-03-12',
},
}

Expand Down Expand Up @@ -994,4 +995,5 @@ export const GetReleaseDates: Partial<ReleaseDates> = {
nonDtoReleaseDate: '2076-01-29',
paroleEligibilityCalculatedDate: '2021-12-12',
postRecallDate: '2021-12-12',
sentenceLicenceExpiryDate: '2132-03-12',
}
3 changes: 3 additions & 0 deletions server/interfaces/releaseDates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ export interface ReleaseDates {
homeDetentionCurfewEligibilityDate: string
lateTermDate: string
lateTransferDate: string
licenceExpiryDate?: string
midTermDate: string
midTransferDate: string
nonDtoReleaseDate: string
nonParoleDate: string
paroleEligibilityCalculatedDate: string
postRecallDate: string
releaseOnTemporaryLicenceDate: string
sentenceExpiryDate?: string
sentenceLicenceExpiryDate?: string
tariffDate: string
tariffEarlyRemovalSchemeEligibilityDate: string
topupSupervisionExpiryDate: string
Expand Down
70 changes: 68 additions & 2 deletions server/services/offencesPage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ describe('OffencesPageService', () => {
homeDetentionCurfewActualDate: '2016-01-13',
homeDetentionCurfewEligibilityDate: '2016-01-14',
licenceExpiryCalculatedDate: 'unused',
licenceExpiryDate: 'unused',
licenceExpiryDate: '2016-02-02',
lateTermDate: '2016-01-15',
ltdOverrideDate: '2016-01-16',
ltdCalculatedDate: '2016-01-17',
Expand All @@ -241,7 +241,7 @@ describe('OffencesPageService', () => {
releaseDate: 'unused',
releaseOnTemporaryLicenceDate: '2016-01-27',
sentenceExpiryCalculatedDate: 'unused',
sentenceExpiryDate: 'unused',
sentenceExpiryDate: '2016-02-01',
sentenceStartDate: 'unused',
tariffEarlyRemovalSchemeEligibilityDate: '2016-01-28',
tariffDate: '2016-01-29',
Expand Down Expand Up @@ -283,6 +283,7 @@ describe('OffencesPageService', () => {
paroleEligibilityCalculatedDate: '2016-01-24',
postRecallDate: '2016-01-26',
releaseOnTemporaryLicenceDate: '2016-01-27',
sentenceExpiryDate: '2016-02-01',
tariffDate: '2016-01-29',
tariffEarlyRemovalSchemeEligibilityDate: '2016-01-28',
topupSupervisionExpiryDate: '2016-01-31',
Expand Down Expand Up @@ -354,5 +355,70 @@ describe('OffencesPageService', () => {
automaticReleaseDate: 'date',
})
})
describe('sed, led, sled', () => {
it('should use sed if present', async () => {
prisonApiClient.getPrisonerSentenceDetails = jest.fn(async () => ({
...prisonerSentenceDetailsMock,
sentenceDetail: {
...sentenceDetail,
sentenceExpiryDate: '2016-02-01',
licenceExpiryDate: '2016-02-02',
},
}))
const offencesPageService = offencesPageServiceConstruct()
const res = await offencesPageService.getReleaseDates('token', '12345')
expect(res.sentenceExpiryDate).toEqual(sentenceDetail.sentenceExpiryDate)
expect(res.licenceExpiryDate).toBeUndefined()
expect(res.sentenceLicenceExpiryDate).toBeUndefined()
})

it('should use led if sed not present', async () => {
prisonApiClient.getPrisonerSentenceDetails = jest.fn(async () => ({
...prisonerSentenceDetailsMock,
sentenceDetail: {
...sentenceDetail,
sentenceExpiryDate: undefined,
licenceExpiryDate: '2016-02-02',
},
}))
const offencesPageService = offencesPageServiceConstruct()
const res = await offencesPageService.getReleaseDates('token', '12345')
expect(res.sentenceExpiryDate).toBeUndefined()
expect(res.licenceExpiryDate).toEqual(sentenceDetail.licenceExpiryDate)
expect(res.sentenceLicenceExpiryDate).toBeUndefined()
})

it('should use sled if both present and the same', async () => {
prisonApiClient.getPrisonerSentenceDetails = jest.fn(async () => ({
...prisonerSentenceDetailsMock,
sentenceDetail: {
...sentenceDetail,
sentenceExpiryDate: '2016-02-02',
licenceExpiryDate: '2016-02-02',
},
}))
const offencesPageService = offencesPageServiceConstruct()
const res = await offencesPageService.getReleaseDates('token', '12345')
expect(res.sentenceExpiryDate).toBeUndefined()
expect(res.licenceExpiryDate).toBeUndefined()
expect(res.sentenceLicenceExpiryDate).toEqual(sentenceDetail.licenceExpiryDate)
})

it('should use none if none present', async () => {
prisonApiClient.getPrisonerSentenceDetails = jest.fn(async () => ({
...prisonerSentenceDetailsMock,
sentenceDetail: {
...sentenceDetail,
sentenceExpiryDate: undefined,
licenceExpiryDate: undefined,
},
}))
const offencesPageService = offencesPageServiceConstruct()
const res = await offencesPageService.getReleaseDates('token', '12345')
expect(res.sentenceExpiryDate).toBeUndefined()
expect(res.licenceExpiryDate).toBeUndefined()
expect(res.sentenceLicenceExpiryDate).toBeUndefined()
})
})
})
})
15 changes: 15 additions & 0 deletions server/services/offencesPageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
} from '../interfaces/prisonApi/sentenceSummary'
import { RestClientBuilder } from '../data'
import { ReleaseDates } from '../interfaces/releaseDates'
import { PrisonerSentenceDetails } from '../interfaces/prisonerSentenceDetails'

export default class OffencesPageService {
private prisonApiClient: PrisonApiClient
Expand Down Expand Up @@ -364,6 +365,19 @@ export default class OffencesPageService {
})
}

private getSedLedSled(sentenceDetails: PrisonerSentenceDetails['sentenceDetail']) {
if (
sentenceDetails.sentenceExpiryDate &&
sentenceDetails.licenceExpiryDate &&
sentenceDetails.sentenceExpiryDate === sentenceDetails.licenceExpiryDate
)
return { sentenceLicenceExpiryDate: sentenceDetails.sentenceExpiryDate }

if (sentenceDetails.sentenceExpiryDate) return { sentenceExpiryDate: sentenceDetails.sentenceExpiryDate }
if (sentenceDetails.licenceExpiryDate) return { licenceExpiryDate: sentenceDetails.licenceExpiryDate }
return {}
}

async getReleaseDates(token: string, prisonerNumber: string): Promise<Partial<ReleaseDates>> {
this.prisonApiClient = this.prisonApiClient ? this.prisonApiClient : this.prisonApiClientBuilder(token)
const releaseDates = await this.prisonApiClient.getPrisonerSentenceDetails(prisonerNumber)
Expand Down Expand Up @@ -394,6 +408,7 @@ export default class OffencesPageService {
tariffEarlyRemovalSchemeEligibilityDate: sentenceDetails.tariffEarlyRemovalSchemeEligibilityDate,
topupSupervisionExpiryDate:
sentenceDetails.topupSupervisionExpiryOverrideDate || sentenceDetails.topupSupervisionExpiryDate,
...this.getSedLedSled(sentenceDetails),
}
return Object.keys(dates).reduce<Partial<ReleaseDates>>((dateObj, dateName) => {
if (!dates[dateName]) return dateObj
Expand Down
27 changes: 27 additions & 0 deletions server/views/dataUtils/releaseDatesToSummaryRows.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ describe('releaseDatesToSummaryRows.test.ts', () => {
tariffDate: '2016-01-29',
tariffEarlyRemovalSchemeEligibilityDate: '2016-01-28',
topupSupervisionExpiryDate: '2016-01-31',
sentenceExpiryDate: '2016-02-01',
licenceExpiryDate: '2016-02-02',
sentenceLicenceExpiryDate: '2016-02-03',
}

it('should return release dates object as summary rows', () => {
Expand Down Expand Up @@ -116,6 +119,14 @@ describe('releaseDatesToSummaryRows.test.ts', () => {
text: '16 January 2016',
},
},
{
key: {
text: 'License expiry date (LED)',
},
value: {
text: '2 February 2016',
},
},
{
key: {
text: 'Mid-term date (MTD)',
Expand Down Expand Up @@ -172,6 +183,22 @@ describe('releaseDatesToSummaryRows.test.ts', () => {
text: '27 January 2016',
},
},
{
key: {
text: 'Sentence and license expiry date (SLED)',
},
value: {
text: '3 February 2016',
},
},
{
key: {
text: 'Sentence expiry date (SED)',
},
value: {
text: '1 February 2016',
},
},
{
key: {
text: 'Tariff',
Expand Down
3 changes: 3 additions & 0 deletions server/views/dataUtils/releaseDatesToSummaryRows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ const labels: Record<keyof ReleaseDates, string> = {
tariffDate: 'Tariff',
tariffEarlyRemovalSchemeEligibilityDate: 'Tariff Expired Removal Scheme eligibility date (TERSED)',
topupSupervisionExpiryDate: 'Top-up supervision expiry date (TUSED)',
sentenceExpiryDate: 'Sentence expiry date (SED)',
licenceExpiryDate: 'License expiry date (LED)',
sentenceLicenceExpiryDate: 'Sentence and license expiry date (SLED)',
}
export default (releaseDates: ReleaseDates): SummaryRow[] => {
return Object.keys(releaseDates)
Expand Down

0 comments on commit 5e5d66d

Please sign in to comment.