fix(auth): add transition role only if the items transition has completed

This commit is contained in:
Karol Sójko 2023-09-12 21:26:40 +02:00
parent fab5d18064
commit f055e52e06
No known key found for this signature in database
GPG key ID: C2F813669419D05F
2 changed files with 20 additions and 1 deletions

View file

@ -39,6 +39,23 @@ describe('UpdateTransitionStatus', () => {
)
})
it('should remove transition status', async () => {
const useCase = createUseCase()
const result = await useCase.execute({
userUuid: '00000000-0000-0000-0000-000000000000',
status: 'FINISHED',
transitionType: 'revisions',
})
expect(result.isFailed()).toBeFalsy()
expect(transitionStatusRepository.removeStatus).toHaveBeenCalledWith(
'00000000-0000-0000-0000-000000000000',
'revisions',
)
expect(roleService.addRoleToUser).not.toHaveBeenCalled()
})
it('should update transition status', async () => {
const useCase = createUseCase()

View file

@ -19,7 +19,9 @@ export class UpdateTransitionStatus implements UseCaseInterface<void> {
if (dto.status === 'FINISHED') {
await this.transitionStatusRepository.removeStatus(dto.userUuid, dto.transitionType)
await this.roleService.addRoleToUser(userUuid, RoleName.create(RoleName.NAMES.TransitionUser).getValue())
if (dto.transitionType === 'items') {
await this.roleService.addRoleToUser(userUuid, RoleName.create(RoleName.NAMES.TransitionUser).getValue())
}
return Result.ok()
}