-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feature/web-pension-calculator-new-year-option
- Loading branch information
Showing
186 changed files
with
3,651 additions
and
1,978 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,7 +54,11 @@ describe('InternalCaseController - Deliver indictment info to court', () => { | |
{ eventType: EventType.INDICTMENT_CONFIRMED, created: indictmentDate }, | ||
], | ||
defendants: [{ name: 'Test Ákærði', nationalId: '1234567890' }], | ||
prosecutor: { name: 'Test Sækjandi', nationalId: '0101010101' }, | ||
prosecutor: { | ||
name: 'Test Sækjandi', | ||
nationalId: '0101010101', | ||
email: '[email protected]', | ||
}, | ||
} as Case | ||
|
||
let mockCourtService: CourtService | ||
|
124 changes: 124 additions & 0 deletions
124
...src/app/modules/case/test/internalCaseController/deliverSignedCourtRecordToPolice.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
import { Base64 } from 'js-base64' | ||
import { uuid } from 'uuidv4' | ||
|
||
import { | ||
CaseOrigin, | ||
CaseState, | ||
CaseType, | ||
User, | ||
} from '@island.is/judicial-system/types' | ||
|
||
import { createTestingCaseModule } from '../createTestingCaseModule' | ||
|
||
import { nowFactory } from '../../../../factories' | ||
import { randomDate } from '../../../../test' | ||
import { AwsS3Service } from '../../../aws-s3' | ||
import { PoliceDocumentType, PoliceService } from '../../../police' | ||
import { Case } from '../../models/case.model' | ||
import { DeliverResponse } from '../../models/deliver.response' | ||
|
||
jest.mock('../../../../factories') | ||
|
||
interface Then { | ||
result: DeliverResponse | ||
error: Error | ||
} | ||
|
||
type GivenWhenThen = (caseId: string, theCase: Case) => Promise<Then> | ||
|
||
describe('InternalCaseController - Deliver signed court record to police', () => { | ||
const userId = uuid() | ||
const user = { id: userId } as User | ||
|
||
let mockAwsS3Service: AwsS3Service | ||
let mockPoliceService: PoliceService | ||
let givenWhenThen: GivenWhenThen | ||
|
||
beforeEach(async () => { | ||
const { awsS3Service, policeService, internalCaseController } = | ||
await createTestingCaseModule() | ||
|
||
mockAwsS3Service = awsS3Service | ||
mockPoliceService = policeService | ||
|
||
const mockGetGeneratedObject = | ||
awsS3Service.getGeneratedRequestCaseObject as jest.Mock | ||
mockGetGeneratedObject.mockRejectedValue(new Error('Some error')) | ||
const mockUpdatePoliceCase = mockPoliceService.updatePoliceCase as jest.Mock | ||
mockUpdatePoliceCase.mockRejectedValue(new Error('Some error')) | ||
|
||
givenWhenThen = async (caseId: string, theCase: Case) => { | ||
const then = {} as Then | ||
|
||
await internalCaseController | ||
.deliverSignedCourtRecordToPolice(caseId, theCase, { user }) | ||
.then((result) => (then.result = result)) | ||
.catch((error) => (then.error = error)) | ||
|
||
return then | ||
} | ||
}) | ||
|
||
describe('deliver case to police', () => { | ||
const caseId = uuid() | ||
const caseType = CaseType.PHONE_TAPPING | ||
const caseState = CaseState.ACCEPTED | ||
const policeCaseNumber = uuid() | ||
const courtCaseNumber = uuid() | ||
const defendantNationalId = '0123456789' | ||
const validToDate = randomDate() | ||
const caseConclusion = 'test conclusion' | ||
const theCase = { | ||
id: caseId, | ||
origin: CaseOrigin.LOKE, | ||
type: caseType, | ||
state: caseState, | ||
policeCaseNumbers: [policeCaseNumber], | ||
courtCaseNumber, | ||
defendants: [{ nationalId: defendantNationalId }], | ||
validToDate, | ||
conclusion: caseConclusion, | ||
} as Case | ||
const courtRecordPdf = 'test court record' | ||
|
||
let then: Then | ||
|
||
beforeEach(async () => { | ||
const mockToday = nowFactory as jest.Mock | ||
mockToday.mockReturnValueOnce(validToDate) | ||
|
||
const mockGetGeneratedObject = | ||
mockAwsS3Service.getGeneratedRequestCaseObject as jest.Mock | ||
mockGetGeneratedObject.mockResolvedValueOnce(courtRecordPdf) | ||
const mockUpdatePoliceCase = | ||
mockPoliceService.updatePoliceCase as jest.Mock | ||
mockUpdatePoliceCase.mockResolvedValueOnce(true) | ||
|
||
then = await givenWhenThen(caseId, theCase) | ||
}) | ||
|
||
it('should update the police case with a signed court record', async () => { | ||
expect( | ||
mockAwsS3Service.getGeneratedRequestCaseObject, | ||
).toHaveBeenCalledWith(caseType, `${caseId}/courtRecord.pdf`) | ||
expect(mockPoliceService.updatePoliceCase).toHaveBeenCalledWith( | ||
user, | ||
caseId, | ||
caseType, | ||
caseState, | ||
policeCaseNumber, | ||
courtCaseNumber, | ||
defendantNationalId, | ||
validToDate, | ||
caseConclusion, | ||
[ | ||
{ | ||
type: PoliceDocumentType.RVTB, | ||
courtDocument: Base64.btoa(courtRecordPdf), | ||
}, | ||
], | ||
) | ||
expect(then.result.delivered).toEqual(true) | ||
}) | ||
}) | ||
}) |
66 changes: 66 additions & 0 deletions
66
...p/modules/case/test/internalCaseController/deliverSignedCourtRecordToPoliceGuards.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { CanActivate } from '@nestjs/common' | ||
|
||
import { | ||
investigationCases, | ||
restrictionCases, | ||
} from '@island.is/judicial-system/types' | ||
|
||
import { CaseCompletedGuard } from '../../guards/caseCompleted.guard' | ||
import { CaseExistsGuard } from '../../guards/caseExists.guard' | ||
import { CaseTypeGuard } from '../../guards/caseType.guard' | ||
import { InternalCaseController } from '../../internalCase.controller' | ||
|
||
describe('InternalCaseController - Deliver signed court record to police guards', () => { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
let guards: any[] | ||
|
||
beforeEach(() => { | ||
guards = Reflect.getMetadata( | ||
'__guards__', | ||
InternalCaseController.prototype.deliverSignedCourtRecordToPolice, | ||
) | ||
}) | ||
|
||
it('should have three guards', () => { | ||
expect(guards).toHaveLength(3) | ||
}) | ||
|
||
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: [...restrictionCases, ...investigationCases], | ||
}) | ||
}) | ||
}) | ||
|
||
describe('CaseCompletedGuard', () => { | ||
let guard: CanActivate | ||
|
||
beforeEach(() => { | ||
guard = new guards[2]() | ||
}) | ||
|
||
it('should have CaseCompletedGuard as guard 3', () => { | ||
expect(guard).toBeInstanceOf(CaseCompletedGuard) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.