From 3f698a7704c69b8a0837370aafcf361ce3c3eeb2 Mon Sep 17 00:00:00 2001 From: James Grant Date: Wed, 5 Jul 2023 12:42:30 +0100 Subject: [PATCH 1/2] CDPS-256 - fix for pods restarting --- server/services/offencesPage.test.ts | 30 ---------------- server/services/offencesPageService.ts | 49 ++------------------------ 2 files changed, 3 insertions(+), 76 deletions(-) diff --git a/server/services/offencesPage.test.ts b/server/services/offencesPage.test.ts index 0d84416af..89420694c 100644 --- a/server/services/offencesPage.test.ts +++ b/server/services/offencesPage.test.ts @@ -192,36 +192,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) diff --git a/server/services/offencesPageService.ts b/server/services/offencesPageService.ts index d41a3bb8e..1751c70f9 100644 --- a/server/services/offencesPageService.ts +++ b/server/services/offencesPageService.ts @@ -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()] } @@ -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, @@ -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) } } From e96a7653e03617eb93304112d6b75d2ea634fc56 Mon Sep 17 00:00:00 2001 From: James Grant Date: Wed, 5 Jul 2023 12:48:24 +0100 Subject: [PATCH 2/2] CDPS-256 - removed unused imports --- server/services/offencesPage.test.ts | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/server/services/offencesPage.test.ts b/server/services/offencesPage.test.ts index 89420694c..00e3864d8 100644 --- a/server/services/offencesPage.test.ts +++ b/server/services/offencesPage.test.ts @@ -8,8 +8,6 @@ import { CourtCasesUnsentencedMockA, CourtCasesUnsentencedMockB, CourtCaseWithNextCourtAppearance, - SentenceTermsWithOffences, - SentenceTermsWithoutOffences, } from '../data/localMockData/courtCaseMock' import { OffenceHistoryMock, OffenceHistoryMockA } from '../data/localMockData/offenceHistoryMock' import { @@ -18,7 +16,6 @@ import { MappedUnsentencedCourtCasesMock, SentencedTermsMockA, sentenceTermsMock, - SummaryDetailRowsMock, } from '../data/localMockData/sentenceTermsMock' import { prisonerSentenceDetailsMock } from '../data/localMockData/prisonerSentenceDetails' import { @@ -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