generated from ministryofjustice/hmpps-template-typescript
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ADJUST-21 create new rada * ADJUST1-24 linting. * ADJUST1-24 linting.
- Loading branch information
Showing
17 changed files
with
462 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
.review-list { | ||
.review-item { | ||
display:block; | ||
background-color: #f8f8f8; | ||
padding:20px; | ||
//border-left: 4px solid #6f72af; | ||
border-left: 4px solid #ccc; | ||
border-bottom:1px solid #ccc; | ||
margin-bottom: 2em; | ||
|
||
&.ng { | ||
border-left: 4px solid #ccc; | ||
} | ||
a { | ||
padding-left:10px; | ||
} | ||
|
||
ul { | ||
margin-left:0; | ||
padding-left:10px; | ||
} | ||
|
||
.govuk-table__cell, .govuk-table__header { | ||
border-bottom: none; | ||
padding-bottom: 0; | ||
} | ||
|
||
.govuk-button--secondary:visited, .govuk-button--secondary:active, .govuk-button--secondary:hover { | ||
color: #0b0c0c !important; | ||
} | ||
|
||
.govuk-summary-list__value { | ||
width:66%; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import dayjs from 'dayjs' | ||
import { AdjustmentDetails } from '../@types/adjustments/adjustmentsTypes' | ||
import { dateItems } from '../utils/utils' | ||
|
||
export default class RestoredAdditionalDaysForm { | ||
constructor(params: Partial<RestoredAdditionalDaysForm>) { | ||
Object.assign(this, params) | ||
} | ||
|
||
'from-day': string | ||
|
||
'from-month': string | ||
|
||
'from-year': string | ||
|
||
days: string | ||
|
||
fromItems() { | ||
return dateItems(this['from-year'], this['from-month'], this['from-day']) | ||
} | ||
|
||
static fromAdjustment(adjustment: AdjustmentDetails): RestoredAdditionalDaysForm { | ||
return new RestoredAdditionalDaysForm({ | ||
'from-day': dayjs(adjustment.fromDate).get('date').toString(), | ||
'from-month': (dayjs(adjustment.fromDate).get('month') + 1).toString(), | ||
'from-year': dayjs(adjustment.fromDate).get('year').toString(), | ||
days: adjustment.days.toString(), | ||
}) | ||
} | ||
|
||
toAdjustmentDetails(bookingId: number, nomsId: string): AdjustmentDetails { | ||
return { | ||
adjustmentType: 'RESTORATION_OF_ADDITIONAL_DAYS_AWARDED', | ||
bookingId, | ||
fromDate: dayjs() | ||
.set('date', Number(this['from-day'])) | ||
.set('month', Number(this['from-month']) - 1) | ||
.set('year', Number(this['from-year'])) | ||
.format('YYYY-MM-DD'), | ||
toDate: null, | ||
person: nomsId, | ||
days: Number(this.days), | ||
sentenceSequence: null, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { PrisonApiPrisoner } from '../@types/prisonApi/prisonClientTypes' | ||
import { AdjustmentDetails } from '../@types/adjustments/adjustmentsTypes' | ||
import adjustmentTypes, { AdjustmentType } from './adjustmentTypes' | ||
|
||
export default class ReviewModel { | ||
constructor(public prisonerDetail: PrisonApiPrisoner, public adjustments: AdjustmentDetails[]) {} | ||
|
||
adjustmentType(adjustment: AdjustmentDetails): AdjustmentType { | ||
return adjustmentTypes.find(it => it.value === adjustment.adjustmentType) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
import type { Express } from 'express' | ||
import request from 'supertest' | ||
import { appWithAllRoutes } from './testutils/appSetup' | ||
import PrisonerService from '../services/prisonerService' | ||
import AdjustmentsService from '../services/adjustmentsService' | ||
import { PrisonApiPrisoner } from '../@types/prisonApi/prisonClientTypes' | ||
import { AdjustmentDetails } from '../@types/adjustments/adjustmentsTypes' | ||
import IdentifyRemandPeriodsService from '../services/identifyRemandPeriodsService' | ||
import { Remand, RemandResult } from '../@types/identifyRemandPeriods/identifyRemandPeriodsTypes' | ||
import AdjustmentsStoreService from '../services/adjustmentsStoreService' | ||
|
||
jest.mock('../services/adjustmentsService') | ||
jest.mock('../services/prisonerService') | ||
jest.mock('../services/identifyRemandPeriodsService') | ||
jest.mock('../services/adjustmentsStoreService') | ||
|
||
const prisonerService = new PrisonerService(null) as jest.Mocked<PrisonerService> | ||
const adjustmentsService = new AdjustmentsService() as jest.Mocked<AdjustmentsService> | ||
const identifyRemandPeriodsService = new IdentifyRemandPeriodsService() as jest.Mocked<IdentifyRemandPeriodsService> | ||
const adjustmentsStoreService = new AdjustmentsStoreService() as jest.Mocked<AdjustmentsStoreService> | ||
|
||
const NOMS_ID = 'ABC123' | ||
|
||
const stubbedPrisonerData = { | ||
offenderNo: NOMS_ID, | ||
firstName: 'Anon', | ||
lastName: 'Nobody', | ||
dateOfBirth: '24/06/2000', | ||
bookingId: 12345, | ||
} as PrisonApiPrisoner | ||
|
||
const remandResult = { | ||
chargeRemand: [], | ||
sentenceRemand: [ | ||
{ | ||
days: 20, | ||
} as Remand, | ||
], | ||
} as RemandResult | ||
|
||
const radaAdjustment = { | ||
adjustmentType: 'RESTORATION_OF_ADDITIONAL_DAYS_AWARDED', | ||
toDate: null, | ||
fromDate: '2023-04-05', | ||
person: 'ABC123', | ||
days: 24, | ||
bookingId: 12345, | ||
sentenceSequence: null, | ||
} as AdjustmentDetails | ||
|
||
let app: Express | ||
|
||
beforeEach(() => { | ||
app = appWithAllRoutes({ | ||
services: { prisonerService, adjustmentsService, identifyRemandPeriodsService, adjustmentsStoreService }, | ||
}) | ||
}) | ||
|
||
afterEach(() => { | ||
jest.resetAllMocks() | ||
}) | ||
|
||
describe('Adjustment routes tests', () => { | ||
it('GET /{nomsId}', () => { | ||
prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) | ||
adjustmentsService.findByPerson.mockResolvedValue([{ id: '1', adjustment: radaAdjustment }]) | ||
identifyRemandPeriodsService.calculateRelevantRemand.mockResolvedValue(remandResult) | ||
return request(app) | ||
.get(`/${NOMS_ID}`) | ||
.expect('Content-Type', /html/) | ||
.expect(res => { | ||
expect(res.text).toContain('Anon') | ||
expect(res.text).toContain('Nobody') | ||
expect(res.text).toContain('Nobody may have 20 days remand') | ||
expect(res.text).toContain('24') | ||
}) | ||
}) | ||
|
||
it('GET /{nomsId}/restored-additional-days/add', () => { | ||
prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) | ||
return request(app) | ||
.get(`/${NOMS_ID}/restored-additional-days/add`) | ||
.expect('Content-Type', /html/) | ||
.expect(res => { | ||
expect(res.text).toContain('Anon') | ||
expect(res.text).toContain('Nobody') | ||
expect(res.text).toContain('Date of days restored') | ||
expect(res.text).toContain('Continue') | ||
}) | ||
}) | ||
|
||
it('POST /{nomsId}/restored-additional-days/add', () => { | ||
prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) | ||
return request(app) | ||
.post(`/${NOMS_ID}/restored-additional-days/add`) | ||
.send({ 'from-day': '5', 'from-month': '4', 'from-year': '2023', days: 24 }) | ||
.type('form') | ||
.expect(302) | ||
.expect('Location', `/${NOMS_ID}/review`) | ||
.expect(res => { | ||
expect(adjustmentsStoreService.store.mock.calls).toHaveLength(1) | ||
expect(adjustmentsStoreService.store.mock.calls[0][2]).toStrictEqual(radaAdjustment) | ||
}) | ||
}) | ||
|
||
it('GET /{nomsId}/review', () => { | ||
prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) | ||
adjustmentsStoreService.get.mockReturnValue([radaAdjustment]) | ||
|
||
return request(app) | ||
.get(`/${NOMS_ID}/review`) | ||
.expect('Content-Type', /html/) | ||
.expect(res => { | ||
expect(res.text).toContain('Anon') | ||
expect(res.text).toContain('Adjustment type') | ||
expect(res.text).toContain('Restore additional days awarded (RADA)') | ||
expect(res.text).toContain('Date of days restored') | ||
expect(res.text).toContain('05 April 2023') | ||
expect(res.text).toContain('Number of days') | ||
expect(res.text).toContain('24') | ||
expect(res.text).toContain('Accept and save') | ||
}) | ||
}) | ||
|
||
it('POST /{nomsId}/review', () => { | ||
prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData) | ||
adjustmentsStoreService.get.mockReturnValue([radaAdjustment]) | ||
return request(app) | ||
.post(`/${NOMS_ID}/review`) | ||
.expect(302) | ||
.expect('Location', `/${NOMS_ID}`) | ||
.expect(res => { | ||
expect(adjustmentsService.create.mock.calls).toHaveLength(1) | ||
expect(adjustmentsService.create.mock.calls[0][0]).toStrictEqual(radaAdjustment) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.