-
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 subpoena revocation to police (#17291)
* feat(j-s): Revoke subpoenas from police when indictment cancelled * Update case.service.ts * feat(j-s): Send subpoena revocation to police * Create deliverSubpoenaRevokedToPoliceGuards.spec.ts --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
- Loading branch information
1 parent
4e1a04f
commit a7ec960
Showing
7 changed files
with
238 additions
and
2 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
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
73 changes: 73 additions & 0 deletions
73
...p/modules/subpoena/test/internalSubpoenaController/deliverSubpoenaRevokedToPolice.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,73 @@ | ||
import { uuid } from 'uuidv4' | ||
|
||
import { createTestingSubpoenaModule } from '../createTestingSubpoenaModule' | ||
|
||
import { Case } from '../../../case' | ||
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 { | ||
error: Error | ||
} | ||
|
||
type GivenWhenThen = () => Promise<Then> | ||
|
||
describe('InternalSubpoenaController - Deliver subpoena revocation to police', () => { | ||
const caseId = uuid() | ||
const subpoenaId = uuid() | ||
const defendantId = uuid() | ||
|
||
const subpoena = { id: subpoenaId } as Subpoena | ||
const theCase = { id: caseId } as Case | ||
const user = { user: { id: uuid() } } as DeliverDto | ||
const delivered = { delivered: true } as DeliverResponse | ||
|
||
let mockSubpoenaService: SubpoenaService | ||
let givenWhenThen: GivenWhenThen | ||
|
||
beforeEach(async () => { | ||
const { subpoenaService, internalSubpoenaController } = | ||
await createTestingSubpoenaModule() | ||
|
||
mockSubpoenaService = subpoenaService | ||
|
||
const deliverSubpoenaRevokedToPoliceMock = jest.fn() | ||
mockSubpoenaService.deliverSubpoenaRevokedToPolice = | ||
deliverSubpoenaRevokedToPoliceMock | ||
|
||
deliverSubpoenaRevokedToPoliceMock.mockResolvedValueOnce(delivered) | ||
|
||
givenWhenThen = async () => { | ||
const then = {} as Then | ||
|
||
try { | ||
await internalSubpoenaController.deliverSubpoenaRevokedToPolice( | ||
caseId, | ||
defendantId, | ||
subpoenaId, | ||
theCase, | ||
subpoena, | ||
user, | ||
) | ||
} catch (error) { | ||
then.error = error as Error | ||
} | ||
|
||
return then | ||
} | ||
}) | ||
|
||
describe('subpoena revoked delivered to police', () => { | ||
beforeEach(async () => { | ||
await givenWhenThen() | ||
}) | ||
|
||
it('should call deliverSubpoenaRevokedToPolice', () => { | ||
expect( | ||
mockSubpoenaService.deliverSubpoenaRevokedToPolice, | ||
).toHaveBeenCalledWith(theCase, subpoena, user.user) | ||
}) | ||
}) | ||
}) |
29 changes: 29 additions & 0 deletions
29
...les/subpoena/test/internalSubpoenaController/deliverSubpoenaRevokedToPoliceGuards.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,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 revoked to police guards', () => { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
let guards: any[] | ||
|
||
beforeEach(() => { | ||
guards = Reflect.getMetadata( | ||
'__guards__', | ||
InternalSubpoenaController.prototype.deliverSubpoenaRevokedToPolice, | ||
) | ||
}) | ||
|
||
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) | ||
}) | ||
}) |
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