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

CDPS-256 pods restarting #210

Merged
merged 2 commits into from
Jul 5, 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
38 changes: 1 addition & 37 deletions server/services/offencesPage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ import {
CourtCasesUnsentencedMockA,
CourtCasesUnsentencedMockB,
CourtCaseWithNextCourtAppearance,
SentenceTermsWithOffences,
SentenceTermsWithoutOffences,
} from '../data/localMockData/courtCaseMock'
import { OffenceHistoryMock, OffenceHistoryMockA } from '../data/localMockData/offenceHistoryMock'
import {
Expand All @@ -18,7 +16,6 @@ import {
MappedUnsentencedCourtCasesMock,
SentencedTermsMockA,
sentenceTermsMock,
SummaryDetailRowsMock,
} from '../data/localMockData/sentenceTermsMock'
import { prisonerSentenceDetailsMock } from '../data/localMockData/prisonerSentenceDetails'
import {
Expand All @@ -34,10 +31,7 @@ import {
CourtDateResultsUnsentencedMockB,
UniqueCourtDateResultsUnsentencedMockA,
} from '../data/localMockData/courtDateResultsMock'
import {
SentenceSummaryWithSentenceMock,
SentenceSummaryWithoutSentenceMock,
} from '../data/localMockData/sentenceSummaryMock'
import { SentenceSummaryWithSentenceMock } from '../data/localMockData/sentenceSummaryMock'

describe('OffencesPageService', () => {
let prisonApiClient: PrisonApiClient
Expand Down Expand Up @@ -192,36 +186,6 @@ describe('OffencesPageService', () => {
expect(res).toEqual(OffenceHistoryMockA)
})

it('Get summary detail rows', async () => {
const offencesPageService = offencesPageServiceConstruct()
const res = await offencesPageService.getSummaryDetailRow(SentencedTermsMockA[0], SentencedTermsMockA)
expect(res).toEqual(SummaryDetailRowsMock)
})

it('Get sentence terms - data with offences', async () => {
const offencesPageService = offencesPageServiceConstruct()
const res = await offencesPageService.getSentenceTerms(
CourtCasesSentencedMockA[0],
SentencedTermsMockA,
OffenceHistoryMockA,
CourtDateResultsMockA,
SentenceSummaryWithSentenceMock,
)
expect(res).toEqual(SentenceTermsWithOffences)
})

it('Get sentence terms - data without offences', async () => {
const offencesPageService = offencesPageServiceConstruct()
const res = await offencesPageService.getSentenceTerms(
CourtCasesSentencedMockA[0],
SentencedTermsMockA,
OffenceHistoryMock,
CourtDateResultsMockA,
SentenceSummaryWithoutSentenceMock,
)
expect(res).toEqual(SentenceTermsWithoutOffences)
})

it('Get generic maps', async () => {
const offencesPageService = offencesPageServiceConstruct()
const res = await offencesPageService.getGenericMaps(CourtCasesSentencedMockA[0], todaysDate)
Expand Down
49 changes: 3 additions & 46 deletions server/services/offencesPageService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -246,50 +246,6 @@ export default class OffencesPageService {
]
}

getSummaryDetailRow(sentence: OffenderSentenceTerms, sentenceTermsData: OffenderSentenceTerms[]) {
return [
{
label: 'Sentence date',
value: formatDate(sentence.sentenceStartDate && sentence.sentenceStartDate, 'long'),
},
{
label: 'Length',
value: this.getLengthTextLabels(sentence),
},
{
label: 'Concurrent or consecutive',
value: this.findConsecutiveSentence({
sentences: sentenceTermsData,
consecutiveTo: sentence.consecutiveTo,
}),
},
// @ts-expect-error ts-migrate(2554) FIXME: Expected 2 arguments, but got 1.
sentence.fineAmount && { label: 'Fine', value: formatCurrency(sentence.fineAmount) },
sentence.licence && {
label: 'Licence',
value: this.getLengthTextLabels(sentence.licence),
},
]
}

getSentenceTerms(
courtCase: CourtCase,
sentenceTermsData: OffenderSentenceTerms[],
offenceHistory: OffenceHistoryDetail[],
courtDateResults: CourtDateResults[],
sentenceSummary: SentenceSummary,
) {
return this.groupSentencesBySequence(sentenceTermsData)
.filter((group: GroupedSentence) => Number(group.caseId) === courtCase.id)
.map((groupedSentence: GroupedSentence) => this.mergeMostRecentLicenceTerm(groupedSentence.items))
.map((sentence: OffenderSentenceTerms) => ({
sentenceHeader: this.getCountForSentencedCourtCase(sentence),
sentenceTypeDescription: sentence.sentenceTypeDescription,
summaryDetailRows: this.getSummaryDetailRow(sentence, sentenceTermsData),
offences: this.getOffences(courtCase, offenceHistory, courtDateResults, sentenceSummary),
}))
}

getUniqueChargesFromCourtDateResults(courtDateResults: CourtDateResults[]) {
return [...new Map(courtDateResults?.map(item => [item.charge.chargeId, item])).values()]
}
Expand Down Expand Up @@ -378,7 +334,8 @@ export default class OffencesPageService {
sentenceValue.sentenceStartDate && sentenceValue.sentenceStartDate,
'long',
)
sentenceValue.sentenceLength = this.getLengthTextLabels(sentenceValue.terms[0])
sentenceValue.sentenceLength =
sentenceValue && sentenceValue.terms ? this.getLengthTextLabels(sentenceValue.terms[0]) : undefined
sentenceValue.concurrentConsecutive = this.findConsecutiveSentence({
sentences: sentenceTermsData,
consecutiveTo: sentenceValue.consecutiveToSequence,
Expand All @@ -392,7 +349,7 @@ export default class OffencesPageService {
Number(term.caseId) === courtSentence.id &&
sentenceValue.sentenceTypeDescription === term.sentenceTypeDescription
) {
if (term.licence) {
if (term && term.licence) {
sentenceValue.sentenceLicence = this.getLengthTextLabels(term.licence)
}
}
Expand Down