From b37ae8dc101df4ef2af4a8ed97e947d8246af834 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0j=C3=B3n=20Gu=C3=B0j=C3=B3nsson?= Date: Fri, 13 Dec 2024 18:16:07 +0000 Subject: [PATCH 1/3] Delivers subpoena to court --- .../src/app/modules/case/case.service.ts | 31 +++-- .../src/app/modules/court/court.service.ts | 1 + .../subpoena/internalSubpoena.controller.ts | 40 ++++++- .../app/modules/subpoena/subpoena.module.ts | 2 + .../app/modules/subpoena/subpoena.service.ts | 37 ++++++ .../test/createTestingSubpoenaModule.ts | 8 +- .../deliverSubpoanaToCourtGuards.spec.ts | 29 +++++ .../deliverSubpoanaToPoliceGuards.spec.ts | 29 +++++ .../deliverSubpoenaToCourt.spec.ts | 111 ++++++++++++++++++ .../deliverSubpoenaToPolice.spec.ts | 46 ++++---- .../updateSubpoeanaGuards.spec.ts | 2 +- .../message/src/lib/message.ts | 2 + 12 files changed, 302 insertions(+), 36 deletions(-) create mode 100644 apps/judicial-system/backend/src/app/modules/subpoena/test/internalSubpoenaController/deliverSubpoanaToCourtGuards.spec.ts create mode 100644 apps/judicial-system/backend/src/app/modules/subpoena/test/internalSubpoenaController/deliverSubpoanaToPoliceGuards.spec.ts create mode 100644 apps/judicial-system/backend/src/app/modules/subpoena/test/internalSubpoenaController/deliverSubpoenaToCourt.spec.ts 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 c89bbc8c0e0c..715281001a39 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 @@ -1255,18 +1255,29 @@ export class CaseService { (defendant) => defendant.id === updatedDefendant.id, )?.subpoenas?.[0]?.id !== updatedDefendant.subpoenas?.[0]?.id, ) - .map((updatedDefendant) => ({ - type: MessageType.DELIVERY_TO_POLICE_SUBPOENA, - user, - caseId: theCase.id, - elementId: [ - updatedDefendant.id, - updatedDefendant.subpoenas?.[0].id ?? '', - ], - })) + .map((updatedDefendant) => [ + { + type: MessageType.DELIVERY_TO_POLICE_SUBPOENA, + user, + caseId: theCase.id, + elementId: [ + updatedDefendant.id, + updatedDefendant.subpoenas?.[0].id ?? '', + ], + }, + { + type: MessageType.DELIVERY_TO_COURT_SUBPOENA, + user, + caseId: theCase.id, + elementId: [ + updatedDefendant.id, + updatedDefendant.subpoenas?.[0].id ?? '', + ], + }, + ]) if (messages && messages.length > 0) { - return this.messageService.sendMessagesToQueue(messages) + return this.messageService.sendMessagesToQueue(messages.flat()) } } 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 df13b35a90be..8629da76d330 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 @@ -34,6 +34,7 @@ export enum CourtDocumentFolder { CASE_DOCUMENTS = 'Gögn málsins', COURT_DOCUMENTS = 'Dómar, úrskurðir og Þingbók', APPEAL_DOCUMENTS = 'Kæra til Landsréttar', + SUBPOENA_DOCUMENTS = 'Boðanir', } export type Subtype = Exclude | IndictmentSubtype diff --git a/apps/judicial-system/backend/src/app/modules/subpoena/internalSubpoena.controller.ts b/apps/judicial-system/backend/src/app/modules/subpoena/internalSubpoena.controller.ts index 87402f7b3ada..2937e657a3f4 100644 --- a/apps/judicial-system/backend/src/app/modules/subpoena/internalSubpoena.controller.ts +++ b/apps/judicial-system/backend/src/app/modules/subpoena/internalSubpoena.controller.ts @@ -67,7 +67,7 @@ export class InternalSubpoenaController { ) @ApiOkResponse({ type: DeliverResponse, - description: 'Delivers a subpoena to police', + description: 'Delivers a subpoena to the police', }) deliverSubpoenaToPolice( @Param('caseId') caseId: string, @@ -79,7 +79,7 @@ export class InternalSubpoenaController { @Body() deliverDto: DeliverDto, ): Promise { this.logger.debug( - `Delivering subpoena ${subpoenaId} to police for defendant ${defendantId} of case ${caseId}`, + `Delivering subpoena ${subpoenaId} pdf to police for defendant ${defendantId} of case ${caseId}`, ) return this.subpoenaService.deliverSubpoenaToPolice( @@ -89,4 +89,40 @@ export class InternalSubpoenaController { deliverDto.user, ) } + + @UseGuards( + CaseExistsGuard, + new CaseTypeGuard(indictmentCases), + DefendantExistsGuard, + SubpoenaExistsGuard, + ) + @Post( + `case/:caseId/${ + messageEndpoint[MessageType.DELIVERY_TO_COURT_SUBPOENA] + }/:defendantId/:subpoenaId`, + ) + @ApiOkResponse({ + type: DeliverResponse, + description: 'Delivers a subpoena to the court', + }) + deliverSubpoenaToCourt( + @Param('caseId') caseId: string, + @Param('defendantId') defendantId: string, + @Param('subpoenaId') subpoenaId: string, + @CurrentCase() theCase: Case, + @CurrentDefendant() defendant: Defendant, + @CurrentSubpoena() subpoena: Subpoena, + @Body() deliverDto: DeliverDto, + ): Promise { + this.logger.debug( + `Delivering subpoena ${subpoenaId} pdf to court for defendant ${defendantId} of case ${caseId}`, + ) + + return this.subpoenaService.deliverSubpoenaToCourt( + theCase, + defendant, + subpoena, + deliverDto.user, + ) + } } diff --git a/apps/judicial-system/backend/src/app/modules/subpoena/subpoena.module.ts b/apps/judicial-system/backend/src/app/modules/subpoena/subpoena.module.ts index 31fba1e49734..05be74045e18 100644 --- a/apps/judicial-system/backend/src/app/modules/subpoena/subpoena.module.ts +++ b/apps/judicial-system/backend/src/app/modules/subpoena/subpoena.module.ts @@ -4,6 +4,7 @@ import { SequelizeModule } from '@nestjs/sequelize' import { MessageModule } from '@island.is/judicial-system/message' import { CaseModule } from '../case/case.module' +import { CourtModule } from '../court/court.module' import { DefendantModule } from '../defendant/defendant.module' import { Defendant } from '../defendant/models/defendant.model' import { EventModule } from '../event/event.module' @@ -23,6 +24,7 @@ import { SubpoenaService } from './subpoena.service' forwardRef(() => MessageModule), forwardRef(() => EventModule), forwardRef(() => DefendantModule), + CourtModule, SequelizeModule.forFeature([Subpoena, Defendant]), ], controllers: [ diff --git a/apps/judicial-system/backend/src/app/modules/subpoena/subpoena.service.ts b/apps/judicial-system/backend/src/app/modules/subpoena/subpoena.service.ts index e2d3116d4aa5..a83405e8a488 100644 --- a/apps/judicial-system/backend/src/app/modules/subpoena/subpoena.service.ts +++ b/apps/judicial-system/backend/src/app/modules/subpoena/subpoena.service.ts @@ -31,6 +31,7 @@ import { import { Case } from '../case/models/case.model' import { PdfService } from '../case/pdf.service' +import { CourtDocumentFolder, CourtService } from '../court' import { DefendantService } from '../defendant/defendant.service' import { Defendant } from '../defendant/models/defendant.model' import { EventService } from '../event' @@ -93,6 +94,7 @@ export class SubpoenaService { private readonly fileService: FileService, private readonly eventService: EventService, private readonly defendantService: DefendantService, + private readonly courtService: CourtService, @Inject(LOGGER_PROVIDER) private readonly logger: Logger, ) {} @@ -356,6 +358,41 @@ export class SubpoenaService { } } + async deliverSubpoenaToCourt( + theCase: Case, + defendant: Defendant, + subpoena: Subpoena, + user: TUser, + ): Promise { + return this.pdfService + .getSubpoenaPdf(theCase, defendant, subpoena) + .then(async (pdf) => { + const fileName = `Fyrirkall - ${defendant.name}` + + return this.courtService.createDocument( + user, + theCase.id, + theCase.courtId, + theCase.courtCaseNumber, + CourtDocumentFolder.SUBPOENA_DOCUMENTS, + fileName, + `${fileName}.pdf`, + 'application/pdf', + pdf, + ) + }) + .then(() => ({ delivered: true })) + .catch((reason) => { + // Tolerate failure, but log error + this.logger.warn( + `Failed to upload subpoena ${subpoena.id} pdf to court for defendant ${defendant.id} of case ${theCase.id}`, + { reason }, + ) + + return { delivered: false } + }) + } + async getSubpoena(subpoena: Subpoena, user?: TUser): Promise { if (!subpoena.subpoenaId) { // The subpoena has not been delivered to the police diff --git a/apps/judicial-system/backend/src/app/modules/subpoena/test/createTestingSubpoenaModule.ts b/apps/judicial-system/backend/src/app/modules/subpoena/test/createTestingSubpoenaModule.ts index e397c3e498ac..c4982ece5817 100644 --- a/apps/judicial-system/backend/src/app/modules/subpoena/test/createTestingSubpoenaModule.ts +++ b/apps/judicial-system/backend/src/app/modules/subpoena/test/createTestingSubpoenaModule.ts @@ -13,6 +13,7 @@ import { import { MessageService } from '@island.is/judicial-system/message' import { CaseService, PdfService } from '../../case' +import { CourtService } from '../../court' import { Defendant, DefendantService } from '../../defendant' import { EventService } from '../../event' import { FileService } from '../../file' @@ -24,6 +25,7 @@ import { Subpoena } from '../models/subpoena.model' import { SubpoenaController } from '../subpoena.controller' import { SubpoenaService } from '../subpoena.service' +jest.mock('@island.is/judicial-system/message') jest.mock('../../user/user.service') jest.mock('../../case/case.service') jest.mock('../../case/pdf.service') @@ -31,7 +33,7 @@ jest.mock('../../police/police.service') jest.mock('../../file/file.service') jest.mock('../../event/event.service') jest.mock('../../defendant/defendant.service') -jest.mock('@island.is/judicial-system/message') +jest.mock('../../court/court.service') export const createTestingSubpoenaModule = async () => { const subpoenaModule = await Test.createTestingModule({ @@ -51,6 +53,7 @@ export const createTestingSubpoenaModule = async () => { FileService, EventService, DefendantService, + CourtService, { provide: LOGGER_PROVIDER, useValue: { @@ -94,6 +97,8 @@ export const createTestingSubpoenaModule = async () => { const fileService = subpoenaModule.get(FileService) + const courtService = subpoenaModule.get(CourtService) + const subpoenaModel = await subpoenaModule.resolve( getModelToken(Subpoena), ) @@ -118,6 +123,7 @@ export const createTestingSubpoenaModule = async () => { pdfService, policeService, fileService, + courtService, subpoenaModel, subpoenaService, subpoenaController, diff --git a/apps/judicial-system/backend/src/app/modules/subpoena/test/internalSubpoenaController/deliverSubpoanaToCourtGuards.spec.ts b/apps/judicial-system/backend/src/app/modules/subpoena/test/internalSubpoenaController/deliverSubpoanaToCourtGuards.spec.ts new file mode 100644 index 000000000000..448185532c87 --- /dev/null +++ b/apps/judicial-system/backend/src/app/modules/subpoena/test/internalSubpoenaController/deliverSubpoanaToCourtGuards.spec.ts @@ -0,0 +1,29 @@ +import { indictmentCases } from '@island.is/judicial-system/types' + +import { CaseExistsGuard, CaseTypeGuard } from '../../../case' +import { DefendantExistsGuard } from '../../../defendant' +import { SubpoenaExistsGuard } from '../../guards/subpoenaExists.guard' +import { InternalSubpoenaController } from '../../internalSubpoena.controller' + +describe('InternalSubpoenaController - Deliver subpoena to court guards', () => { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + let guards: any[] + + beforeEach(() => { + guards = Reflect.getMetadata( + '__guards__', + InternalSubpoenaController.prototype.deliverSubpoenaToCourt, + ) + }) + + it('should have the right guard configuration', () => { + expect(guards).toHaveLength(4) + expect(new guards[0]()).toBeInstanceOf(CaseExistsGuard) + expect(guards[1]).toBeInstanceOf(CaseTypeGuard) + expect(guards[1]).toEqual({ + allowedCaseTypes: indictmentCases, + }) + expect(new guards[2]()).toBeInstanceOf(DefendantExistsGuard) + expect(new guards[3]()).toBeInstanceOf(SubpoenaExistsGuard) + }) +}) diff --git a/apps/judicial-system/backend/src/app/modules/subpoena/test/internalSubpoenaController/deliverSubpoanaToPoliceGuards.spec.ts b/apps/judicial-system/backend/src/app/modules/subpoena/test/internalSubpoenaController/deliverSubpoanaToPoliceGuards.spec.ts new file mode 100644 index 000000000000..4f1663e3cc03 --- /dev/null +++ b/apps/judicial-system/backend/src/app/modules/subpoena/test/internalSubpoenaController/deliverSubpoanaToPoliceGuards.spec.ts @@ -0,0 +1,29 @@ +import { indictmentCases } from '@island.is/judicial-system/types' + +import { CaseExistsGuard, CaseTypeGuard } from '../../../case' +import { DefendantExistsGuard } from '../../../defendant' +import { SubpoenaExistsGuard } from '../../guards/subpoenaExists.guard' +import { InternalSubpoenaController } from '../../internalSubpoena.controller' + +describe('InternalSubpoenaController - Deliver subpoena to police guards', () => { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + let guards: any[] + + beforeEach(() => { + guards = Reflect.getMetadata( + '__guards__', + InternalSubpoenaController.prototype.deliverSubpoenaToPolice, + ) + }) + + it('should have the right guard configuration', () => { + expect(guards).toHaveLength(4) + expect(new guards[0]()).toBeInstanceOf(CaseExistsGuard) + expect(guards[1]).toBeInstanceOf(CaseTypeGuard) + expect(guards[1]).toEqual({ + allowedCaseTypes: indictmentCases, + }) + expect(new guards[2]()).toBeInstanceOf(DefendantExistsGuard) + expect(new guards[3]()).toBeInstanceOf(SubpoenaExistsGuard) + }) +}) diff --git a/apps/judicial-system/backend/src/app/modules/subpoena/test/internalSubpoenaController/deliverSubpoenaToCourt.spec.ts b/apps/judicial-system/backend/src/app/modules/subpoena/test/internalSubpoenaController/deliverSubpoenaToCourt.spec.ts new file mode 100644 index 000000000000..1601f396fc59 --- /dev/null +++ b/apps/judicial-system/backend/src/app/modules/subpoena/test/internalSubpoenaController/deliverSubpoenaToCourt.spec.ts @@ -0,0 +1,111 @@ +import { uuid } from 'uuidv4' + +import { createTestingSubpoenaModule } from '../createTestingSubpoenaModule' + +import { Case, PdfService } from '../../../case' +import { CourtService } from '../../../court' +import { Defendant } from '../../../defendant' +import { DeliverDto } from '../../dto/deliver.dto' +import { DeliverResponse } from '../../models/deliver.response' +import { Subpoena } from '../../models/subpoena.model' + +interface Then { + result: DeliverResponse + error: Error +} + +type GivenWhenThen = () => Promise + +describe('InternalSubpoenaController - Deliver subpoena to court', () => { + const caseId = uuid() + const courtId = uuid() + const courtCaseNumber = uuid() + const subpoenaId = uuid() + const defendantId = uuid() + const defendantName = uuid() + + const subpoena = { id: subpoenaId } as Subpoena + const defendant = { + id: defendantId, + name: defendantName, + subpoenas: [subpoena], + } as Defendant + const theCase = { + id: caseId, + courtId, + courtCaseNumber, + defendants: [defendant], + } as Case + const user = { id: uuid() } + const dto = { user } as DeliverDto + + let mockPdfService: PdfService + let mockCourtService: CourtService + let givenWhenThen: GivenWhenThen + + beforeEach(async () => { + const { courtService, pdfService, internalSubpoenaController } = + await createTestingSubpoenaModule() + + mockPdfService = pdfService + const mockGetSubpoenaPdf = mockPdfService.getSubpoenaPdf as jest.Mock + mockGetSubpoenaPdf.mockRejectedValue(new Error('Some error')) + + mockCourtService = courtService + const mockCreateDocument = mockCourtService.createDocument as jest.Mock + mockCreateDocument.mockRejectedValue(new Error('Some error')) + + givenWhenThen = async () => { + const then = {} as Then + + await internalSubpoenaController + .deliverSubpoenaToCourt( + caseId, + defendantId, + subpoenaId, + theCase, + defendant, + subpoena, + dto, + ) + .then((result) => (then.result = result)) + .catch((error) => (then.error = error)) + + return then + } + }) + + describe('subpoena delivered to court', () => { + const subpoenaPdf = uuid() + let then: Then + + beforeEach(async () => { + const mockGetSubpoenaPdf = mockPdfService.getSubpoenaPdf as jest.Mock + mockGetSubpoenaPdf.mockResolvedValue(subpoenaPdf) + const mockCreateDocument = mockCourtService.createDocument as jest.Mock + mockCreateDocument.mockResolvedValue('') + + then = await givenWhenThen() + }) + + it('should deliver the subpoena', () => { + expect(mockPdfService.getSubpoenaPdf).toBeCalledWith( + theCase, + defendant, + subpoena, + ) + expect(mockCourtService.createDocument).toBeCalledWith( + user, + caseId, + courtId, + courtCaseNumber, + 'Boðanir', + `Fyrirkall - ${defendantName}`, + `Fyrirkall - ${defendantName}.pdf`, + 'application/pdf', + subpoenaPdf, + ) + expect(then.result).toEqual({ delivered: true }) + }) + }) +}) diff --git a/apps/judicial-system/backend/src/app/modules/subpoena/test/internalSubpoenaController/deliverSubpoenaToPolice.spec.ts b/apps/judicial-system/backend/src/app/modules/subpoena/test/internalSubpoenaController/deliverSubpoenaToPolice.spec.ts index 43255bd30aa1..af9318d82a20 100644 --- a/apps/judicial-system/backend/src/app/modules/subpoena/test/internalSubpoenaController/deliverSubpoenaToPolice.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/subpoena/test/internalSubpoenaController/deliverSubpoenaToPolice.spec.ts @@ -2,14 +2,14 @@ import { uuid } from 'uuidv4' import { createTestingSubpoenaModule } from '../createTestingSubpoenaModule' -import { Case } from '../../../case' +import { Case, PdfService } from '../../../case' import { Defendant } from '../../../defendant' import { DeliverDto } from '../../dto/deliver.dto' import { DeliverResponse } from '../../models/deliver.response' import { Subpoena } from '../../models/subpoena.model' -import { SubpoenaService } from '../../subpoena.service' interface Then { + result: DeliverResponse error: Error } @@ -22,57 +22,59 @@ describe('InternalSubpoenaController - Deliver subpoena to police', () => { const subpoena = { id: subpoenaId } as Subpoena const defendant = { id: defendantId, subpoenas: [subpoena] } as Defendant - const theCase = { id: caseId } as Case - const user = { user: { id: uuid() } } as DeliverDto - const delivered = { delivered: true } as DeliverResponse + const theCase = { id: caseId, defendants: [defendant] } as Case + const user = { id: uuid() } + const dto = { user } as DeliverDto - let mockSubpoenaService: SubpoenaService + let mockPdfService: PdfService let givenWhenThen: GivenWhenThen beforeEach(async () => { - const { subpoenaService, internalSubpoenaController } = + const { pdfService, internalSubpoenaController } = await createTestingSubpoenaModule() - mockSubpoenaService = subpoenaService - - const deliverSubpoenaToPoliceMock = jest.fn() - mockSubpoenaService.deliverSubpoenaToPolice = deliverSubpoenaToPoliceMock - - deliverSubpoenaToPoliceMock.mockResolvedValueOnce(delivered) + mockPdfService = pdfService + const mockGetSubpoenaPdf = mockPdfService.getSubpoenaPdf as jest.Mock + mockGetSubpoenaPdf.mockRejectedValue(new Error('Some error')) givenWhenThen = async () => { const then = {} as Then - try { - await internalSubpoenaController.deliverSubpoenaToPolice( + await internalSubpoenaController + .deliverSubpoenaToPolice( caseId, defendantId, subpoenaId, theCase, defendant, subpoena, - user, + dto, ) - } catch (error) { - then.error = error as Error - } + .then((result) => (then.result = result)) + .catch((error) => (then.error = error)) return then } }) describe('subpoena delivered to police', () => { + const subpoenaPdf = uuid() + let then: Then + beforeEach(async () => { - await givenWhenThen() + const mockGetSubpoenaPdf = mockPdfService.getSubpoenaPdf as jest.Mock + mockGetSubpoenaPdf.mockResolvedValue(subpoenaPdf) + + then = await givenWhenThen() }) it('should call deliverSubpoenaToPolice', () => { - expect(mockSubpoenaService.deliverSubpoenaToPolice).toHaveBeenCalledWith( + expect(mockPdfService.getSubpoenaPdf).toBeCalledWith( theCase, defendant, subpoena, - user.user, ) + // TODO: complege tests when all indictments are generated }) }) }) diff --git a/apps/judicial-system/backend/src/app/modules/subpoena/test/internalSubpoenaController/updateSubpoeanaGuards.spec.ts b/apps/judicial-system/backend/src/app/modules/subpoena/test/internalSubpoenaController/updateSubpoeanaGuards.spec.ts index 1cad7bd28cdb..33106b7cc5a8 100644 --- a/apps/judicial-system/backend/src/app/modules/subpoena/test/internalSubpoenaController/updateSubpoeanaGuards.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/subpoena/test/internalSubpoenaController/updateSubpoeanaGuards.spec.ts @@ -1,7 +1,7 @@ import { PoliceSubpoenaExistsGuard } from '../../guards/policeSubpoenaExists.guard' import { InternalSubpoenaController } from '../../internalSubpoena.controller' -describe('InternalSubpoenaController - Update subpoena guards', () => { +describe('InternalSubpoenaController - Update subpoena guards', () => { // eslint-disable-next-line @typescript-eslint/no-explicit-any let guards: any[] diff --git a/libs/judicial-system/message/src/lib/message.ts b/libs/judicial-system/message/src/lib/message.ts index c93854bab4e6..0aa539df861e 100644 --- a/libs/judicial-system/message/src/lib/message.ts +++ b/libs/judicial-system/message/src/lib/message.ts @@ -11,6 +11,7 @@ export enum MessageType { 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', + DELIVERY_TO_COURT_SUBPOENA = 'DELIVERY_TO_COURT_SUBPOENA', DELIVERY_TO_COURT_COURT_RECORD = 'DELIVERY_TO_COURT_COURT_RECORD', DELIVERY_TO_COURT_SIGNED_RULING = 'DELIVERY_TO_COURT_SIGNED_RULING', DELIVERY_TO_COURT_CASE_CONCLUSION = 'DELIVERY_TO_COURT_CASE_CONCLUSION', @@ -48,6 +49,7 @@ export const messageEndpoint: { [key in MessageType]: string } = { DELIVERY_TO_COURT_CASE_FILE: 'deliverCaseFileToCourt', DELIVERY_TO_COURT_CASE_FILES_RECORD: 'deliverCaseFilesRecordToCourt', DELIVERY_TO_COURT_REQUEST: 'deliverRequestToCourt', + DELIVERY_TO_COURT_SUBPOENA: 'deliverSubpoenaToCourt', DELIVERY_TO_COURT_COURT_RECORD: 'deliverCourtRecordToCourt', DELIVERY_TO_COURT_SIGNED_RULING: 'deliverSignedRulingToCourt', DELIVERY_TO_COURT_CASE_CONCLUSION: 'deliverCaseConclusionToCourt', From 9a0fd741bb62059dd517e2fb06b6e87e242778fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0j=C3=B3n=20Gu=C3=B0j=C3=B3nsson?= Date: Fri, 13 Dec 2024 19:17:09 +0000 Subject: [PATCH 2/3] Updates tests --- .../src/app/modules/case/case.service.ts | 5 +++- .../modules/case/internalCase.controller.ts | 5 +++- .../case/test/caseController/update.spec.ts | 12 +++++++++ .../deliverProsecutorToCourtGuards.spec.ts | 25 ++++++++----------- .../src/app/modules/court/court.service.ts | 1 + 5 files changed, 32 insertions(+), 16 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 715281001a39..95ec317f3148 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 @@ -1380,7 +1380,10 @@ export class CaseService { await this.addMessagesForCourtCaseConnectionToQueue(updatedCase, user) } } else { - if (updatedCase.prosecutorId !== theCase.prosecutorId) { + if ( + !isIndictment && + updatedCase.prosecutorId !== theCase.prosecutorId + ) { // New prosecutor await this.addMessagesForProsecutorChangeToQueue(updatedCase, user) } 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 60991a38b33f..785d2bd0fb61 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 @@ -116,7 +116,10 @@ export class InternalCaseController { ) } - @UseGuards(CaseExistsGuard) + @UseGuards( + CaseExistsGuard, + new CaseTypeGuard([...restrictionCases, ...investigationCases]), + ) @Post( `case/:caseId/${messageEndpoint[MessageType.DELIVERY_TO_COURT_PROSECUTOR]}`, ) diff --git a/apps/judicial-system/backend/src/app/modules/case/test/caseController/update.spec.ts b/apps/judicial-system/backend/src/app/modules/case/test/caseController/update.spec.ts index b3b0bb816313..51d7fd6c5d6e 100644 --- a/apps/judicial-system/backend/src/app/modules/case/test/caseController/update.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/case/test/caseController/update.spec.ts @@ -897,12 +897,24 @@ describe('CaseController - Update', () => { caseId: theCase.id, elementId: [defendantId1, subpoenaId1], }, + { + type: MessageType.DELIVERY_TO_COURT_SUBPOENA, + user, + caseId: theCase.id, + elementId: [defendantId1, subpoenaId1], + }, { type: MessageType.DELIVERY_TO_POLICE_SUBPOENA, user, caseId: theCase.id, elementId: [defendantId2, subpoenaId2], }, + { + type: MessageType.DELIVERY_TO_COURT_SUBPOENA, + user, + caseId: theCase.id, + elementId: [defendantId2, subpoenaId2], + }, ]) }) }) diff --git a/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverProsecutorToCourtGuards.spec.ts b/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverProsecutorToCourtGuards.spec.ts index 4e5a488ca75b..3c13895d77c9 100644 --- a/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverProsecutorToCourtGuards.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverProsecutorToCourtGuards.spec.ts @@ -1,6 +1,10 @@ -import { CanActivate } from '@nestjs/common' +import { + investigationCases, + restrictionCases, +} 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 prosecutor to court guards', () => { @@ -14,19 +18,12 @@ describe('InternalCaseController - Deliver prosecutor to court guards', () => { ) }) - it('should have one guards', () => { - expect(guards).toHaveLength(1) - }) - - describe('CaseExistsGuard', () => { - let guard: CanActivate - - beforeEach(() => { - guard = new guards[0]() - }) - - it('should have CaseExistsGuard as guard 1', () => { - expect(guard).toBeInstanceOf(CaseExistsGuard) + it('should have the right guard configuration', () => { + expect(guards).toHaveLength(2) + expect(new guards[0]()).toBeInstanceOf(CaseExistsGuard) + expect(guards[1]).toBeInstanceOf(CaseTypeGuard) + expect(guards[1]).toEqual({ + allowedCaseTypes: [...restrictionCases, ...investigationCases], }) }) }) 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 8629da76d330..dfe5e4e88579 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 @@ -343,6 +343,7 @@ export class CourtService { return await this.courtClientService.createCase(courtId, { caseType: isIndictment ? 'S - Ákærumál' : 'R - Rannsóknarmál', + // TODO: send a list of subtypes when CourtService supports it subtype: courtSubtype as string, status: 'Skráð', receivalDate: formatISO(receivalDate, { representation: 'date' }), From bced4070a66a836073d1cb18be4d21413aa0ba53 Mon Sep 17 00:00:00 2001 From: unakb Date: Thu, 19 Dec 2024 13:35:23 +0000 Subject: [PATCH 3/3] Update apps/judicial-system/backend/src/app/modules/subpoena/test/internalSubpoenaController/deliverSubpoenaToPolice.spec.ts --- .../internalSubpoenaController/deliverSubpoenaToPolice.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/judicial-system/backend/src/app/modules/subpoena/test/internalSubpoenaController/deliverSubpoenaToPolice.spec.ts b/apps/judicial-system/backend/src/app/modules/subpoena/test/internalSubpoenaController/deliverSubpoenaToPolice.spec.ts index af9318d82a20..ff02a709d797 100644 --- a/apps/judicial-system/backend/src/app/modules/subpoena/test/internalSubpoenaController/deliverSubpoenaToPolice.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/subpoena/test/internalSubpoenaController/deliverSubpoenaToPolice.spec.ts @@ -74,7 +74,7 @@ describe('InternalSubpoenaController - Deliver subpoena to police', () => { defendant, subpoena, ) - // TODO: complege tests when all indictments are generated + // TODO: complete tests when all indictments are generated }) }) })