Skip to content

Commit

Permalink
ADJST-759 LAL Confirm and Save (#419)
Browse files Browse the repository at this point in the history
  • Loading branch information
dave-virden authored Sep 25, 2024
1 parent 817a411 commit 835a8ff
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 6 deletions.
16 changes: 16 additions & 0 deletions server/@types/adjustments/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ export interface components {
remand?: components['schemas']['RemandDto']
additionalDaysAwarded?: components['schemas']['AdditionalDaysAwardedDto']
unlawfullyAtLarge?: components['schemas']['UnlawfullyAtLargeDto']
lawfullyAtLarge?: components['schemas']['LawfullyAtLargeDto']
taggedBail?: components['schemas']['TaggedBailDto']
/**
* Format: int32
Expand Down Expand Up @@ -278,6 +279,14 @@ export interface components {
*/
source?: 'NOMIS' | 'DPS'
}
/** @description The details of a LAL adjustment */
LawfullyAtLargeDto: {
/**
* @description The type of LAL
* @enum {string}
*/
affectsDates?: 'YES' | 'NO'
}
/** @description The details of remand adjustment */
RemandDto: {
/** @description The id of the charges this remand applies to */
Expand Down Expand Up @@ -341,6 +350,13 @@ export interface components {
| 'UAL_FIRST_DATE_CANNOT_BE_FUTURE'
| 'UAL_LAST_DATE_CANNOT_BE_FUTURE'
| 'UAL_DATE_MUST_BE_AFTER_SENTENCE_DATE'
| 'LAL_FROM_DATE_NOT_NULL'
| 'LAL_TO_DATE_NOT_NULL'
| 'LAL_FROM_DATE_AFTER_TO_DATE'
| 'LAL_AFFECTS_DATES_NOT_NULL'
| 'LAL_FIRST_DATE_CANNOT_BE_FUTURE'
| 'LAL_LAST_DATE_CANNOT_BE_FUTURE'
| 'LAL_DATE_MUST_BE_AFTER_SENTENCE_DATE'
arguments: string[]
message: string
/** @enum {string} */
Expand Down
1 change: 1 addition & 0 deletions server/model/adjustmentFormFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export default class AdjustmentsFormFactory {
'to-day': dayjs(adjustment.toDate).get('date').toString(),
'to-month': (dayjs(adjustment.toDate).get('month') + 1).toString(),
'to-year': dayjs(adjustment.toDate).get('year').toString(),
affectsDates: adjustment.lawfullyAtLarge?.affectsDates,
})
}

Expand Down
1 change: 1 addition & 0 deletions server/model/lawfullyAtLargeForm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export default class LawfullyAtLargeForm extends AdjustmentsForm<LawfullyAtLarge
fromDate,
toDate,
person: nomsId,
lawfullyAtLarge: { affectsDates: this.affectsDates },
prisonId: prisonerDetails.prisonId,
}
}
Expand Down
46 changes: 46 additions & 0 deletions server/model/reviewModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Adjustment } from '../@types/adjustments/adjustmentsTypes'
import adjustmentTypes, { AdjustmentType } from './adjustmentTypes'
import ualType from './ualType'
import { daysBetween, formatDate } from '../utils/utils'
import lalAffectsReleaseDates from './lalAffectsReleaseDates'

export default class ReviewModel {
constructor(public adjustment: Adjustment) {}
Expand Down Expand Up @@ -58,6 +59,9 @@ export default class ReviewModel {
if (adjustment.adjustmentType === 'UNLAWFULLY_AT_LARGE') {
return this.ualRows(adjustment, includeEdit)
}
if (adjustment.adjustmentType === 'LAWFULLY_AT_LARGE') {
return this.lalRows(adjustment, includeEdit)
}
return [
{
key: {
Expand Down Expand Up @@ -157,4 +161,46 @@ export default class ReviewModel {
},
]
}

private static lalRows(adjustment: Adjustment, includeEdit: boolean) {
const affectsDates = lalAffectsReleaseDates.find(it => it.value === adjustment.lawfullyAtLarge?.affectsDates)
return [
{
key: {
text: 'First day spent LAL',
},
value: {
text: formatDate(adjustment.fromDate),
},
...ReviewModel.editActions(adjustment, includeEdit, 'first day spent on LAL'),
},
{
key: {
text: 'Last day spent LAL',
},
value: {
text: formatDate(adjustment.toDate),
},
...ReviewModel.editActions(adjustment, includeEdit, 'last day spent on LAL'),
},
{
key: {
text: 'Number of days',
},
value: {
text: daysBetween(new Date(adjustment.fromDate), new Date(adjustment.toDate)),
},
...ReviewModel.editActions(adjustment, includeEdit, 'number of days'),
},
{
key: {
text: 'Delay release dates',
},
value: {
text: affectsDates ? affectsDates.text : 'Unknown',
},
...ReviewModel.editActions(adjustment, includeEdit, 'delay release dates'),
},
]
}
}
107 changes: 101 additions & 6 deletions server/routes/adjustmentRoutes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,23 @@ const adaAdjustment = {
} as Adjustment

const unlawfullyAtLargeAdjustment = {
id: '1',
id: '2',
adjustmentType: 'UNLAWFULLY_AT_LARGE',
toDate: '2023-06-05',
fromDate: '2023-04-05',
toDate: '2023-07-25',
fromDate: '2023-06-05',
unlawfullyAtLarge: { type: 'RECALL' },
person: 'ABC123',
bookingId: 12345,
sentenceSequence: null,
prisonId: 'LDS',
} as Adjustment

const lawfullyAtLargeAdjustment = {
id: '3',
adjustmentType: 'LAWFULLY_AT_LARGE',
toDate: '2023-09-05',
fromDate: '2023-07-05',
lawfullyAtLarge: { affectsDates: 'YES' },
person: 'ABC123',
bookingId: 12345,
sentenceSequence: null,
Expand Down Expand Up @@ -411,7 +424,7 @@ describe('Adjustment routes tests', () => {
})
})

it('GET /{nomsId}/review', () => {
it('GET /{nomsId}/review RADA', () => {
adjustmentsStoreService.getOnly.mockReturnValue(radaAdjustment)

return request(app)
Expand All @@ -428,6 +441,48 @@ describe('Adjustment routes tests', () => {
})
})

it('GET /{nomsId}/review UAL', () => {
adjustmentsStoreService.getOnly.mockReturnValue(unlawfullyAtLargeAdjustment)

return request(app)
.get(`/${NOMS_ID}/review`)
.expect('Content-Type', /html/)
.expect(res => {
expect(res.text).toContain('Anon')
expect(res.text).toContain('First day spent UAL')
expect(res.text).toContain('Last day spent UAL')
expect(res.text).toContain('5 Jun 2023')
expect(res.text).toContain('25 Jul 2023')
expect(res.text).toContain('Number of days')
expect(res.text).toContain('51')
expect(res.text).toContain('Type of UAL')
expect(res.text).toContain('Recall')
expect(res.text).toContain('Confirm and save')
expect(res.text).toContain(`/${NOMS_ID}/unlawfully-at-large/edit`)
})
})

it('GET /{nomsId}/review LAL', () => {
adjustmentsStoreService.getOnly.mockReturnValue(lawfullyAtLargeAdjustment)

return request(app)
.get(`/${NOMS_ID}/review`)
.expect('Content-Type', /html/)
.expect(res => {
expect(res.text).toContain('Anon')
expect(res.text).toContain('First day spent LAL')
expect(res.text).toContain('Last day spent LAL')
expect(res.text).toContain('5 Jul 2023')
expect(res.text).toContain('5 Sep 2023')
expect(res.text).toContain('Number of days')
expect(res.text).toContain('61')
expect(res.text).toContain('Delay release dates')
expect(res.text).toContain('Yes')
expect(res.text).toContain('Confirm and save')
expect(res.text).toContain(`/${NOMS_ID}/lawfully-at-large/edit`)
})
})

it('POST /{nomsId}/review', () => {
adjustmentsStoreService.getOnly.mockReturnValue({ ...radaAdjustment, id: undefined })
adjustmentsService.create.mockResolvedValue({ adjustmentIds: ['this-is-an-id'] })
Expand All @@ -444,7 +499,7 @@ describe('Adjustment routes tests', () => {
expect(adjustmentsService.create.mock.calls[0][0]).toStrictEqual([{ ...radaAdjustment, id: undefined }])
})
})
it('POST /{nomsId}/review with a adjustment with an id', () => {
it('POST /{nomsId}/review with a rada adjustment with an id', () => {
adjustmentsStoreService.getOnly.mockReturnValue({ ...radaAdjustment, id: 'this-is-an-id' })
adjustmentsService.get.mockResolvedValue({ ...radaAdjustment, id: 'this-is-an-id' })
return request(app)
Expand All @@ -464,6 +519,46 @@ describe('Adjustment routes tests', () => {
})
})

it('POST /{nomsId}/review with a UAL adjustment with an id', () => {
adjustmentsStoreService.getOnly.mockReturnValue({ ...unlawfullyAtLargeAdjustment, id: 'this-is-an-id' })
adjustmentsService.get.mockResolvedValue({ ...lawfullyAtLargeAdjustment, id: 'this-is-an-id' })
return request(app)
.post(`/${NOMS_ID}/review`)
.expect(302)
.expect(
'Location',
`/${NOMS_ID}/success?message=%7B%22type%22:%22UNLAWFULLY_AT_LARGE%22,%22days%22:51,%22action%22:%22UPDATE%22%7D`,
)
.expect(res => {
expect(adjustmentsService.update.mock.calls).toHaveLength(1)
expect(adjustmentsService.update.mock.calls[0][0]).toStrictEqual('this-is-an-id')
expect(adjustmentsService.update.mock.calls[0][1]).toStrictEqual({
...unlawfullyAtLargeAdjustment,
id: 'this-is-an-id',
})
})
})

it('POST /{nomsId}/review with a LAL adjustment with an id', () => {
adjustmentsStoreService.getOnly.mockReturnValue({ ...lawfullyAtLargeAdjustment, id: 'this-is-an-id' })
adjustmentsService.get.mockResolvedValue({ ...lawfullyAtLargeAdjustment, id: 'this-is-an-id' })
return request(app)
.post(`/${NOMS_ID}/review`)
.expect(302)
.expect(
'Location',
`/${NOMS_ID}/success?message=%7B%22type%22:%22LAWFULLY_AT_LARGE%22,%22days%22:63,%22action%22:%22UPDATE%22%7D`,
)
.expect(res => {
expect(adjustmentsService.update.mock.calls).toHaveLength(1)
expect(adjustmentsService.update.mock.calls[0][0]).toStrictEqual('this-is-an-id')
expect(adjustmentsService.update.mock.calls[0][1]).toStrictEqual({
...lawfullyAtLargeAdjustment,
id: 'this-is-an-id',
})
})
})

it('GET /{nomsId}/{adjustmentType}/view', () => {
adjustmentsService.findByPerson.mockResolvedValue([
{ ...radaAdjustment, id: 'this-is-an-id', lastUpdatedBy: 'Doris McNealy', status: 'ACTIVE', prisonName: 'Leeds' },
Expand Down Expand Up @@ -701,7 +796,7 @@ describe('Adjustment routes tests', () => {
'to-day': '20',
'to-month': '3',
'to-year': '2023',
type: 'IMMIGRATION_DETENTION',
affectedDates: 'YES',
})
.type('form')
.expect('Content-Type', /html/)
Expand Down

0 comments on commit 835a8ff

Please sign in to comment.