-
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.
feat(j-s): Deliver defender info to robot for indictment cases (#15191)
* feat(j-s): Deliver defender info to robot for indictment cases * Update deliverIndictmentDefenderInfoToCourt.spec.ts * Update court.service.ts --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
- Loading branch information
1 parent
878c6c8
commit e9b5864
Showing
7 changed files
with
284 additions
and
47 deletions.
There are no files selected for viewing
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
98 changes: 98 additions & 0 deletions
98
...app/modules/case/test/internalCaseController/deliverIndictmentDefenderInfoToCourt.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,98 @@ | ||
import { uuid } from 'uuidv4' | ||
|
||
import { CaseType, User } 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<Then> | ||
|
||
describe('InternalCaseController - Deliver indictment defender info to court', () => { | ||
const user = { id: uuid() } as User | ||
const caseId = uuid() | ||
const courtCaseNumber = uuid() | ||
|
||
const theCase = { | ||
id: caseId, | ||
type: CaseType.INDICTMENT, | ||
courtCaseNumber, | ||
defendants: [ | ||
{ | ||
name: 'Test Ákærði', | ||
nationalId: '1234567890', | ||
defenderNationalId: '1234567899', | ||
defenderName: 'Test Verjandi', | ||
defenderEmail: 'defenderEmail', | ||
}, | ||
{ | ||
name: 'Test Ákærði 2', | ||
nationalId: '1234567891', | ||
defenderNationalId: '1234567898', | ||
defenderName: 'Test Verjandi 2', | ||
defenderEmail: 'defenderEmail2', | ||
}, | ||
], | ||
} as Case | ||
|
||
let mockCourtService: jest.Mocked<CourtService> | ||
let givenWhenThen: GivenWhenThen | ||
|
||
beforeEach(async () => { | ||
const { courtService, internalCaseController } = | ||
await createTestingCaseModule() | ||
|
||
mockCourtService = courtService as jest.Mocked<CourtService> | ||
mockCourtService.updateIndictmentWithDefenderInfo.mockResolvedValue(uuid()) | ||
|
||
givenWhenThen = async (caseId: string, theCase: Case, body: DeliverDto) => { | ||
const then = {} as Then | ||
|
||
await internalCaseController | ||
.deliverIndictmentDefenderInfoToCourt(caseId, theCase, body) | ||
.then((result) => (then.result = result)) | ||
.catch((error) => (then.error = error)) | ||
|
||
return then | ||
} | ||
}) | ||
|
||
it('should deliver the defender information to court', async () => { | ||
const then = await givenWhenThen(caseId, theCase, { user }) | ||
|
||
expect( | ||
mockCourtService.updateIndictmentWithDefenderInfo, | ||
).toHaveBeenCalledWith( | ||
user, | ||
theCase.id, | ||
theCase.courtCaseNumber, | ||
theCase.defendants, | ||
) | ||
|
||
expect(then.result).toEqual({ delivered: true }) | ||
expect(then.error).toBeUndefined() | ||
}) | ||
|
||
it('should handle not deliver if error occurs', async () => { | ||
const error = new Error('Service error') | ||
mockCourtService.updateIndictmentWithDefenderInfo.mockRejectedValueOnce( | ||
error, | ||
) | ||
|
||
const then = await givenWhenThen(caseId, theCase, { user }) | ||
|
||
expect(then.result).toEqual({ delivered: false }) | ||
}) | ||
}) |
50 changes: 50 additions & 0 deletions
50
...dules/case/test/internalCaseController/deliverIndictmentDefenderInfoToCourtGuards.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,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 indictment defender info to court guards', () => { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
let guards: any[] | ||
|
||
beforeEach(() => { | ||
guards = Reflect.getMetadata( | ||
'__guards__', | ||
InternalCaseController.prototype.deliverIndictmentDefenderInfoToCourt, | ||
) | ||
}) | ||
|
||
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, | ||
}) | ||
}) | ||
}) | ||
}) |
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
Oops, something went wrong.