mirror of
https://gitlab.com/mobicoop/v3/service/auth.git
synced 2026-01-02 21:02:41 +00:00
test authorization module
This commit is contained in:
@@ -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: [],
|
||||
|
||||
@@ -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 {}
|
||||
|
||||
@@ -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 { 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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user