From 3880e0a285c921fc761efbf487452994e428b761 Mon Sep 17 00:00:00 2001 From: unakb Date: Wed, 12 Jun 2024 12:18:26 +0000 Subject: [PATCH 1/6] feat(j-s): Robot email for assigned roles in indictment case --- .../modules/case/internalCase.controller.ts | 25 ++++++ .../app/modules/case/internalCase.service.ts | 40 +++++++++ ...iverIndictmentAssignedRolesToCourt.spec.ts | 85 +++++++++++++++++++ ...dictmentAssignedRolesToCourtGuards.spec.ts | 50 +++++++++++ .../src/app/modules/court/court.service.ts | 33 ++++++- .../message/src/lib/message.ts | 2 + 6 files changed, 234 insertions(+), 1 deletion(-) create mode 100644 apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentAssignedRolesToCourt.spec.ts create mode 100644 apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentAssignedRolesToCourtGuards.spec.ts diff --git a/apps/judicial-system/backend/src/app/modules/case/internalCase.controller.ts b/apps/judicial-system/backend/src/app/modules/case/internalCase.controller.ts index 06fb7ff427c8..e50ffa98cf22 100644 --- a/apps/judicial-system/backend/src/app/modules/case/internalCase.controller.ts +++ b/apps/judicial-system/backend/src/app/modules/case/internalCase.controller.ts @@ -169,6 +169,31 @@ export class InternalCaseController { ) } + @UseGuards(CaseExistsGuard, new CaseTypeGuard(indictmentCases)) + @Post( + `case/:caseId/${ + messageEndpoint[MessageType.DELIVERY_TO_COURT_INDICTMENT_COURT_ROLES] + }`, + ) + @ApiOkResponse({ + type: DeliverResponse, + description: 'Delivers assigned roles in indictment case to court', + }) + deliverIndictmentAssignedRolesToCourt( + @Param('caseId') caseId: string, + @CurrentCase() theCase: Case, + @Body() deliverDto: DeliverDto, + ): Promise { + this.logger.debug( + `Delivering the assigned roles of indictment case ${caseId} to court`, + ) + + return this.internalCaseService.deliverIndictmentAssignedRolesToCourt( + theCase, + deliverDto.user, + ) + } + @UseGuards(CaseExistsGuard, new CaseTypeGuard(indictmentCases)) @Post( `case/:caseId/${ 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 3f011be35ca2..cc15dcaf3cfa 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 @@ -544,6 +544,46 @@ export class InternalCaseService { }) } + async deliverIndictmentAssignedRolesToCourt( + theCase: Case, + user: TUser, + ): Promise { + const assignedRoles = [ + ...(theCase.judge + ? [ + { + name: theCase.judge.name, + role: UserRole.DISTRICT_COURT_JUDGE, + }, + ] + : []), + ...(theCase.registrar + ? [ + { + name: theCase.registrar.name, + role: UserRole.DISTRICT_COURT_REGISTRAR, + }, + ] + : []), + ] + + return this.courtService + .updateIndictmentCaseWithAssignedRoles( + user, + theCase.id, + theCase.courtCaseNumber, + assignedRoles, + ) + .then(() => ({ delivered: true })) + .catch((reason) => { + this.logger.error( + `Failed to update indictment case ${theCase.id} with assigned roles`, + { reason }, + ) + + return { delivered: false } + }) + } async deliverCaseFilesRecordToCourt( theCase: Case, policeCaseNumber: string, 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 new file mode 100644 index 000000000000..33d6efc496dd --- /dev/null +++ b/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentAssignedRolesToCourt.spec.ts @@ -0,0 +1,85 @@ +import { uuid } from 'uuidv4' + +import { CaseType, User, UserRole } from '@island.is/judicial-system/types' + +import { createTestingCaseModule } from '../createTestingCaseModule' + +import { CourtService } from '../../../court' +import { DeliverDto } from '../../dto/deliver.dto' +import { Case } from '../../models/case.model' +import { DeliverResponse } from '../../models/deliver.response' + +interface Then { + result: DeliverResponse + error: Error +} + +type GivenWhenThen = ( + caseId: string, + theCase: Case, + body: DeliverDto, +) => Promise + +describe('InternalCaseController - Deliver assigned roles for indictment case to court', () => { + const user = { id: uuid() } as User + const caseId = uuid() + const courtCaseNumber = uuid() + + const theCase = { + id: caseId, + type: CaseType.INDICTMENT, + + courtCaseNumber, + judge: { name: 'Test Dómari', nationalId: '0101010101' }, + registrar: { name: 'Test Ritari', nationalId: '0202020202' }, + } as Case + + let mockCourtService: CourtService + let givenWhenThen: GivenWhenThen + + beforeEach(async () => { + const { courtService, internalCaseController } = + await createTestingCaseModule() + + mockCourtService = courtService + const mockUpdateIndictmentCaseWithAssignedRoles = + mockCourtService.updateIndictmentCaseWithAssignedRoles as jest.Mock + mockUpdateIndictmentCaseWithAssignedRoles.mockResolvedValue(uuid()) + + givenWhenThen = async (caseId: string, theCase: Case) => { + const then = {} as Then + + await internalCaseController + .deliverIndictmentAssignedRolesToCourt(caseId, theCase, { user }) + .then((result) => (then.result = result)) + .catch((error) => (then.error = error)) + + return then + } + }) + + describe('deliver assigned roles in indictment case to court', () => { + let then: Then + + beforeEach(async () => { + then = await givenWhenThen(caseId, theCase, { user }) + }) + + it('should deliver the assigned roles to the court', () => { + expect( + mockCourtService.updateIndictmentCaseWithAssignedRoles, + ).toHaveBeenCalledWith(user, theCase.id, theCase.courtCaseNumber, [ + { + name: theCase.judge?.name, + role: UserRole.DISTRICT_COURT_JUDGE, + }, + { + name: theCase.registrar?.name, + role: UserRole.DISTRICT_COURT_REGISTRAR, + }, + ]) + + expect(then.result).toEqual({ delivered: true }) + }) + }) +}) diff --git a/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentAssignedRolesToCourtGuards.spec.ts b/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentAssignedRolesToCourtGuards.spec.ts new file mode 100644 index 000000000000..37c6c87d158a --- /dev/null +++ b/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentAssignedRolesToCourtGuards.spec.ts @@ -0,0 +1,50 @@ +import { CanActivate } from '@nestjs/common' + +import { indictmentCases } from '@island.is/judicial-system/types' + +import { CaseExistsGuard } from '../../guards/caseExists.guard' +import { CaseTypeGuard } from '../../guards/caseType.guard' +import { InternalCaseController } from '../../internalCase.controller' + +describe('InternalCaseController - Deliver assigned roles in indictment case to court guards', () => { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + let guards: any[] + + beforeEach(() => { + guards = Reflect.getMetadata( + '__guards__', + InternalCaseController.prototype.deliverIndictmentAssignedRolesToCourt, + ) + }) + + it('should have two guards', () => { + expect(guards).toHaveLength(2) + }) + + describe('CaseExistsGuard', () => { + let guard: CanActivate + + beforeEach(() => { + guard = new guards[0]() + }) + + it('should have CaseExistsGuard as guard 1', () => { + expect(guard).toBeInstanceOf(CaseExistsGuard) + }) + }) + + describe('CaseTypeGuard', () => { + let guard: CanActivate + + beforeEach(() => { + guard = guards[1] + }) + + it('should have CaseTypeGuard as guard 2', () => { + expect(guard).toBeInstanceOf(CaseTypeGuard) + expect(guard).toEqual({ + allowedCaseTypes: indictmentCases, + }) + }) + }) +}) 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 3c407a5d4d3b..0014367569dd 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 @@ -12,7 +12,7 @@ import type { ConfigType } from '@island.is/nest/config' import { CourtClientService } from '@island.is/judicial-system/court-client' import { sanitize } from '@island.is/judicial-system/formatters' -import type { User } from '@island.is/judicial-system/types' +import type { User, UserRole } from '@island.is/judicial-system/types' import { CaseAppealRulingDecision, CaseDecision, @@ -127,6 +127,7 @@ enum RobotEmailType { APPEAL_CASE_CONCLUSION = 'APPEAL_CASE_CONCLUSION', APPEAL_CASE_FILE = 'APPEAL_CASE_FILE', NEW_INDICTMENT_INFO = 'INDICTMENT_INFO', + INDICTMENT_CASE_ASSIGNED_ROLES = 'INDICTMENT_CASE_ASSIGNED_ROLES', } @Injectable() @@ -603,6 +604,36 @@ export class CourtService { } } + async updateIndictmentCaseWithAssignedRoles( + user: User, + caseId: string, + courtCaseNumber?: string, + assignedRole?: { name?: string; role?: UserRole }[], + ): Promise { + try { + const subject = `Ákæra - ${courtCaseNumber} - úthlutun` + const content = JSON.stringify({ assignedRole }) + + return this.sendToRobot( + subject, + content, + RobotEmailType.INDICTMENT_CASE_ASSIGNED_ROLES, + caseId, + ) + } catch (error) { + this.eventService.postErrorEvent( + 'Failed to update indictment case with assigned roles', + { + caseId, + actor: user.name, + courtCaseNumber, + }, + error, + ) + + throw error + } + } async updateAppealCaseWithReceivedDate( user: User, caseId: string, diff --git a/libs/judicial-system/message/src/lib/message.ts b/libs/judicial-system/message/src/lib/message.ts index c4ea1d83a92f..edd583a902cd 100644 --- a/libs/judicial-system/message/src/lib/message.ts +++ b/libs/judicial-system/message/src/lib/message.ts @@ -5,6 +5,7 @@ export enum MessageType { DELIVERY_TO_COURT_DEFENDANT = 'DELIVERY_TO_COURT_DEFENDANT', DELIVERY_TO_COURT_INDICTMENT = 'DELIVERY_TO_COURT_INDICTMENT', DELIVERY_TO_COURT_INDICTMENT_INFO = 'DELIVERY_TO_COURT_INDICTMENT_INFO', + DELIVERY_TO_COURT_INDICTMENT_COURT_ROLES = 'DELIVERY_TO_COURT_INDICTMENT_COURT_ROLES', DELIVERY_TO_COURT_CASE_FILE = 'DELIVERY_TO_COURT_CASE_FILE', DELIVERY_TO_COURT_CASE_FILES_RECORD = 'DELIVERY_TO_COURT_CASE_FILES_RECORD', DELIVERY_TO_COURT_REQUEST = 'DELIVERY_TO_COURT_REQUEST', @@ -32,6 +33,7 @@ export const messageEndpoint: { [key in MessageType]: string } = { DELIVERY_TO_COURT_DEFENDANT: 'deliverDefendantToCourt', DELIVERY_TO_COURT_INDICTMENT: 'deliverIndictmentToCourt', DELIVERY_TO_COURT_INDICTMENT_INFO: 'deliverIndictmentInfoToCourt', + DELIVERY_TO_COURT_INDICTMENT_DEFENDER: 'deliverIndictmentDefenderToCourt', DELIVERY_TO_COURT_CASE_FILE: 'deliverCaseFileToCourt', DELIVERY_TO_COURT_CASE_FILES_RECORD: 'deliverCaseFilesRecordToCourt', DELIVERY_TO_COURT_REQUEST: 'deliverRequestToCourt', From 1b47c7f39ee6d80633f4444ddb4ad37c6323deda Mon Sep 17 00:00:00 2001 From: unakb Date: Wed, 12 Jun 2024 12:19:28 +0000 Subject: [PATCH 2/6] Update message.ts --- libs/judicial-system/message/src/lib/message.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/libs/judicial-system/message/src/lib/message.ts b/libs/judicial-system/message/src/lib/message.ts index edd583a902cd..72ea80f23c67 100644 --- a/libs/judicial-system/message/src/lib/message.ts +++ b/libs/judicial-system/message/src/lib/message.ts @@ -32,8 +32,9 @@ export const messageEndpoint: { [key in MessageType]: string } = { DELIVERY_TO_COURT_PROSECUTOR: 'deliverProsecutorToCourt', DELIVERY_TO_COURT_DEFENDANT: 'deliverDefendantToCourt', DELIVERY_TO_COURT_INDICTMENT: 'deliverIndictmentToCourt', + DELIVERY_TO_COURT_INDICTMENT_COURT_ROLES: + 'deliverIndictmentCourtRolesToCourt', DELIVERY_TO_COURT_INDICTMENT_INFO: 'deliverIndictmentInfoToCourt', - DELIVERY_TO_COURT_INDICTMENT_DEFENDER: 'deliverIndictmentDefenderToCourt', DELIVERY_TO_COURT_CASE_FILE: 'deliverCaseFileToCourt', DELIVERY_TO_COURT_CASE_FILES_RECORD: 'deliverCaseFilesRecordToCourt', DELIVERY_TO_COURT_REQUEST: 'deliverRequestToCourt', From 723fe44ce13395eef173a04df900db99757cd757 Mon Sep 17 00:00:00 2001 From: unakb Date: Wed, 12 Jun 2024 15:00:04 +0000 Subject: [PATCH 3/6] feat(j-s): Trigger for updating court role --- .../src/app/modules/case/case.service.ts | 39 +++++++++++++++++++ .../modules/case/internalCase.controller.ts | 6 ++- .../app/modules/case/internalCase.service.ts | 33 +++++++--------- ...iverIndictmentAssignedRolesToCourt.spec.ts | 34 +++++++++------- ...dictmentAssignedRolesToCourtGuards.spec.ts | 2 +- .../src/app/modules/court/court.service.ts | 4 +- 6 files changed, 79 insertions(+), 39 deletions(-) diff --git a/apps/judicial-system/backend/src/app/modules/case/case.service.ts b/apps/judicial-system/backend/src/app/modules/case/case.service.ts index a61fa38030a2..c1e609eecd63 100644 --- a/apps/judicial-system/backend/src/app/modules/case/case.service.ts +++ b/apps/judicial-system/backend/src/app/modules/case/case.service.ts @@ -629,6 +629,21 @@ export class CaseService { return this.messageService.sendMessagesToQueue(messages) } + private addMessagesForIndictmentCourtRoleAssigned( + theCase: Case, + user: TUser, + assignedNationalId: string, + ): Promise { + return this.messageService.sendMessagesToQueue([ + { + type: MessageType.DELIVERY_TO_COURT_INDICTMENT_COURT_ROLES, + user, + caseId: theCase.id, + elementId: assignedNationalId, + }, + ]) + } + private addMessagesForCourtCaseConnectionToQueue( theCase: Case, user: TUser, @@ -1203,6 +1218,30 @@ export class CaseService { } } + if ( + isIndictmentCase(updatedCase.type) && + ![ + CaseState.DRAFT, + CaseState.SUBMITTED, + CaseState.WAITING_FOR_CONFIRMATION, + ].includes(updatedCase.state) + ) { + const updatedRole = + updatedCase.judge?.nationalId !== theCase.judge?.nationalId + ? updatedCase.judge + : updatedCase.registrar?.nationalId !== theCase.registrar?.nationalId + ? updatedCase.registrar + : null + + if (updatedRole?.nationalId) { + await this.addMessagesForIndictmentCourtRoleAssigned( + updatedCase, + user, + updatedRole.nationalId, + ) + } + } + // This only applies to restriction cases if (updatedCase.appealCaseNumber) { if (updatedCase.appealCaseNumber !== theCase.appealCaseNumber) { diff --git a/apps/judicial-system/backend/src/app/modules/case/internalCase.controller.ts b/apps/judicial-system/backend/src/app/modules/case/internalCase.controller.ts index e50ffa98cf22..dc8a9a4d4823 100644 --- a/apps/judicial-system/backend/src/app/modules/case/internalCase.controller.ts +++ b/apps/judicial-system/backend/src/app/modules/case/internalCase.controller.ts @@ -173,16 +173,17 @@ export class InternalCaseController { @Post( `case/:caseId/${ messageEndpoint[MessageType.DELIVERY_TO_COURT_INDICTMENT_COURT_ROLES] - }`, + }/:nationalId`, ) @ApiOkResponse({ type: DeliverResponse, description: 'Delivers assigned roles in indictment case to court', }) - deliverIndictmentAssignedRolesToCourt( + deliverIndictmentAssignedRoleToCourt( @Param('caseId') caseId: string, @CurrentCase() theCase: Case, @Body() deliverDto: DeliverDto, + @Param('nationalId') nationalId: string, ): Promise { this.logger.debug( `Delivering the assigned roles of indictment case ${caseId} to court`, @@ -191,6 +192,7 @@ export class InternalCaseController { return this.internalCaseService.deliverIndictmentAssignedRolesToCourt( theCase, deliverDto.user, + nationalId, ) } 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 cc15dcaf3cfa..9a266208fd47 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 @@ -547,32 +547,27 @@ export class InternalCaseService { async deliverIndictmentAssignedRolesToCourt( theCase: Case, user: TUser, + nationalId?: string, ): Promise { - const assignedRoles = [ - ...(theCase.judge - ? [ - { - name: theCase.judge.name, - role: UserRole.DISTRICT_COURT_JUDGE, - }, - ] - : []), - ...(theCase.registrar - ? [ - { - name: theCase.registrar.name, - role: UserRole.DISTRICT_COURT_REGISTRAR, - }, - ] - : []), - ] + const assignedRole = + theCase.judge?.nationalId === nationalId + ? { + name: theCase.judge?.name, + role: UserRole.DISTRICT_COURT_JUDGE, + } + : theCase.registrar?.nationalId === nationalId + ? { + name: theCase.registrar?.name, + role: UserRole.DISTRICT_COURT_REGISTRAR, + } + : {} return this.courtService .updateIndictmentCaseWithAssignedRoles( user, theCase.id, theCase.courtCaseNumber, - assignedRoles, + assignedRole, ) .then(() => ({ delivered: true })) .catch((reason) => { 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 33d6efc496dd..15498ef9fed5 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 @@ -17,7 +17,7 @@ interface Then { type GivenWhenThen = ( caseId: string, theCase: Case, - body: DeliverDto, + nationalId: string, ) => Promise describe('InternalCaseController - Deliver assigned roles for indictment case to court', () => { @@ -28,7 +28,6 @@ describe('InternalCaseController - Deliver assigned roles for indictment case to const theCase = { id: caseId, type: CaseType.INDICTMENT, - courtCaseNumber, judge: { name: 'Test Dómari', nationalId: '0101010101' }, registrar: { name: 'Test Ritari', nationalId: '0202020202' }, @@ -46,11 +45,20 @@ describe('InternalCaseController - Deliver assigned roles for indictment case to mockCourtService.updateIndictmentCaseWithAssignedRoles as jest.Mock mockUpdateIndictmentCaseWithAssignedRoles.mockResolvedValue(uuid()) - givenWhenThen = async (caseId: string, theCase: Case) => { + givenWhenThen = async ( + caseId: string, + theCase: Case, + nationalId: string, + ) => { const then = {} as Then await internalCaseController - .deliverIndictmentAssignedRolesToCourt(caseId, theCase, { user }) + .deliverIndictmentAssignedRoleToCourt( + caseId, + theCase, + { user }, + nationalId, + ) .then((result) => (then.result = result)) .catch((error) => (then.error = error)) @@ -62,24 +70,20 @@ describe('InternalCaseController - Deliver assigned roles for indictment case to let then: Then beforeEach(async () => { - then = await givenWhenThen(caseId, theCase, { user }) + then = await givenWhenThen(caseId, theCase, '0101010101') }) it('should deliver the assigned roles to the court', () => { expect( mockCourtService.updateIndictmentCaseWithAssignedRoles, - ).toHaveBeenCalledWith(user, theCase.id, theCase.courtCaseNumber, [ - { - name: theCase.judge?.name, - role: UserRole.DISTRICT_COURT_JUDGE, - }, - { - name: theCase.registrar?.name, - role: UserRole.DISTRICT_COURT_REGISTRAR, - }, - ]) + ).toHaveBeenCalledWith(user, theCase.id, theCase.courtCaseNumber, { + name: theCase.judge?.name, + role: UserRole.DISTRICT_COURT_JUDGE, + }) expect(then.result).toEqual({ delivered: true }) }) }) + + }) diff --git a/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentAssignedRolesToCourtGuards.spec.ts b/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentAssignedRolesToCourtGuards.spec.ts index 37c6c87d158a..9de723b095dc 100644 --- a/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentAssignedRolesToCourtGuards.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentAssignedRolesToCourtGuards.spec.ts @@ -13,7 +13,7 @@ describe('InternalCaseController - Deliver assigned roles in indictment case to beforeEach(() => { guards = Reflect.getMetadata( '__guards__', - InternalCaseController.prototype.deliverIndictmentAssignedRolesToCourt, + InternalCaseController.prototype.deliverIndictmentAssignedRoleToCourt, ) }) 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 0014367569dd..e5376d1e27df 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 @@ -608,11 +608,11 @@ export class CourtService { user: User, caseId: string, courtCaseNumber?: string, - assignedRole?: { name?: string; role?: UserRole }[], + assignedRole?: { name?: string; role?: UserRole }, ): Promise { try { const subject = `Ákæra - ${courtCaseNumber} - úthlutun` - const content = JSON.stringify({ assignedRole }) + const content = JSON.stringify(assignedRole) return this.sendToRobot( subject, From 0b04a80a7e15e6344e9349d3dbc9384066a2aeaf Mon Sep 17 00:00:00 2001 From: unakb Date: Wed, 12 Jun 2024 15:09:33 +0000 Subject: [PATCH 4/6] Update deliverIndictmentAssignedRolesToCourt.spec.ts --- .../deliverIndictmentAssignedRolesToCourt.spec.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) 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 15498ef9fed5..49ccd3ee532a 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 @@ -5,7 +5,6 @@ import { CaseType, User, UserRole } from '@island.is/judicial-system/types' import { createTestingCaseModule } from '../createTestingCaseModule' import { CourtService } from '../../../court' -import { DeliverDto } from '../../dto/deliver.dto' import { Case } from '../../models/case.model' import { DeliverResponse } from '../../models/deliver.response' @@ -36,7 +35,7 @@ describe('InternalCaseController - Deliver assigned roles for indictment case to let mockCourtService: CourtService let givenWhenThen: GivenWhenThen - beforeEach(async () => { + beforeAll(async () => { const { courtService, internalCaseController } = await createTestingCaseModule() @@ -69,7 +68,7 @@ describe('InternalCaseController - Deliver assigned roles for indictment case to describe('deliver assigned roles in indictment case to court', () => { let then: Then - beforeEach(async () => { + beforeAll(async () => { then = await givenWhenThen(caseId, theCase, '0101010101') }) @@ -84,6 +83,4 @@ describe('InternalCaseController - Deliver assigned roles for indictment case to expect(then.result).toEqual({ delivered: true }) }) }) - - }) From 7f6af3d3936119b22f728037aa704dcabcd9d3c6 Mon Sep 17 00:00:00 2001 From: unakb Date: Wed, 12 Jun 2024 15:18:30 +0000 Subject: [PATCH 5/6] Merge conflicts resolved --- .../app/modules/case/internalCase.service.ts | 67 ------------------- .../src/app/modules/court/court.service.ts | 39 +---------- 2 files changed, 1 insertion(+), 105 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 1be335e6c360..117bcc062f09 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 @@ -611,73 +611,6 @@ export class InternalCaseService { }) } - async deliverIndictmentInfoToCourt( - theCase: Case, - user: TUser, - ): Promise { - const subtypeList = theCase.indictmentSubtypes - ? Object.values(theCase.indictmentSubtypes).flat() - : [] - - const mappedSubtypes = subtypeList.flatMap((key) => courtSubtypes[key]) - - return this.courtService - .updateIndictmentCaseWithIndictmentInfo( - user, - theCase.id, - theCase.courtCaseNumber, - theCase.eventLogs?.find( - (eventLog) => eventLog.eventType === EventType.CASE_RECEIVED_BY_COURT, - )?.created, - theCase.eventLogs?.find( - (eventLog) => eventLog.eventType === EventType.INDICTMENT_CONFIRMED, - )?.created, - theCase.policeCaseNumbers[0], - mappedSubtypes, - theCase.defendants?.map((defendant) => ({ - name: defendant.name, - nationalId: defendant.nationalId, - })), - theCase.prosecutor - ? { - name: theCase.prosecutor.name, - nationalId: theCase.prosecutor.nationalId, - } - : undefined, - ) - .then(() => ({ delivered: true })) - .catch((reason) => { - this.logger.error( - `Failed to update indictment case ${theCase.id} with indictment info`, - { reason }, - ) - - return { delivered: false } - }) - } - - async deliverIndictmentDefenderInfoToCourt( - theCase: Case, - user: TUser, - ): Promise { - return this.courtService - .updateIndictmentWithDefenderInfo( - user, - theCase.id, - theCase.courtCaseNumber, - theCase.defendants, - ) - .then(() => ({ delivered: true })) - .catch((reason) => { - this.logger.error( - `Failed to update indictment case ${theCase.id} with defender info`, - { reason }, - ) - - return { delivered: false } - }) - } - async deliverIndictmentAssignedRolesToCourt( theCase: Case, user: TUser, 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 c7da47b1a95a..3b51ff1fc7a4 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 @@ -644,44 +644,6 @@ export class CourtService { } } - async updateIndictmentWithDefenderInfo( - user: User, - caseId: string, - courtCaseNumber?: string, - defendants?: Defendant[], - ): Promise { - try { - const defendantInfo = defendants?.map((defendant) => ({ - nationalId: defendant.nationalId, - defenderName: defendant.defenderName, - defenderEmail: defendant.defenderEmail, - })) - - const subject = `Ákæra - ${courtCaseNumber} - verjanda upplýsingar` - const content = JSON.stringify(defendantInfo) - - return this.sendToRobot( - subject, - content, - RobotEmailType.INDICTMENT_CASE_DEFENDER_INFO, - caseId, - ) - } catch (error) { - this.eventService.postErrorEvent( - 'Failed to update indictment with defender info', - { - caseId, - actor: user.name, - institution: user.institution?.name, - courtCaseNumber, - }, - error, - ) - - throw error - } - } - async updateIndictmentCaseWithAssignedRoles( user: User, caseId: string, @@ -712,6 +674,7 @@ export class CourtService { throw error } } + async updateAppealCaseWithReceivedDate( user: User, caseId: string, From a68f883e22ab1e6e932f4c53b68a237ffd1314a9 Mon Sep 17 00:00:00 2001 From: unakb Date: Tue, 18 Jun 2024 12:17:27 +0000 Subject: [PATCH 6/6] fix(j-s): test cleanup --- ...dictmentAssignedRolesToCourtGuards.spec.ts | 35 +++---------------- 1 file changed, 5 insertions(+), 30 deletions(-) diff --git a/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentAssignedRolesToCourtGuards.spec.ts b/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentAssignedRolesToCourtGuards.spec.ts index 9de723b095dc..3d5c534a0e74 100644 --- a/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentAssignedRolesToCourtGuards.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentAssignedRolesToCourtGuards.spec.ts @@ -1,5 +1,3 @@ -import { CanActivate } from '@nestjs/common' - import { indictmentCases } from '@island.is/judicial-system/types' import { CaseExistsGuard } from '../../guards/caseExists.guard' @@ -17,34 +15,11 @@ describe('InternalCaseController - Deliver assigned roles in indictment case to ) }) - it('should have two guards', () => { - expect(guards).toHaveLength(2) - }) - - describe('CaseExistsGuard', () => { - let guard: CanActivate - - beforeEach(() => { - guard = new guards[0]() - }) - - it('should have CaseExistsGuard as guard 1', () => { - expect(guard).toBeInstanceOf(CaseExistsGuard) - }) - }) - - describe('CaseTypeGuard', () => { - let guard: CanActivate - - beforeEach(() => { - guard = guards[1] - }) - - it('should have CaseTypeGuard as guard 2', () => { - expect(guard).toBeInstanceOf(CaseTypeGuard) - expect(guard).toEqual({ - allowedCaseTypes: indictmentCases, - }) + it('should have the right guard configuration', () => { + expect(new guards[0]()).toBeInstanceOf(CaseExistsGuard) + expect(guards[1]).toBeInstanceOf(CaseTypeGuard) + expect(guards[1]).toEqual({ + allowedCaseTypes: indictmentCases, }) }) })