Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust1 304 filter sentences #121

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/generate-prison-api-types.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
npx openapi-typescript https://api-dev.prison.service.justice.gov.uk/v3/api-docs > ../server/@types/prisonApi/index.d.ts
npx openapi-typescript https://prison-api-dev.prison.service.justice.gov.uk/v3/api-docs > ../server/@types/prisonApi/index.d.ts
15,946 changes: 7,255 additions & 8,691 deletions server/@types/prisonApi/index.d.ts

Large diffs are not rendered by default.

6 changes: 0 additions & 6 deletions server/@types/prisonApi/prisonClientTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,8 @@ import { components } from './index'

export type PrisonApiPrisoner = components['schemas']['InmateDetail']
export type PrisonApiUserCaseloads = components['schemas']['CaseLoad']
export type PrisonApiSentence = components['schemas']['Sentence']
export type PrisonApiCharge = components['schemas']['Charge']
export type PrisonApiCourtCase = components['schemas']['CourtCase']
export type PrisonApiAdjustment = components['schemas']['Adjustment']
export type PrisonApiCourtDateResult = components['schemas']['CourtDateResult']
export type PrisonApiBookingAndSentenceAdjustments = components['schemas']['BookingAndSentenceAdjustments']
export type PrisonApiSentenceAdjustments = components['schemas']['SentenceAdjustmentValues']
export type PrisonApiAdjudicationSearchResponse = components['schemas']['AdjudicationSearchResponse']
export type PrisonApiAdjudication = components['schemas']['AdjudicationDetail']
export type PrisonApiOffenderSentenceAndOffences = components['schemas']['OffenderSentenceAndOffences']
export type PrisonApiOffence = components['schemas']['OffenderOffence']
46 changes: 0 additions & 46 deletions server/api/prisonApiClient.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import config, { ApiConfig } from '../config'
import RestClient from '../data/restClient'
import type {
PrisonApiAdjudication,
PrisonApiAdjudicationSearchResponse,
PrisonApiAdjustment,
PrisonApiBookingAndSentenceAdjustments,
PrisonApiCharge,
PrisonApiCourtCase,
PrisonApiCourtDateResult,
PrisonApiOffenderSentenceAndOffences,
PrisonApiPrisoner,
PrisonApiSentence,
PrisonApiUserCaseloads,
} from '../@types/prisonApi/prisonClientTypes'

Expand All @@ -29,46 +23,6 @@ export default class PrisonApiClient {
return this.restClient.get({ path: `/api/users/me/caseLoads` }) as Promise<PrisonApiUserCaseloads[]>
}

async getAdjudications(nomsId: string): Promise<PrisonApiAdjudicationSearchResponse> {
return this.restClient.get({
path: `/api/offenders/${nomsId}/adjudications?finding=PROVED`, // TODO filter by date
}) as Promise<PrisonApiAdjudicationSearchResponse>
}

async getAdjudication(nomsId: string, adjudationNumber: number): Promise<PrisonApiAdjudication> {
return this.restClient.get({
path: `/api/offenders/${nomsId}/adjudications/${adjudationNumber}`,
}) as Promise<PrisonApiAdjudication>
}

async createCourtCase(bookingId: number, courtCase: PrisonApiCourtCase): Promise<number> {
return this.restClient.post({
path: `/api/digital-warrant/booking/${bookingId}/court-case`,
data: courtCase,
}) as Promise<number>
}

async createCharge(bookingId: number, charge: PrisonApiCharge): Promise<number> {
return this.restClient.post({
path: `/api/digital-warrant/booking/${bookingId}/charge`,
data: charge,
}) as Promise<number>
}

async createSentence(bookingId: number, sentence: PrisonApiSentence): Promise<number> {
return this.restClient.post({
path: `/api/digital-warrant/booking/${bookingId}/sentence`,
data: sentence,
}) as Promise<number>
}

async createAdjustment(bookingId: number, sentence: PrisonApiAdjustment): Promise<number> {
return this.restClient.post({
path: `/api/digital-warrant/booking/${bookingId}/adjustment`,
data: sentence,
}) as Promise<number>
}

async getCourtDateResults(nomsId: string): Promise<PrisonApiCourtDateResult[]> {
return this.restClient.get({
path: `/api/digital-warrant/court-date-results/${nomsId}`,
Expand Down
55 changes: 0 additions & 55 deletions server/model/additionalDaysModel.ts

This file was deleted.

17 changes: 0 additions & 17 deletions server/routes/adjustmentRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import PrisonerService from '../services/prisonerService'
import AdjustmentsService from '../services/adjustmentsService'
import AdjustmentsHubViewModel, { Message } from '../model/adjustmentsHubViewModel'
import config from '../config'
import AdditionalDaysModel from '../model/additionalDaysModel'
import ReviewModel from '../model/reviewModel'
import AdjustmentsStoreService from '../services/adjustmentsStoreService'
import WarningModel from '../model/warningModel'
Expand Down Expand Up @@ -106,22 +105,6 @@ export default class AdjustmentRoutes {
return res.redirect(`${config.services.identifyRemandPeriods.url}/${nomsId}`)
}

public additionalDays: RequestHandler = async (req, res): Promise<void> => {
const { caseloads, token } = res.locals.user
const { nomsId } = req.params
const prisonerDetail = await this.prisonerService.getPrisonerDetail(nomsId, caseloads, token)
const adjudicationsSearch = await this.prisonerService.getAdjudications(nomsId, token)
const adjudications = await Promise.all(
adjudicationsSearch.results.map(adj =>
this.prisonerService.getAdjudication(nomsId, adj.adjudicationNumber, token),
),
)

return res.render('pages/adjustments/additionalDays', {
model: new AdditionalDaysModel(prisonerDetail, adjudications),
})
}

public form: RequestHandler = async (req, res): Promise<void> => {
const { caseloads, token } = res.locals.user
const { nomsId, adjustmentTypeUrl, addOrEdit, id } = req.params
Expand Down
3 changes: 1 addition & 2 deletions server/routes/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ export default function routes(service: Services): Router {
get('/:nomsId/remand/remove/:id', remandRoutes.remove)
get('/:nomsId/remand/edit/:id', remandRoutes.edit)
post('/:nomsId/remand/edit/:id', remandRoutes.submitEdit)
get('/:nomsId/remand/no-applicable-sentences', remandRoutes.noApplicableSentences)

get('/:nomsId/:adjustmentTypeUrl/view', adjustmentRoutes.view)
get('/:nomsId/:adjustmentTypeUrl/remove/:id', adjustmentRoutes.remove)
Expand All @@ -78,7 +79,5 @@ export default function routes(service: Services): Router {
post('/:nomsId/:adjustmentTypeUrl/:addOrEdit/:id', adjustmentRoutes.submitForm)

get('/:nomsId/remand', adjustmentRoutes.remand)
get('/:nomsId/additional-days/add', adjustmentRoutes.additionalDays)

return router
}
62 changes: 52 additions & 10 deletions server/routes/remandRoutes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,57 @@ afterEach(() => {
})

describe('Adjustment routes tests', () => {
it('GET /{nomsId}/remand/add', () => {
it('GET /{nomsId}/remand/add okay', () => {
prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData)
adjustmentsStoreService.store.mockReturnValue(SESSION_ID)
prisonerService.getSentencesAndOffencesFilteredForRemand.mockResolvedValue(stubbedSentencesAndOffences)
return request(app)
.get(`/${NOMS_ID}/remand/add`)
.expect(302)
.expect('Location', `/${NOMS_ID}/remand/dates/add/${SESSION_ID}`)
})

it('GET /{nomsId}/remand/add no applicable', () => {
prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData)
prisonerService.getSentencesAndOffencesFilteredForRemand.mockResolvedValue([])
return request(app)
.get(`/${NOMS_ID}/remand/add`)
.expect(302)
.expect('Location', `/${NOMS_ID}/remand/no-applicable-sentences`)
})

it('GET /{nomsId}/remand/no-applicable-sentences', () => {
prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData)
return request(app)
.get(`/${NOMS_ID}/remand/no-applicable-sentences`)
.expect('Content-Type', /html/)
.expect(res => {
expect(res.text).toContain('Anon')
expect(res.text).toContain('Nobody')
expect(res.text).toContain(`<a href="/${NOMS_ID}" class="govuk-back-link">Back</a>`)
expect(res.text).toContain('Remand cannot be applied as none of the sentence offences are eligible for remand.')
})
})

it('GET /{nomsId}/remand/dates/add', () => {
const adjustments = {}
adjustments[SESSION_ID] = blankAdjustment
prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData)
adjustmentsStoreService.getAll.mockReturnValue(adjustments)
adjustmentsStoreService.getById.mockReturnValue(blankAdjustment)
return request(app)
.get(`/${NOMS_ID}/remand/dates/add/${SESSION_ID}`)
.expect('Content-Type', /html/)
.expect(res => {
expect(res.text).toContain('Anon')
expect(res.text).toContain('Nobody')
expect(res.text).toContain(`<a href="/${NOMS_ID}" class="govuk-back-link">Back</a>`)
expect(res.text).toContain('Remand start date')
expect(res.text).toContain('Remand end date')
expect(res.text).toContain('Continue')
})
})

describe('POST /{nomsId}/remand/dates/:addOrEdit validation tests', () => {
test.each`
addOrEdit | redirectLocation
Expand Down Expand Up @@ -219,7 +261,7 @@ describe('Adjustment routes tests', () => {
const adjustments = {}
adjustments[SESSION_ID] = blankAdjustment
prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData)
prisonerService.getSentencesAndOffences.mockResolvedValue(stubbedSentencesAndOffences)
prisonerService.getSentencesAndOffencesFilteredForRemand.mockResolvedValue(stubbedSentencesAndOffences)
adjustmentsStoreService.getById.mockReturnValue(adjustmentWithDates)
return request(app)
.get(`/${NOMS_ID}/remand/offences/${addOrEdit}/${SESSION_ID}`)
Expand Down Expand Up @@ -264,7 +306,7 @@ describe('Adjustment routes tests', () => {
${'edit'}
`('POST /{nomsId}/remand/offence/:addOrEdit no offences selected', async ({ addOrEdit }) => {
prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData)
prisonerService.getSentencesAndOffences.mockResolvedValue(stubbedSentencesAndOffences)
prisonerService.getSentencesAndOffencesFilteredForRemand.mockResolvedValue(stubbedSentencesAndOffences)
adjustmentsStoreService.getById.mockReturnValue(adjustmentWithDates)
return request(app)
.post(`/${NOMS_ID}/remand/offences/${addOrEdit}/${SESSION_ID}`)
Expand All @@ -280,7 +322,7 @@ describe('Adjustment routes tests', () => {
const adjustments = {}
adjustments[SESSION_ID] = adjustmentWithDatesAndCharges
prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData)
prisonerService.getSentencesAndOffences.mockResolvedValue(stubbedSentencesAndOffences)
prisonerService.getSentencesAndOffencesFilteredForRemand.mockResolvedValue(stubbedSentencesAndOffences)
adjustmentsService.findByPerson.mockResolvedValue([])
calculateReleaseDatesService.calculateUnusedDeductions.mockResolvedValue({
unusedDeductions: 50,
Expand Down Expand Up @@ -343,7 +385,7 @@ describe('Adjustment routes tests', () => {
const adjustments = {}
adjustments[SESSION_ID] = adjustmentWithDatesAndCharges
prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData)
prisonerService.getSentencesAndOffences.mockResolvedValue(stubbedSentencesAndOffences)
prisonerService.getSentencesAndOffencesFilteredForRemand.mockResolvedValue(stubbedSentencesAndOffences)
adjustmentsStoreService.getAll.mockReturnValue(adjustments)
return request(app)
.post(`/${NOMS_ID}/remand/review`)
Expand All @@ -357,7 +399,7 @@ describe('Adjustment routes tests', () => {
const adjustments = {}
adjustments[SESSION_ID] = adjustmentWithDatesAndCharges
prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData)
prisonerService.getSentencesAndOffences.mockResolvedValue(stubbedSentencesAndOffences)
prisonerService.getSentencesAndOffencesFilteredForRemand.mockResolvedValue(stubbedSentencesAndOffences)
adjustmentsService.findByPerson.mockResolvedValue([])
calculateReleaseDatesService.calculateUnusedDeductions.mockResolvedValue({
unusedDeductions: 50,
Expand Down Expand Up @@ -385,7 +427,7 @@ describe('Adjustment routes tests', () => {
const adjustments = {}
adjustments[SESSION_ID] = adjustmentWithDatesAndCharges
prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData)
prisonerService.getSentencesAndOffences.mockResolvedValue(stubbedSentencesAndOffences)
prisonerService.getSentencesAndOffencesFilteredForRemand.mockResolvedValue(stubbedSentencesAndOffences)
adjustmentsService.findByPerson.mockResolvedValue([])
calculateReleaseDatesService.calculateUnusedDeductions.mockRejectedValue({ error: 'an error' })
adjustmentsStoreService.getAll.mockReturnValue(adjustments)
Expand All @@ -409,7 +451,7 @@ describe('Adjustment routes tests', () => {

it('GET /{nomsId}/remand/remove', () => {
prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData)
prisonerService.getSentencesAndOffences.mockResolvedValue(stubbedSentencesAndOffences)
prisonerService.getSentencesAndOffencesFilteredForRemand.mockResolvedValue(stubbedSentencesAndOffences)
adjustmentsService.get.mockResolvedValue(adjustmentWithDatesAndCharges)

return request(app)
Expand All @@ -427,7 +469,7 @@ describe('Adjustment routes tests', () => {

it('POST /{nomsId}/remand/remove', () => {
prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData)
prisonerService.getSentencesAndOffences.mockResolvedValue(stubbedSentencesAndOffences)
prisonerService.getSentencesAndOffencesFilteredForRemand.mockResolvedValue(stubbedSentencesAndOffences)
adjustmentsService.get.mockResolvedValue(adjustmentWithDatesAndCharges)

return request(app)
Expand All @@ -438,7 +480,7 @@ describe('Adjustment routes tests', () => {

it('GET /{nomsId}/remand/edit', () => {
prisonerService.getPrisonerDetail.mockResolvedValue(stubbedPrisonerData)
prisonerService.getSentencesAndOffences.mockResolvedValue(stubbedSentencesAndOffences)
prisonerService.getSentencesAndOffencesFilteredForRemand.mockResolvedValue(stubbedSentencesAndOffences)
adjustmentsService.get.mockResolvedValue(adjustmentWithDatesAndCharges)

return request(app)
Expand Down
Loading