-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(shared && courses): fixing protected to and using it at the cour…
…ses controller
- Loading branch information
1 parent
2070486
commit 1508b6e
Showing
9 changed files
with
54 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,24 @@ | ||
import { faker } from '@faker-js/faker'; | ||
import { UserRole } from '@modules/user/domain/entities/user/user-role.enum'; | ||
import { Right } from '@shared/helpers/either'; | ||
import { RequestUserEntity } from './request-user.entity'; | ||
|
||
describe('RequestUserEntity', () => { | ||
it('should be able to instantiate', () => { | ||
const id = faker.string.uuid(); | ||
const email = faker.internet.email(); | ||
const roles = [UserRole.ADMIN]; | ||
|
||
const entity = RequestUserEntity.create({ | ||
id, | ||
email, | ||
roles, | ||
}); | ||
|
||
expect(entity).toBeInstanceOf(Right); | ||
|
||
expect((entity.value as RequestUserEntity).id).toBe(id); | ||
expect((entity.value as RequestUserEntity).email).toBe(email); | ||
expect((entity.value as RequestUserEntity).roles).toEqual(roles); | ||
}); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,22 @@ | ||
// protected-to.decorator.ts | ||
import { AuthJwtGuard } from '@modules/auth/infra/guards/auth-jwt.guard'; | ||
import { UserRole } from '@modules/user/domain/entities/user/user-role.enum'; | ||
import { | ||
applyDecorators, | ||
ForbiddenException, | ||
SetMetadata, | ||
UseGuards, | ||
} from '@nestjs/common'; | ||
import { | ||
ApiBearerAuth, | ||
ApiForbiddenResponse, | ||
ApiUnauthorizedResponse, | ||
} from '@nestjs/swagger'; | ||
import { ApiBearerAuth, ApiForbiddenResponse } from '@nestjs/swagger'; | ||
import { RolesGuard } from '../guards/role.guard'; | ||
|
||
export const ProtectedTo = (...roles: UserRole[]) => | ||
applyDecorators( | ||
SetMetadata('roles', roles), | ||
UseGuards(RolesGuard), | ||
UseGuards(AuthJwtGuard, RolesGuard), | ||
ApiBearerAuth(), | ||
ApiForbiddenResponse({ type: ForbiddenException }), | ||
ApiForbiddenResponse({ | ||
type: ForbiddenException, | ||
status: 403, | ||
description: 'Você não possui autorização para acessar esse recurso.', | ||
}), | ||
); |
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