From 874854ebef3e2146e39d1a81fd6b5e948c904547 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0j=C3=B3n=20Gu=C3=B0j=C3=B3nsson?= Date: Tue, 5 Nov 2024 22:54:34 +0000 Subject: [PATCH 1/2] Fix loke file upload --- .../src/app/modules/case/internalCase.service.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 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 9fe3c7ad7d78..80385cf96b66 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 @@ -1005,9 +1005,9 @@ export class InternalCaseService { ) .map(async (caseFile) => { // TODO: Tolerate failure, but log error - const file = await this.awsS3Service.getObject( - theCase.type, - caseFile.key, + const file = await this.fileService.getCaseFileFromS3( + theCase, + caseFile, ) return { @@ -1154,9 +1154,9 @@ export class InternalCaseService { ?.filter((file) => file.category === CaseFileCategory.APPEAL_RULING) .map(async (caseFile) => { // TODO: Tolerate failure, but log error - const file = await this.awsS3Service.getObject( - theCase.type, - caseFile.key, + const file = await this.fileService.getCaseFileFromS3( + theCase, + caseFile, ) return { From 9d973b94800aa2be5924505c4cd81e7d065e9f04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gu=C3=B0j=C3=B3n=20Gu=C3=B0j=C3=B3nsson?= Date: Tue, 5 Nov 2024 23:24:27 +0000 Subject: [PATCH 2/2] Updates unit tests --- .../deliverAppealToPolice.spec.ts | 29 ++++++----- .../deliverIndictmentCaseToPolice.spec.ts | 48 +++++++++++-------- 2 files changed, 41 insertions(+), 36 deletions(-) diff --git a/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverAppealToPolice.spec.ts b/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverAppealToPolice.spec.ts index ce8748c18bbc..c5b896902f5f 100644 --- a/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverAppealToPolice.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverAppealToPolice.spec.ts @@ -13,7 +13,7 @@ import { import { createTestingCaseModule } from '../createTestingCaseModule' import { randomDate } from '../../../../test' -import { AwsS3Service } from '../../../aws-s3' +import { FileService } from '../../../file' import { PoliceDocumentType, PoliceService } from '../../../police' import { Case } from '../../models/case.model' import { DeliverResponse } from '../../models/deliver.response' @@ -29,19 +29,19 @@ describe('InternalCaseController - Deliver appeal to police', () => { const userId = uuid() const user = { id: userId } as User - let mockAwsS3Service: AwsS3Service + let mockFileService: FileService let mockPoliceService: PoliceService let givenWhenThen: GivenWhenThen beforeEach(async () => { - const { awsS3Service, policeService, internalCaseController } = + const { fileService, policeService, internalCaseController } = await createTestingCaseModule() - mockAwsS3Service = awsS3Service + mockFileService = fileService mockPoliceService = policeService - const mockGetGeneratedObject = awsS3Service.getObject as jest.Mock - mockGetGeneratedObject.mockRejectedValue(new Error('Some error')) + const mockGetCaseFileFromS3 = fileService.getCaseFileFromS3 as jest.Mock + mockGetCaseFileFromS3.mockRejectedValue(new Error('Some error')) const mockUpdatePoliceCase = mockPoliceService.updatePoliceCase as jest.Mock mockUpdatePoliceCase.mockRejectedValue(new Error('Some error')) @@ -66,8 +66,8 @@ describe('InternalCaseController - Deliver appeal to police', () => { const defendantNationalId = '0123456789' const validToDate = randomDate() const caseConclusion = 'test conclusion' - const appealRulingKey = uuid() const appealRulingPdf = 'test appeal ruling' + const caseFile = { id: uuid(), category: CaseFileCategory.APPEAL_RULING } const theCase = { id: caseId, origin: CaseOrigin.LOKE, @@ -79,16 +79,15 @@ describe('InternalCaseController - Deliver appeal to police', () => { defendants: [{ nationalId: defendantNationalId }], validToDate, conclusion: caseConclusion, - caseFiles: [ - { key: appealRulingKey, category: CaseFileCategory.APPEAL_RULING }, - ], + caseFiles: [caseFile], } as Case let then: Then beforeEach(async () => { - const mockGetGeneratedObject = mockAwsS3Service.getObject as jest.Mock - mockGetGeneratedObject.mockResolvedValueOnce(appealRulingPdf) + const mockGetCaseFileFromS3 = + mockFileService.getCaseFileFromS3 as jest.Mock + mockGetCaseFileFromS3.mockResolvedValueOnce(appealRulingPdf) const mockUpdatePoliceCase = mockPoliceService.updatePoliceCase as jest.Mock mockUpdatePoliceCase.mockResolvedValueOnce(true) @@ -96,9 +95,9 @@ describe('InternalCaseController - Deliver appeal to police', () => { then = await givenWhenThen(caseId, theCase) }) it('should update the police case', async () => { - expect(mockAwsS3Service.getObject).toHaveBeenCalledWith( - caseType, - appealRulingKey, + expect(mockFileService.getCaseFileFromS3).toHaveBeenCalledWith( + theCase, + caseFile, ) expect(mockPoliceService.updatePoliceCase).toHaveBeenCalledWith( user, diff --git a/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentCaseToPolice.spec.ts b/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentCaseToPolice.spec.ts index 6266632ddea0..d73af8dc79b8 100644 --- a/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentCaseToPolice.spec.ts +++ b/apps/judicial-system/backend/src/app/modules/case/test/internalCaseController/deliverIndictmentCaseToPolice.spec.ts @@ -13,7 +13,7 @@ import { createTestingCaseModule } from '../createTestingCaseModule' import { nowFactory } from '../../../../factories' import { randomDate } from '../../../../test' -import { AwsS3Service } from '../../../aws-s3' +import { FileService } from '../../../file' import { PoliceDocumentType, PoliceService } from '../../../police' import { Case } from '../../models/case.model' import { DeliverResponse } from '../../models/deliver.response' @@ -32,21 +32,21 @@ describe('InternalCaseController - Deliver indictment case to police', () => { const userId = uuid() const user = { id: userId } as User - let mockAwsS3Service: AwsS3Service + let mockFileService: FileService let mockPoliceService: PoliceService let givenWhenThen: GivenWhenThen beforeEach(async () => { - const { awsS3Service, policeService, internalCaseController } = + const { fileService, policeService, internalCaseController } = await createTestingCaseModule() - mockAwsS3Service = awsS3Service + mockFileService = fileService mockPoliceService = policeService const mockToday = nowFactory as jest.Mock mockToday.mockReturnValueOnce(date) - const mockGetObject = awsS3Service.getObject as jest.Mock - mockGetObject.mockRejectedValue(new Error('Some error')) + const mockGetCaseFileFromS3 = fileService.getCaseFileFromS3 as jest.Mock + mockGetCaseFileFromS3.mockRejectedValue(new Error('Some error')) const mockUpdatePoliceCase = mockPoliceService.updatePoliceCase as jest.Mock mockUpdatePoliceCase.mockRejectedValue(new Error('Some error')) @@ -69,10 +69,18 @@ describe('InternalCaseController - Deliver indictment case to police', () => { const policeCaseNumber = uuid() const courtCaseNumber = uuid() const defendantNationalId = '0123456789' - const courtRecordKey = uuid() const courtRecordPdf = 'test court record' - const rulingKey = uuid() const rulingPdf = 'test ruling' + const caseFile1 = { + id: uuid(), + key: uuid(), + category: CaseFileCategory.COURT_RECORD, + } + const caseFile2 = { + id: uuid(), + key: uuid(), + category: CaseFileCategory.RULING, + } const theCase = { id: caseId, origin: CaseOrigin.LOKE, @@ -81,18 +89,16 @@ describe('InternalCaseController - Deliver indictment case to police', () => { policeCaseNumbers: [policeCaseNumber], courtCaseNumber, defendants: [{ nationalId: defendantNationalId }], - caseFiles: [ - { key: courtRecordKey, category: CaseFileCategory.COURT_RECORD }, - { key: rulingKey, category: CaseFileCategory.RULING }, - ], + caseFiles: [caseFile1, caseFile2], } as Case let then: Then beforeEach(async () => { - const mockGetObject = mockAwsS3Service.getObject as jest.Mock - mockGetObject.mockResolvedValueOnce(courtRecordPdf) - mockGetObject.mockResolvedValueOnce(rulingPdf) + const mockGetCaseFileFromS3 = + mockFileService.getCaseFileFromS3 as jest.Mock + mockGetCaseFileFromS3.mockResolvedValueOnce(courtRecordPdf) + mockGetCaseFileFromS3.mockResolvedValueOnce(rulingPdf) const mockUpdatePoliceCase = mockPoliceService.updatePoliceCase as jest.Mock mockUpdatePoliceCase.mockResolvedValueOnce(true) @@ -101,13 +107,13 @@ describe('InternalCaseController - Deliver indictment case to police', () => { }) it('should update the police case', async () => { - expect(mockAwsS3Service.getObject).toHaveBeenCalledWith( - caseType, - courtRecordKey, + expect(mockFileService.getCaseFileFromS3).toHaveBeenCalledWith( + theCase, + caseFile1, ) - expect(mockAwsS3Service.getObject).toHaveBeenCalledWith( - caseType, - rulingKey, + expect(mockFileService.getCaseFileFromS3).toHaveBeenCalledWith( + theCase, + caseFile2, ) expect(mockPoliceService.updatePoliceCase).toHaveBeenCalledWith( user,