-
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): Get connected Indictment cases to merge with (#15508)
* feat(j-s): Get connected indictment cases * fix(j-s): Added guards and roles tests * fix(j-s): Review comment * test(j-s): Added test for getConnectedCases * fix(j-s): AuditedAction type * fix(j-s): Update type * fix(j-s): Cleanup * fix(j-s): More cleanup * fix(j-s): Handle more than one defendant * fix(j-s): Merge conflict
- Loading branch information
Showing
23 changed files
with
446 additions
and
5 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
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
74 changes: 74 additions & 0 deletions
74
...udicial-system/backend/src/app/modules/case/test/caseController/getConnectedCases.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,74 @@ | ||
import { uuid } from 'uuidv4' | ||
|
||
import { User } from '@island.is/judicial-system/types' | ||
|
||
import { createTestingCaseModule } from '../createTestingCaseModule' | ||
|
||
import { Case } from '../../models/case.model' | ||
|
||
interface Then { | ||
result: Case[] | ||
error: Error | ||
} | ||
|
||
type GivenWhenThen = (caseId: string, theCase: Case) => Promise<Then> | ||
|
||
describe('CaseController - Get connected cases', () => { | ||
const user = { id: uuid() } as User | ||
let mockCaseModel: typeof Case | ||
let givenWhenThen: GivenWhenThen | ||
|
||
beforeEach(async () => { | ||
const { caseModel, caseController } = await createTestingCaseModule() | ||
mockCaseModel = caseModel | ||
|
||
givenWhenThen = async (caseId: string, theCase: Case) => { | ||
const then = {} as Then | ||
|
||
try { | ||
then.result = await caseController.getConnectedCases(caseId, theCase) | ||
} catch (error) { | ||
then.error = error as Error | ||
} | ||
|
||
return then | ||
} | ||
}) | ||
|
||
describe('case has no defendants', () => { | ||
const caseId = uuid() | ||
const theCase = { id: caseId } as Case | ||
let then: Then | ||
|
||
beforeEach(async () => { | ||
then = await givenWhenThen(caseId, theCase) | ||
}) | ||
|
||
it('should return an empty array', () => { | ||
expect(then.result).toEqual([]) | ||
}) | ||
}) | ||
|
||
describe('case has defendants', () => { | ||
const caseId = uuid() | ||
const defendantId1 = uuid() | ||
const defendantId2 = uuid() | ||
const theCase = { | ||
id: caseId, | ||
defendants: [{ id: defendantId1 }, { id: defendantId2 }], | ||
} as Case | ||
const connectedCase1 = { id: uuid() } as Case | ||
const connectedCase2 = { id: uuid() } as Case | ||
let then: Then | ||
|
||
beforeEach(async () => { | ||
const mockFindAll = mockCaseModel.findAll as jest.Mock | ||
mockFindAll.mockResolvedValueOnce([connectedCase1, connectedCase2]) | ||
then = await givenWhenThen(caseId, theCase) | ||
}) | ||
|
||
it('should return the connected cases', () => { | ||
expect(then.result).toEqual([connectedCase1, connectedCase2]) | ||
}) | ||
}) | ||
}) |
21 changes: 21 additions & 0 deletions
21
...l-system/backend/src/app/modules/case/test/caseController/getConnectedCasesGuards.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,21 @@ | ||
import { JwtAuthGuard } from '@island.is/judicial-system/auth' | ||
|
||
import { CaseController } from '../../case.controller' | ||
import { CaseExistsGuard } from '../../guards/caseExists.guard' | ||
|
||
describe('CaseController - Get connected cases by case id guards', () => { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
let guards: any[] | ||
|
||
beforeEach(() => { | ||
guards = Reflect.getMetadata( | ||
'__guards__', | ||
CaseController.prototype.getConnectedCases, | ||
) | ||
}) | ||
|
||
it('should have the right guard configuration', () => { | ||
expect(new guards[0]()).toBeInstanceOf(JwtAuthGuard) | ||
expect(new guards[1]()).toBeInstanceOf(CaseExistsGuard) | ||
}) | ||
}) |
25 changes: 25 additions & 0 deletions
25
...stem/backend/src/app/modules/case/test/caseController/getConnectedCasesRolesRules.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,25 @@ | ||
import { | ||
districtCourtAssistantRule, | ||
districtCourtJudgeRule, | ||
districtCourtRegistrarRule, | ||
} from '../../../../guards' | ||
import { CaseController } from '../../case.controller' | ||
|
||
describe('CaseController - Get connected cases by case id rules', () => { | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
let rules: any[] | ||
|
||
beforeEach(() => { | ||
rules = Reflect.getMetadata( | ||
'roles-rules', | ||
CaseController.prototype.getConnectedCases, | ||
) | ||
}) | ||
|
||
it('should give permission to roles', () => { | ||
expect(rules).toHaveLength(3) | ||
expect(rules).toContain(districtCourtJudgeRule) | ||
expect(rules).toContain(districtCourtRegistrarRule) | ||
expect(rules).toContain(districtCourtAssistantRule) | ||
}) | ||
}) |
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
Oops, something went wrong.