From 5e45720c1f2b92c611fede1823aa9dbfb86f84ed Mon Sep 17 00:00:00 2001 From: mg-moj Date: Tue, 21 Jan 2025 15:17:38 +0000 Subject: [PATCH] crs-1956-nomis-override-date-hints (#872) Change getNomisCalculationSummary to use an updated CRD endpoint for retrieving Nomis calculation with override dates. It's necessary to pass the bookingId in order to obtain override dates. --- .../calculateReleaseDatesApiClient.test.ts | 15 +++++++++---- server/api/calculateReleaseDatesApiClient.ts | 4 ++-- server/routes/viewRoutes.ts | 1 + .../calculateReleaseDatesService.test.ts | 21 +++++++++++-------- .../services/calculateReleaseDatesService.ts | 8 +++++-- 5 files changed, 32 insertions(+), 17 deletions(-) diff --git a/server/api/calculateReleaseDatesApiClient.test.ts b/server/api/calculateReleaseDatesApiClient.test.ts index 858ed2f5..4e3ce351 100644 --- a/server/api/calculateReleaseDatesApiClient.test.ts +++ b/server/api/calculateReleaseDatesApiClient.test.ts @@ -55,16 +55,23 @@ describe('Calculate release dates API client tests', () => { describe('Get nomis calculation summary for prisoner', () => { it('Get nomis calculation summary for offenderSentCalcId fails with 404 and throws Error', async () => { - fakeApi.get(`/calculation/nomis-calculation-summary/${offenderSentCalcId}`, '').reply(404) + const bookingId = 123456 + fakeApi + .get(`/calculation/nomis-calculation-summary/booking/${bookingId}/calculation/${offenderSentCalcId}`, '') + .reply(404) const client = new CalculateReleaseDatesApiClient(token) - await expect(client.getNomisCalculationSummary(offenderSentCalcId)).rejects.toThrow('Not Found') + await expect(client.getNomisCalculationSummary(offenderSentCalcId, bookingId)).rejects.toThrow('Not Found') }) it('Get nomis calculation summary for offenderSentCalcId successfully', async () => { + const bookingId = 123456 fakeApi - .get(`/calculation/nomis-calculation-summary/${offenderSentCalcId}`, '') + .get(`/calculation/nomis-calculation-summary/booking/${bookingId}/calculation/${offenderSentCalcId}`, '') .reply(200, nomisCalculationSummary) - const data = await new CalculateReleaseDatesApiClient(token).getNomisCalculationSummary(offenderSentCalcId) + const data = await new CalculateReleaseDatesApiClient(token).getNomisCalculationSummary( + offenderSentCalcId, + bookingId, + ) expect(data).toEqual(nomisCalculationSummary) expect(nock.isDone()).toBe(true) }) diff --git a/server/api/calculateReleaseDatesApiClient.ts b/server/api/calculateReleaseDatesApiClient.ts index 5c0a9162..ea3f5b95 100644 --- a/server/api/calculateReleaseDatesApiClient.ts +++ b/server/api/calculateReleaseDatesApiClient.ts @@ -329,9 +329,9 @@ export default class CalculateReleaseDatesApiClient { }) as Promise } - getNomisCalculationSummary(offenderSentCalcId: number): Promise { + getNomisCalculationSummary(offenderSentCalcId: number, bookingId: number): Promise { return this.restClient.get({ - path: `/calculation/nomis-calculation-summary/${offenderSentCalcId}`, + path: `/calculation/nomis-calculation-summary/booking/${bookingId}/calculation/${offenderSentCalcId}`, }) as Promise } diff --git a/server/routes/viewRoutes.ts b/server/routes/viewRoutes.ts index 258f00e2..2f323a73 100644 --- a/server/routes/viewRoutes.ts +++ b/server/routes/viewRoutes.ts @@ -310,6 +310,7 @@ export default class ViewRoutes { const prisonerDetail = await this.prisonerService.getPrisonerDetail(nomsId, caseloads, token) const pastNomisCalculation = await this.calculateReleaseDatesService.getNomisCalculationSummary( offenderSentCalculationId, + prisonerDetail.bookingId, token, ) res.render( diff --git a/server/services/calculateReleaseDatesService.test.ts b/server/services/calculateReleaseDatesService.test.ts index f8d38b24..701ab935 100644 --- a/server/services/calculateReleaseDatesService.test.ts +++ b/server/services/calculateReleaseDatesService.test.ts @@ -175,18 +175,21 @@ describe('Calculate release dates service tests', () => { describe('Test nomis calculation summary', () => { it('asserting successful scenario', async () => { - fakeApi.get(`/calculation/nomis-calculation-summary/${offenderSentCalcId}`).reply(200, nomisCalculationSummary) - - const result = await calculateReleaseDatesService.getNomisCalculationSummary(offenderSentCalcId, token) - + const bookingId = 123456 + fakeApi + .get(`/calculation/nomis-calculation-summary/booking/${bookingId}/calculation/${offenderSentCalcId}`) + .reply(200, nomisCalculationSummary) + const result = await calculateReleaseDatesService.getNomisCalculationSummary(offenderSentCalcId, bookingId, token) expect(result).toEqual(nomisCalculationSummary) }) it('asserting fail scenario', async () => { - fakeApi.get(`/calculation/nomis-calculation-summary/${offenderSentCalcId}`).reply(404) - - await expect(calculateReleaseDatesService.getNomisCalculationSummary(offenderSentCalcId, token)).rejects.toThrow( - 'Not Found', - ) + const bookingId = 123456 + fakeApi + .get(`/calculation/nomis-calculation-summary/booking/${bookingId}/calculation/${offenderSentCalcId}`) + .reply(404) + await expect( + calculateReleaseDatesService.getNomisCalculationSummary(offenderSentCalcId, bookingId, token), + ).rejects.toThrow('Not Found') }) }) diff --git a/server/services/calculateReleaseDatesService.ts b/server/services/calculateReleaseDatesService.ts index f9e67ca7..cb187bf1 100644 --- a/server/services/calculateReleaseDatesService.ts +++ b/server/services/calculateReleaseDatesService.ts @@ -480,8 +480,12 @@ export default class CalculateReleaseDatesService { } } - async getNomisCalculationSummary(offenderSentCalcId: number, token: string): Promise { - return new CalculateReleaseDatesApiClient(token).getNomisCalculationSummary(offenderSentCalcId) + async getNomisCalculationSummary( + offenderSentCalcId: number, + bookingId: number, + token: string, + ): Promise { + return new CalculateReleaseDatesApiClient(token).getNomisCalculationSummary(offenderSentCalcId, bookingId) } async getReleaseDatesForACalcReqId(calcRequestId: number, token: string): Promise {