test authorization module

This commit is contained in:
Gsk54 2023-01-16 17:25:53 +01:00
parent 1e5e0f2fbd
commit 50742fc53a
4 changed files with 30 additions and 0 deletions

View File

@ -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: [],

View File

@ -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 {}

View File

@ -0,0 +1,11 @@
import { IsNotEmpty, IsString } from 'class-validator';
export class ValidateAuthorizationRequest {
@IsString()
@IsNotEmpty()
uuid: string;
@IsString()
@IsNotEmpty()
action: string;
}

View File

@ -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();
});
});
});