test authorization module
This commit is contained in:
parent
1e5e0f2fbd
commit
50742fc53a
|
@ -3,12 +3,14 @@ import { AutomapperModule } from '@automapper/nestjs';
|
||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { ConfigModule } from '@nestjs/config';
|
import { ConfigModule } from '@nestjs/config';
|
||||||
import { AuthenticationModule } from './modules/authentication/authentication.module';
|
import { AuthenticationModule } from './modules/authentication/authentication.module';
|
||||||
|
import { AuthorizationModule } from './modules/authorization/authorization.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
ConfigModule.forRoot({ isGlobal: true }),
|
ConfigModule.forRoot({ isGlobal: true }),
|
||||||
AutomapperModule.forRoot({ strategyInitializer: classes() }),
|
AutomapperModule.forRoot({ strategyInitializer: classes() }),
|
||||||
AuthenticationModule,
|
AuthenticationModule,
|
||||||
|
AuthorizationModule,
|
||||||
],
|
],
|
||||||
controllers: [],
|
controllers: [],
|
||||||
providers: [],
|
providers: [],
|
||||||
|
|
|
@ -1,9 +1,11 @@
|
||||||
import { Module } from '@nestjs/common';
|
import { Module } from '@nestjs/common';
|
||||||
import { CqrsModule } from '@nestjs/cqrs';
|
import { CqrsModule } from '@nestjs/cqrs';
|
||||||
|
import { ValidateAuthenticationUseCase } from '../authentication/domain/usecases/validate-authentication.usecase';
|
||||||
import { DatabaseModule } from '../database/database.module';
|
import { DatabaseModule } from '../database/database.module';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [DatabaseModule, CqrsModule],
|
imports: [DatabaseModule, CqrsModule],
|
||||||
exports: [],
|
exports: [],
|
||||||
|
providers: [ValidateAuthenticationUseCase],
|
||||||
})
|
})
|
||||||
export class AuthorizationModule {}
|
export class AuthorizationModule {}
|
||||||
|
|
|
@ -0,0 +1,11 @@
|
||||||
|
import { IsNotEmpty, IsString } from 'class-validator';
|
||||||
|
|
||||||
|
export class ValidateAuthorizationRequest {
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
uuid: string;
|
||||||
|
|
||||||
|
@IsString()
|
||||||
|
@IsNotEmpty()
|
||||||
|
action: string;
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
import { classes } from '@automapper/classes';
|
import { classes } from '@automapper/classes';
|
||||||
import { AutomapperModule } from '@automapper/nestjs';
|
import { AutomapperModule } from '@automapper/nestjs';
|
||||||
import { Test, TestingModule } from '@nestjs/testing';
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
|
import { ValidateAuthorizationRequest } from '../../domain/dtos/validate-authorization.request';
|
||||||
import { ValidateAuthorizationUseCase } from '../../domain/usecases/validate-authorization.usecase';
|
import { ValidateAuthorizationUseCase } from '../../domain/usecases/validate-authorization.usecase';
|
||||||
|
|
||||||
describe('ValidateAuthorizationUseCase', () => {
|
describe('ValidateAuthorizationUseCase', () => {
|
||||||
|
@ -20,4 +21,18 @@ describe('ValidateAuthorizationUseCase', () => {
|
||||||
it('should be defined', () => {
|
it('should be defined', () => {
|
||||||
expect(validateAuthorizationUseCase).toBeDefined();
|
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();
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue