Skip to content

Commit

Permalink
fix(j-s): LÖKE File Upload (#16732)
Browse files Browse the repository at this point in the history
* Fix loke file upload

* Updates unit tests

---------

Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: Ívar Oddsson <[email protected]>
  • Loading branch information
3 people authored Nov 8, 2024
1 parent 30a0e38 commit 3445c32
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'))

Expand All @@ -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,
Expand All @@ -79,26 +79,25 @@ 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)

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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'))

Expand All @@ -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,
Expand All @@ -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)
Expand All @@ -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,
Expand Down

0 comments on commit 3445c32

Please sign in to comment.