From 652f650e3e7a608fb16ab2352bf29a618db53056 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0j=C3=B3n=20Gu=C3=B0j=C3=B3nsson?= Date: Tue, 25 Jun 2024 14:20:21 +0000 Subject: [PATCH] Adds district court name to indictment case robot email subjects --- .../src/app/modules/case/internalCase.service.ts | 5 ++++- .../deliverIndictmentAssignedRolesToCourt.spec.ts | 4 +++- .../deliverIndictmentDefenderInfoToCourt.spec.ts | 15 ++++++++++----- .../deliverIndictmentInfoToCourt.spec.ts | 7 +++++-- .../src/app/modules/court/court.service.ts | 13 ++++++++----- 5 files changed, 30 insertions(+), 14 deletions(-) diff --git a/apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts b/apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts index 10a9b8cd5554..e560ed57c336 100644 --- a/apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts +++ b/apps/judicial-system/backend/src/app/modules/case/internalCase.service.ts @@ -588,6 +588,7 @@ export class InternalCaseService { .updateIndictmentCaseWithIndictmentInfo( user, theCase.id, + theCase.court?.name, theCase.courtCaseNumber, theCase.eventLogs?.find( (eventLog) => eventLog.eventType === EventType.CASE_RECEIVED_BY_COURT, @@ -624,9 +625,10 @@ export class InternalCaseService { user: TUser, ): Promise { return this.courtService - .updateIndictmentWithDefenderInfo( + .updateIndictmentCaseWithDefenderInfo( user, theCase.id, + theCase.court?.name, theCase.courtCaseNumber, theCase.defendants, ) @@ -663,6 +665,7 @@ export class InternalCaseService { .updateIndictmentCaseWithAssignedRoles( user, theCase.id, + theCase.court?.name, theCase.courtCaseNumber, assignedRole, ) diff --git a/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentAssignedRolesToCourt.spec.ts b/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentAssignedRolesToCourt.spec.ts index 49ccd3ee532a..aeba60fde5c3 100644 --- a/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentAssignedRolesToCourt.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentAssignedRolesToCourt.spec.ts @@ -22,11 +22,13 @@ type GivenWhenThen = ( describe('InternalCaseController - Deliver assigned roles for indictment case to court', () => { const user = { id: uuid() } as User const caseId = uuid() + const courtName = uuid() const courtCaseNumber = uuid() const theCase = { id: caseId, type: CaseType.INDICTMENT, + court: { name: courtName }, courtCaseNumber, judge: { name: 'Test Dómari', nationalId: '0101010101' }, registrar: { name: 'Test Ritari', nationalId: '0202020202' }, @@ -75,7 +77,7 @@ describe('InternalCaseController - Deliver assigned roles for indictment case to it('should deliver the assigned roles to the court', () => { expect( mockCourtService.updateIndictmentCaseWithAssignedRoles, - ).toHaveBeenCalledWith(user, theCase.id, theCase.courtCaseNumber, { + ).toHaveBeenCalledWith(user, caseId, courtName, courtCaseNumber, { name: theCase.judge?.name, role: UserRole.DISTRICT_COURT_JUDGE, }) diff --git a/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentDefenderInfoToCourt.spec.ts b/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentDefenderInfoToCourt.spec.ts index 2664f609102a..f60117749089 100644 --- a/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentDefenderInfoToCourt.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentDefenderInfoToCourt.spec.ts @@ -23,11 +23,13 @@ type GivenWhenThen = ( describe('InternalCaseController - Deliver indictment defender info to court', () => { const user = { id: uuid() } as User const caseId = uuid() + const courtName = uuid() const courtCaseNumber = uuid() const theCase = { id: caseId, type: CaseType.INDICTMENT, + court: { name: courtName }, courtCaseNumber, defendants: [ { @@ -55,7 +57,9 @@ describe('InternalCaseController - Deliver indictment defender info to court', ( await createTestingCaseModule() mockCourtService = courtService as jest.Mocked - mockCourtService.updateIndictmentWithDefenderInfo.mockResolvedValue(uuid()) + mockCourtService.updateIndictmentCaseWithDefenderInfo.mockResolvedValue( + uuid(), + ) givenWhenThen = async (caseId: string, theCase: Case, body: DeliverDto) => { const then = {} as Then @@ -73,11 +77,12 @@ describe('InternalCaseController - Deliver indictment defender info to court', ( const then = await givenWhenThen(caseId, theCase, { user }) expect( - mockCourtService.updateIndictmentWithDefenderInfo, + mockCourtService.updateIndictmentCaseWithDefenderInfo, ).toHaveBeenCalledWith( user, - theCase.id, - theCase.courtCaseNumber, + caseId, + courtName, + courtCaseNumber, theCase.defendants, ) @@ -87,7 +92,7 @@ describe('InternalCaseController - Deliver indictment defender info to court', ( it('should handle not deliver if error occurs', async () => { const error = new Error('Service error') - mockCourtService.updateIndictmentWithDefenderInfo.mockRejectedValueOnce( + mockCourtService.updateIndictmentCaseWithDefenderInfo.mockRejectedValueOnce( error, ) diff --git a/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentInfoToCourt.spec.ts b/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentInfoToCourt.spec.ts index 671d8fc9fc63..4c929c759e7a 100644 --- a/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentInfoToCourt.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentInfoToCourt.spec.ts @@ -29,6 +29,7 @@ type GivenWhenThen = ( describe('InternalCaseController - Deliver indictment info to court', () => { const user = { id: uuid() } as User const caseId = uuid() + const courtName = uuid() const policeCaseNumber = uuid() const policeCaseNumber2 = uuid() const courtCaseNumber = uuid() @@ -46,6 +47,7 @@ describe('InternalCaseController - Deliver indictment info to court', () => { ], [policeCaseNumber2]: [IndictmentSubtype.THEFT], }, + court: { name: courtName }, courtCaseNumber, eventLogs: [ { eventType: EventType.CASE_RECEIVED_BY_COURT, created: receivedDate }, @@ -91,8 +93,9 @@ describe('InternalCaseController - Deliver indictment info to court', () => { mockCourtService.updateIndictmentCaseWithIndictmentInfo, ).toHaveBeenCalledWith( user, - theCase.id, - theCase.courtCaseNumber, + caseId, + courtName, + courtCaseNumber, receivedDate, indictmentDate, policeCaseNumber, diff --git a/apps/judicial-system/backend/src/app/modules/court/court.service.ts b/apps/judicial-system/backend/src/app/modules/court/court.service.ts index 3b51ff1fc7a4..b2b889ac715d 100644 --- a/apps/judicial-system/backend/src/app/modules/court/court.service.ts +++ b/apps/judicial-system/backend/src/app/modules/court/court.service.ts @@ -562,6 +562,7 @@ export class CourtService { async updateIndictmentCaseWithIndictmentInfo( user: User, caseId: string, + courtName?: string, courtCaseNumber?: string, receivedByCourtDate?: Date, indictmentDate?: Date, @@ -571,7 +572,7 @@ export class CourtService { prosecutor?: { name?: string; nationalId?: string }, ): Promise { try { - const subject = `Ákæra - ${courtCaseNumber} - upplýsingar` + const subject = `${courtName} - ${courtCaseNumber} - upplýsingar` const content = JSON.stringify({ receivedByCourtDate, indictmentDate, @@ -606,9 +607,10 @@ export class CourtService { } } - async updateIndictmentWithDefenderInfo( + async updateIndictmentCaseWithDefenderInfo( user: User, caseId: string, + courtName?: string, courtCaseNumber?: string, defendants?: Defendant[], ): Promise { @@ -619,7 +621,7 @@ export class CourtService { defenderEmail: defendant.defenderEmail, })) - const subject = `Ákæra - ${courtCaseNumber} - verjanda upplýsingar` + const subject = `${courtName} - ${courtCaseNumber} - verjanda upplýsingar` const content = JSON.stringify(defendantInfo) return this.sendToRobot( @@ -647,11 +649,12 @@ export class CourtService { async updateIndictmentCaseWithAssignedRoles( user: User, caseId: string, + courtName?: string, courtCaseNumber?: string, assignedRole?: { name?: string; role?: UserRole }, ): Promise { try { - const subject = `Ákæra - ${courtCaseNumber} - úthlutun` + const subject = `${courtName} - ${courtCaseNumber} - úthlutun` const content = JSON.stringify(assignedRole) return this.sendToRobot( @@ -856,7 +859,7 @@ export class CourtService { .then((log) => [log.id, log.seqNumber]) } - async sendToRobot( + private async sendToRobot( subject: string, content: string, type: RobotEmailType,