diff --git a/src/app.module.ts b/src/app.module.ts index be364d4..8afd292 100644 --- a/src/app.module.ts +++ b/src/app.module.ts @@ -3,12 +3,14 @@ import { AutomapperModule } from '@automapper/nestjs'; import { Module } from '@nestjs/common'; import { ConfigModule } from '@nestjs/config'; import { AuthenticationModule } from './modules/authentication/authentication.module'; +import { AuthorizationModule } from './modules/authorization/authorization.module'; @Module({ imports: [ ConfigModule.forRoot({ isGlobal: true }), AutomapperModule.forRoot({ strategyInitializer: classes() }), AuthenticationModule, + AuthorizationModule, ], controllers: [], providers: [], diff --git a/src/modules/authorization/authorization.module.ts b/src/modules/authorization/authorization.module.ts index 91eb2d1..13dcf88 100644 --- a/src/modules/authorization/authorization.module.ts +++ b/src/modules/authorization/authorization.module.ts @@ -1,9 +1,11 @@ import { Module } from '@nestjs/common'; import { CqrsModule } from '@nestjs/cqrs'; +import { ValidateAuthenticationUseCase } from '../authentication/domain/usecases/validate-authentication.usecase'; import { DatabaseModule } from '../database/database.module'; @Module({ imports: [DatabaseModule, CqrsModule], exports: [], + providers: [ValidateAuthenticationUseCase], }) export class AuthorizationModule {} diff --git a/src/modules/authorization/domain/dtos/validate-authorization.request.ts b/src/modules/authorization/domain/dtos/validate-authorization.request.ts new file mode 100644 index 0000000..8bfbf72 --- /dev/null +++ b/src/modules/authorization/domain/dtos/validate-authorization.request.ts @@ -0,0 +1,11 @@ +import { IsNotEmpty, IsString } from 'class-validator'; + +export class ValidateAuthorizationRequest { + @IsString() + @IsNotEmpty() + uuid: string; + + @IsString() + @IsNotEmpty() + action: string; +} diff --git a/src/modules/authorization/tests/unit/validate-authorization.usecase.spec.ts b/src/modules/authorization/tests/unit/validate-authorization.usecase.spec.ts index ad2d1c2..f68d24e 100644 --- a/src/modules/authorization/tests/unit/validate-authorization.usecase.spec.ts +++ b/src/modules/authorization/tests/unit/validate-authorization.usecase.spec.ts @@ -1,6 +1,7 @@ import { classes } from '@automapper/classes'; import { AutomapperModule } from '@automapper/nestjs'; import { Test, TestingModule } from '@nestjs/testing'; +import { ValidateAuthorizationRequest } from '../../domain/dtos/validate-authorization.request'; import { ValidateAuthorizationUseCase } from '../../domain/usecases/validate-authorization.usecase'; describe('ValidateAuthorizationUseCase', () => { @@ -20,4 +21,18 @@ describe('ValidateAuthorizationUseCase', () => { it('should be defined', () => { expect(validateAuthorizationUseCase).toBeDefined(); }); + + describe('execute', () => { + it('should validate an authorization', async () => { + const validateAuthorizationRequest: ValidateAuthorizationRequest = + new ValidateAuthorizationRequest(); + validateAuthorizationRequest.uuid = + 'bb281075-1b98-4456-89d6-c643d3044a91'; + validateAuthorizationRequest.action = 'authorized'; + + expect( + validateAuthorizationUseCase.execute(validateAuthorizationRequest), + ).toBeTruthy(); + }); + }); });