-
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.
chore(j-s): Civil claimant spokesperson assigned notifications (#16750)
* feat(j-s): Handle advocate assigned to defendant notification * Update defendant.service.ts * feat(j-s): Send civil claimant notification when assigned * Update defendantNotification.service.ts * fix(j-s): Small fix on modal texts * fix(j-s): Stop using advocate for defender emails * fix(j-s): remove advocate assigned from user roles rules * fix(j-s): remove and change tests * fix(j-s): Tests * test(j-s): Defendant notification tests * Update update.spec.ts * Update update.spec.ts * Update sendDefenderAssignedNotifications.spec.ts * Update defendantNotification.service.ts * test(j-s): Add tests * fix(j-s): Tests * test(j-s): Added more civil claimant tests * test(j-s): Added more civil claimant tests * Update civilClaimantNotification.service.ts * Update internalNotification.controller.ts * Update notification.module.ts * Update sendAdvocateAssignedNotifications.spec.ts * Update civilClaimant.service.ts * Update civilClaimant.service.ts * test(j-s): Civil claimant exists guard tests --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com> Co-authored-by: Guðjón Guðjónsson <gudjon@kolibri.is>
- Loading branch information
Showing
30 changed files
with
1,124 additions
and
263 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
7 changes: 7 additions & 0 deletions
7
apps/judicial-system/backend/src/app/modules/defendant/guards/civilClaimaint.decorator.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,7 @@ | ||
import { createParamDecorator } from '@nestjs/common' | ||
|
||
import { CivilClaimant } from '../models/civilClaimant.model' | ||
|
||
export const CurrentCivilClaimant = createParamDecorator( | ||
(data, { args: [_1, { req }] }): CivilClaimant => req.civilClaimant, | ||
) |
42 changes: 42 additions & 0 deletions
42
apps/judicial-system/backend/src/app/modules/defendant/guards/civilClaimantExists.guard.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,42 @@ | ||
import { | ||
BadRequestException, | ||
CanActivate, | ||
ExecutionContext, | ||
Injectable, | ||
NotFoundException, | ||
} from '@nestjs/common' | ||
|
||
import { Case } from '../../case' | ||
|
||
@Injectable() | ||
export class CivilClaimantExistsGuard implements CanActivate { | ||
canActivate(context: ExecutionContext): boolean { | ||
const request = context.switchToHttp().getRequest() | ||
|
||
const theCase: Case = request.case | ||
|
||
if (!theCase) { | ||
throw new BadRequestException('Missing case') | ||
} | ||
|
||
const civilClaimantId = request.params.civilClaimantId | ||
|
||
if (!civilClaimantId) { | ||
throw new BadRequestException('Missing civil claimant id') | ||
} | ||
|
||
const civilClaimant = theCase.civilClaimants?.find( | ||
(civilClaimants) => civilClaimants.id === civilClaimantId, | ||
) | ||
|
||
if (!civilClaimant) { | ||
throw new NotFoundException( | ||
`Civil claimant ${civilClaimantId} of case ${theCase.id} does not exist`, | ||
) | ||
} | ||
|
||
request.civilClaimant = civilClaimant | ||
|
||
return true | ||
} | ||
} |
117 changes: 117 additions & 0 deletions
117
...ial-system/backend/src/app/modules/defendant/guards/test/civilClaimantExistsGuard.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,117 @@ | ||
import { uuid } from 'uuidv4' | ||
|
||
import { | ||
BadRequestException, | ||
ExecutionContext, | ||
NotFoundException, | ||
} from '@nestjs/common' | ||
|
||
import { CivilClaimantExistsGuard } from '../civilClaimantExists.guard' | ||
|
||
interface Then { | ||
result: boolean | ||
error: Error | ||
} | ||
|
||
type GivenWhenThen = () => Promise<Then> | ||
|
||
describe('Civil Claimant Exists Guard', () => { | ||
const mockRequest = jest.fn() | ||
let givenWhenThen: GivenWhenThen | ||
|
||
beforeEach(async () => { | ||
givenWhenThen = async (): Promise<Then> => { | ||
const guard = new CivilClaimantExistsGuard() | ||
const then = {} as Then | ||
|
||
try { | ||
then.result = guard.canActivate({ | ||
switchToHttp: () => ({ getRequest: mockRequest }), | ||
} as unknown as ExecutionContext) | ||
} catch (error) { | ||
then.error = error as Error | ||
} | ||
|
||
return then | ||
} | ||
}) | ||
|
||
describe('civil claimant exists', () => { | ||
const caseId = uuid() | ||
const civilClaimantId = uuid() | ||
const civilClaimant = { id: civilClaimantId, caseId } | ||
const theCase = { id: caseId, civilClaimants: [civilClaimant] } | ||
const request = { | ||
params: { caseId, civilClaimantId }, | ||
case: theCase, | ||
civilClaimant: undefined, | ||
} | ||
let then: Then | ||
|
||
beforeEach(async () => { | ||
mockRequest.mockReturnValueOnce(request) | ||
|
||
then = await givenWhenThen() | ||
}) | ||
|
||
it('should activate', () => { | ||
expect(then.result).toBe(true) | ||
expect(request.civilClaimant).toBe(civilClaimant) | ||
}) | ||
}) | ||
|
||
describe('civil claimant does not exist', () => { | ||
const caseId = uuid() | ||
const civilClaimantId = uuid() | ||
const theCase = { id: caseId, civilClaimants: [] } | ||
let then: Then | ||
|
||
beforeEach(async () => { | ||
mockRequest.mockReturnValueOnce({ | ||
params: { caseId, civilClaimantId }, | ||
case: theCase, | ||
}) | ||
|
||
then = await givenWhenThen() | ||
}) | ||
|
||
it('should throw NotFoundException', () => { | ||
expect(then.error).toBeInstanceOf(NotFoundException) | ||
expect(then.error.message).toBe( | ||
`Civil claimant ${civilClaimantId} of case ${caseId} does not exist`, | ||
) | ||
}) | ||
}) | ||
|
||
describe('missing case', () => { | ||
let then: Then | ||
|
||
beforeEach(async () => { | ||
mockRequest.mockReturnValueOnce({ params: {} }) | ||
|
||
then = await givenWhenThen() | ||
}) | ||
|
||
it('should throw BadRequestException', () => { | ||
expect(then.error).toBeInstanceOf(BadRequestException) | ||
expect(then.error.message).toBe('Missing case') | ||
}) | ||
}) | ||
|
||
describe('missing civil claimant id', () => { | ||
const caseId = uuid() | ||
const theCase = { id: caseId, civilClaimants: [] } | ||
let then: Then | ||
|
||
beforeEach(async () => { | ||
mockRequest.mockReturnValueOnce({ params: { caseId }, case: theCase }) | ||
|
||
then = await givenWhenThen() | ||
}) | ||
|
||
it('should throw BadRequestException', () => { | ||
expect(then.error).toBeInstanceOf(BadRequestException) | ||
expect(then.error.message).toBe('Missing civil claimant id') | ||
}) | ||
}) | ||
}) |
5 changes: 4 additions & 1 deletion
5
apps/judicial-system/backend/src/app/modules/defendant/index.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 |
---|---|---|
@@ -1,6 +1,9 @@ | ||
export { Defendant } from './models/defendant.model' | ||
export { DefendantService } from './defendant.service' | ||
export { CivilClaimant } from './models/civilClaimant.model' | ||
export { DefendantExistsGuard } from './guards/defendantExists.guard' | ||
export { CurrentDefendant } from './guards/defendant.decorator' | ||
|
||
export { CivilClaimant } from './models/civilClaimant.model' | ||
export { CivilClaimantService } from './civilClaimant.service' | ||
export { CivilClaimantExistsGuard } from './guards/civilClaimantExists.guard' | ||
export { CurrentCivilClaimant } from './guards/civilClaimaint.decorator' |
Oops, something went wrong.