Merge branch 'refactorMessager' into 'main'
refactor message broker See merge request v3/service/auth!22
This commit is contained in:
commit
87e142fcfd
|
@ -7,6 +7,7 @@ DATABASE_URL="postgresql://auth:auth@v3-auth-db:5432/auth?schema=public"
|
||||||
|
|
||||||
# RABBIT MQ
|
# RABBIT MQ
|
||||||
RMQ_URI=amqp://v3-broker:5672
|
RMQ_URI=amqp://v3-broker:5672
|
||||||
|
RMQ_EXCHANGE=mobicoop
|
||||||
|
|
||||||
# POSTGRES
|
# POSTGRES
|
||||||
POSTGRES_IMAGE=postgres:15.0
|
POSTGRES_IMAGE=postgres:15.0
|
||||||
|
|
|
@ -5,9 +5,6 @@ SERVICE_PORT=5002
|
||||||
# PRISMA
|
# PRISMA
|
||||||
DATABASE_URL="postgresql://auth:auth@localhost:5602/auth?schema=public"
|
DATABASE_URL="postgresql://auth:auth@localhost:5602/auth?schema=public"
|
||||||
|
|
||||||
# RABBIT MQ
|
|
||||||
RMQ_URI=amqp://v3-broker:5672
|
|
||||||
|
|
||||||
# POSTGRES
|
# POSTGRES
|
||||||
POSTGRES_IMAGE=postgres:15.0
|
POSTGRES_IMAGE=postgres:15.0
|
||||||
|
|
||||||
|
|
|
@ -12,9 +12,7 @@ export class AuthenticationMessagerController {
|
||||||
constructor(private readonly _commandBus: CommandBus) {}
|
constructor(private readonly _commandBus: CommandBus) {}
|
||||||
|
|
||||||
@RabbitSubscribe({
|
@RabbitSubscribe({
|
||||||
exchange: 'user',
|
name: 'user-update',
|
||||||
routingKey: 'update',
|
|
||||||
queue: 'authentication-user-update',
|
|
||||||
})
|
})
|
||||||
public async userUpdatedHandler(message: string) {
|
public async userUpdatedHandler(message: string) {
|
||||||
const updatedUser = JSON.parse(message);
|
const updatedUser = JSON.parse(message);
|
||||||
|
@ -40,9 +38,7 @@ export class AuthenticationMessagerController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@RabbitSubscribe({
|
@RabbitSubscribe({
|
||||||
exchange: 'user',
|
name: 'user-delete',
|
||||||
routingKey: 'delete',
|
|
||||||
queue: 'authentication-user-delete',
|
|
||||||
})
|
})
|
||||||
public async userDeletedHandler(message: string) {
|
public async userDeletedHandler(message: string) {
|
||||||
const deletedUser = JSON.parse(message);
|
const deletedUser = JSON.parse(message);
|
||||||
|
|
|
@ -1,14 +0,0 @@
|
||||||
import { AmqpConnection } from '@golevelup/nestjs-rabbitmq';
|
|
||||||
import { Injectable } from '@nestjs/common';
|
|
||||||
import { IMessageBroker } from '../../domain/interfaces/message-broker';
|
|
||||||
|
|
||||||
@Injectable()
|
|
||||||
export class LoggingMessager extends IMessageBroker {
|
|
||||||
constructor(private readonly _amqpConnection: AmqpConnection) {
|
|
||||||
super('logging');
|
|
||||||
}
|
|
||||||
|
|
||||||
publish(routingKey: string, message: string): void {
|
|
||||||
this._amqpConnection.publish(this.exchange, routingKey, message);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,11 +1,15 @@
|
||||||
import { AmqpConnection } from '@golevelup/nestjs-rabbitmq';
|
import { AmqpConnection } from '@golevelup/nestjs-rabbitmq';
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
|
import { ConfigService } from '@nestjs/config';
|
||||||
import { IMessageBroker } from '../../domain/interfaces/message-broker';
|
import { IMessageBroker } from '../../domain/interfaces/message-broker';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AuthenticationMessager extends IMessageBroker {
|
export class Messager extends IMessageBroker {
|
||||||
constructor(private readonly _amqpConnection: AmqpConnection) {
|
constructor(
|
||||||
super('auth');
|
private readonly _amqpConnection: AmqpConnection,
|
||||||
|
configService: ConfigService,
|
||||||
|
) {
|
||||||
|
super(configService.get<string>('RMQ_EXCHANGE'));
|
||||||
}
|
}
|
||||||
|
|
||||||
publish(routingKey: string, message: string): void {
|
publish(routingKey: string, message: string): void {
|
|
@ -15,7 +15,7 @@ import { DeleteAuthenticationUseCase } from './domain/usecases/delete-authentica
|
||||||
import { RabbitMQModule } from '@golevelup/nestjs-rabbitmq';
|
import { RabbitMQModule } from '@golevelup/nestjs-rabbitmq';
|
||||||
import { ConfigModule, ConfigService } from '@nestjs/config';
|
import { ConfigModule, ConfigService } from '@nestjs/config';
|
||||||
import { AuthenticationMessagerController } from './adapters/primaries/authentication-messager.controller';
|
import { AuthenticationMessagerController } from './adapters/primaries/authentication-messager.controller';
|
||||||
import { LoggingMessager } from './adapters/secondaries/logging.messager';
|
import { Messager } from './adapters/secondaries/messager';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
|
@ -27,14 +27,20 @@ import { LoggingMessager } from './adapters/secondaries/logging.messager';
|
||||||
useFactory: async (configService: ConfigService) => ({
|
useFactory: async (configService: ConfigService) => ({
|
||||||
exchanges: [
|
exchanges: [
|
||||||
{
|
{
|
||||||
name: 'user',
|
name: configService.get<string>('RMQ_EXCHANGE'),
|
||||||
type: 'topic',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: 'logging',
|
|
||||||
type: 'topic',
|
type: 'topic',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
handlers: {
|
||||||
|
userUpdate: {
|
||||||
|
exchange: configService.get<string>('RMQ_EXCHANGE'),
|
||||||
|
routingKey: 'user.update',
|
||||||
|
},
|
||||||
|
userDelete: {
|
||||||
|
exchange: configService.get<string>('RMQ_EXCHANGE'),
|
||||||
|
routingKey: 'user.delete',
|
||||||
|
},
|
||||||
|
},
|
||||||
uri: configService.get<string>('RMQ_URI'),
|
uri: configService.get<string>('RMQ_URI'),
|
||||||
connectionInitOptions: { wait: false },
|
connectionInitOptions: { wait: false },
|
||||||
enableControllerDiscovery: true,
|
enableControllerDiscovery: true,
|
||||||
|
@ -46,7 +52,7 @@ import { LoggingMessager } from './adapters/secondaries/logging.messager';
|
||||||
AuthenticationProfile,
|
AuthenticationProfile,
|
||||||
UsernameProfile,
|
UsernameProfile,
|
||||||
AuthenticationRepository,
|
AuthenticationRepository,
|
||||||
LoggingMessager,
|
Messager,
|
||||||
ValidateAuthenticationUseCase,
|
ValidateAuthenticationUseCase,
|
||||||
CreateAuthenticationUseCase,
|
CreateAuthenticationUseCase,
|
||||||
AddUsernameUseCase,
|
AddUsernameUseCase,
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { CommandHandler } from '@nestjs/cqrs';
|
import { CommandHandler } from '@nestjs/cqrs';
|
||||||
import { LoggingMessager } from '../../adapters/secondaries/logging.messager';
|
import { Messager } from '../../adapters/secondaries/messager';
|
||||||
import { UsernameRepository } from '../../adapters/secondaries/username.repository';
|
import { UsernameRepository } from '../../adapters/secondaries/username.repository';
|
||||||
import { AddUsernameCommand } from '../../commands/add-username.command';
|
import { AddUsernameCommand } from '../../commands/add-username.command';
|
||||||
import { Username } from '../entities/username';
|
import { Username } from '../entities/username';
|
||||||
|
@ -8,7 +8,7 @@ import { Username } from '../entities/username';
|
||||||
export class AddUsernameUseCase {
|
export class AddUsernameUseCase {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly _usernameRepository: UsernameRepository,
|
private readonly _usernameRepository: UsernameRepository,
|
||||||
private readonly _loggingMessager: LoggingMessager,
|
private readonly _messager: Messager,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async execute(command: AddUsernameCommand): Promise<Username> {
|
async execute(command: AddUsernameCommand): Promise<Username> {
|
||||||
|
@ -20,8 +20,8 @@ export class AddUsernameUseCase {
|
||||||
username,
|
username,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this._loggingMessager.publish(
|
this._messager.publish(
|
||||||
'auth.username.add.warning',
|
'logging.auth.username.add.warning',
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
command,
|
command,
|
||||||
error,
|
error,
|
||||||
|
|
|
@ -4,14 +4,14 @@ import { CreateAuthenticationCommand } from '../../commands/create-authenticatio
|
||||||
import { Authentication } from '../entities/authentication';
|
import { Authentication } from '../entities/authentication';
|
||||||
import * as bcrypt from 'bcrypt';
|
import * as bcrypt from 'bcrypt';
|
||||||
import { UsernameRepository } from '../../adapters/secondaries/username.repository';
|
import { UsernameRepository } from '../../adapters/secondaries/username.repository';
|
||||||
import { LoggingMessager } from '../../adapters/secondaries/logging.messager';
|
import { Messager } from '../../adapters/secondaries/messager';
|
||||||
|
|
||||||
@CommandHandler(CreateAuthenticationCommand)
|
@CommandHandler(CreateAuthenticationCommand)
|
||||||
export class CreateAuthenticationUseCase {
|
export class CreateAuthenticationUseCase {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly _authenticationRepository: AuthenticationRepository,
|
private readonly _authenticationRepository: AuthenticationRepository,
|
||||||
private readonly _usernameRepository: UsernameRepository,
|
private readonly _usernameRepository: UsernameRepository,
|
||||||
private readonly _loggingMessager: LoggingMessager,
|
private readonly _messager: Messager,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async execute(command: CreateAuthenticationCommand): Promise<Authentication> {
|
async execute(command: CreateAuthenticationCommand): Promise<Authentication> {
|
||||||
|
@ -31,8 +31,8 @@ export class CreateAuthenticationUseCase {
|
||||||
|
|
||||||
return auth;
|
return auth;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this._loggingMessager.publish(
|
this._messager.publish(
|
||||||
'auth.create.crit',
|
'logging.auth.create.crit',
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
command,
|
command,
|
||||||
error,
|
error,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { CommandHandler } from '@nestjs/cqrs';
|
import { CommandHandler } from '@nestjs/cqrs';
|
||||||
import { AuthenticationRepository } from '../../adapters/secondaries/authentication.repository';
|
import { AuthenticationRepository } from '../../adapters/secondaries/authentication.repository';
|
||||||
import { LoggingMessager } from '../../adapters/secondaries/logging.messager';
|
import { Messager } from '../../adapters/secondaries/messager';
|
||||||
import { UsernameRepository } from '../../adapters/secondaries/username.repository';
|
import { UsernameRepository } from '../../adapters/secondaries/username.repository';
|
||||||
import { DeleteAuthenticationCommand } from '../../commands/delete-authentication.command';
|
import { DeleteAuthenticationCommand } from '../../commands/delete-authentication.command';
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@ export class DeleteAuthenticationUseCase {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly _authenticationRepository: AuthenticationRepository,
|
private readonly _authenticationRepository: AuthenticationRepository,
|
||||||
private readonly _usernameRepository: UsernameRepository,
|
private readonly _usernameRepository: UsernameRepository,
|
||||||
private readonly _loggingMessager: LoggingMessager,
|
private readonly _messager: Messager,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async execute(command: DeleteAuthenticationCommand) {
|
async execute(command: DeleteAuthenticationCommand) {
|
||||||
|
@ -21,8 +21,8 @@ export class DeleteAuthenticationUseCase {
|
||||||
command.deleteAuthenticationRequest.uuid,
|
command.deleteAuthenticationRequest.uuid,
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this._loggingMessager.publish(
|
this._messager.publish(
|
||||||
'auth.delete.crit',
|
'logging.auth.delete.crit',
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
command,
|
command,
|
||||||
error,
|
error,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { UnauthorizedException } from '@nestjs/common';
|
import { UnauthorizedException } from '@nestjs/common';
|
||||||
import { CommandHandler } from '@nestjs/cqrs';
|
import { CommandHandler } from '@nestjs/cqrs';
|
||||||
import { LoggingMessager } from '../../adapters/secondaries/logging.messager';
|
import { Messager } from '../../adapters/secondaries/messager';
|
||||||
import { UsernameRepository } from '../../adapters/secondaries/username.repository';
|
import { UsernameRepository } from '../../adapters/secondaries/username.repository';
|
||||||
import { DeleteUsernameCommand } from '../../commands/delete-username.command';
|
import { DeleteUsernameCommand } from '../../commands/delete-username.command';
|
||||||
|
|
||||||
|
@ -8,7 +8,7 @@ import { DeleteUsernameCommand } from '../../commands/delete-username.command';
|
||||||
export class DeleteUsernameUseCase {
|
export class DeleteUsernameUseCase {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly _usernameRepository: UsernameRepository,
|
private readonly _usernameRepository: UsernameRepository,
|
||||||
private readonly _loggingMessager: LoggingMessager,
|
private readonly _messager: Messager,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async execute(command: DeleteUsernameCommand) {
|
async execute(command: DeleteUsernameCommand) {
|
||||||
|
@ -25,8 +25,8 @@ export class DeleteUsernameUseCase {
|
||||||
}
|
}
|
||||||
throw new UnauthorizedException();
|
throw new UnauthorizedException();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this._loggingMessager.publish(
|
this._messager.publish(
|
||||||
'auth.username.delete.warning',
|
'logging.auth.username.delete.warning',
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
command,
|
command,
|
||||||
error,
|
error,
|
||||||
|
|
|
@ -3,13 +3,13 @@ import { AuthenticationRepository } from '../../adapters/secondaries/authenticat
|
||||||
import { Authentication } from '../entities/authentication';
|
import { Authentication } from '../entities/authentication';
|
||||||
import * as bcrypt from 'bcrypt';
|
import * as bcrypt from 'bcrypt';
|
||||||
import { UpdatePasswordCommand } from '../../commands/update-password.command';
|
import { UpdatePasswordCommand } from '../../commands/update-password.command';
|
||||||
import { LoggingMessager } from '../../adapters/secondaries/logging.messager';
|
import { Messager } from '../../adapters/secondaries/messager';
|
||||||
|
|
||||||
@CommandHandler(UpdatePasswordCommand)
|
@CommandHandler(UpdatePasswordCommand)
|
||||||
export class UpdatePasswordUseCase {
|
export class UpdatePasswordUseCase {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly _authenticationRepository: AuthenticationRepository,
|
private readonly _authenticationRepository: AuthenticationRepository,
|
||||||
private readonly _loggingMessager: LoggingMessager,
|
private readonly _messager: Messager,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async execute(command: UpdatePasswordCommand): Promise<Authentication> {
|
async execute(command: UpdatePasswordCommand): Promise<Authentication> {
|
||||||
|
@ -21,8 +21,8 @@ export class UpdatePasswordUseCase {
|
||||||
password: hash,
|
password: hash,
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this._loggingMessager.publish(
|
this._messager.publish(
|
||||||
'auth.password.update.warning',
|
'logging.auth.password.update.warning',
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
command,
|
command,
|
||||||
error,
|
error,
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { Mapper } from '@automapper/core';
|
||||||
import { InjectMapper } from '@automapper/nestjs';
|
import { InjectMapper } from '@automapper/nestjs';
|
||||||
import { BadRequestException } from '@nestjs/common';
|
import { BadRequestException } from '@nestjs/common';
|
||||||
import { CommandBus, CommandHandler } from '@nestjs/cqrs';
|
import { CommandBus, CommandHandler } from '@nestjs/cqrs';
|
||||||
import { LoggingMessager } from '../../adapters/secondaries/logging.messager';
|
import { Messager } from '../../adapters/secondaries/messager';
|
||||||
import { UsernameRepository } from '../../adapters/secondaries/username.repository';
|
import { UsernameRepository } from '../../adapters/secondaries/username.repository';
|
||||||
import { AddUsernameCommand } from '../../commands/add-username.command';
|
import { AddUsernameCommand } from '../../commands/add-username.command';
|
||||||
import { UpdateUsernameCommand } from '../../commands/update-username.command';
|
import { UpdateUsernameCommand } from '../../commands/update-username.command';
|
||||||
|
@ -16,7 +16,7 @@ export class UpdateUsernameUseCase {
|
||||||
private readonly _usernameRepository: UsernameRepository,
|
private readonly _usernameRepository: UsernameRepository,
|
||||||
private readonly _commandBus: CommandBus,
|
private readonly _commandBus: CommandBus,
|
||||||
@InjectMapper() private readonly _mapper: Mapper,
|
@InjectMapper() private readonly _mapper: Mapper,
|
||||||
private readonly _loggingMessager: LoggingMessager,
|
private readonly _messager: Messager,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
async execute(command: UpdateUsernameCommand): Promise<Username> {
|
async execute(command: UpdateUsernameCommand): Promise<Username> {
|
||||||
|
@ -41,8 +41,8 @@ export class UpdateUsernameUseCase {
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this._loggingMessager.publish(
|
this._messager.publish(
|
||||||
'auth.username.update.warning',
|
'logging.auth.username.update.warning',
|
||||||
JSON.stringify({
|
JSON.stringify({
|
||||||
command,
|
command,
|
||||||
error,
|
error,
|
||||||
|
|
|
@ -8,7 +8,7 @@ import { Type } from '../../domain/dtos/type.enum';
|
||||||
import { AddUsernameRequest } from '../../domain/dtos/add-username.request';
|
import { AddUsernameRequest } from '../../domain/dtos/add-username.request';
|
||||||
import { AddUsernameCommand } from '../../commands/add-username.command';
|
import { AddUsernameCommand } from '../../commands/add-username.command';
|
||||||
import { AddUsernameUseCase } from '../../domain/usecases/add-username.usecase';
|
import { AddUsernameUseCase } from '../../domain/usecases/add-username.usecase';
|
||||||
import { LoggingMessager } from '../../adapters/secondaries/logging.messager';
|
import { Messager } from '../../adapters/secondaries/messager';
|
||||||
|
|
||||||
const addUsernameRequest: AddUsernameRequest = {
|
const addUsernameRequest: AddUsernameRequest = {
|
||||||
uuid: 'bb281075-1b98-4456-89d6-c643d3044a91',
|
uuid: 'bb281075-1b98-4456-89d6-c643d3044a91',
|
||||||
|
@ -46,7 +46,7 @@ describe('AddUsernameUseCase', () => {
|
||||||
useValue: mockUsernameRepository,
|
useValue: mockUsernameRepository,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
provide: LoggingMessager,
|
provide: Messager,
|
||||||
useValue: mockMessager,
|
useValue: mockMessager,
|
||||||
},
|
},
|
||||||
AddUsernameUseCase,
|
AddUsernameUseCase,
|
||||||
|
|
|
@ -9,7 +9,7 @@ import { CreateAuthenticationUseCase } from '../../domain/usecases/create-authen
|
||||||
import * as bcrypt from 'bcrypt';
|
import * as bcrypt from 'bcrypt';
|
||||||
import { UsernameRepository } from '../../adapters/secondaries/username.repository';
|
import { UsernameRepository } from '../../adapters/secondaries/username.repository';
|
||||||
import { Type } from '../../domain/dtos/type.enum';
|
import { Type } from '../../domain/dtos/type.enum';
|
||||||
import { LoggingMessager } from '../../adapters/secondaries/logging.messager';
|
import { Messager } from '../../adapters/secondaries/messager';
|
||||||
|
|
||||||
const newAuthenticationRequest: CreateAuthenticationRequest =
|
const newAuthenticationRequest: CreateAuthenticationRequest =
|
||||||
new CreateAuthenticationRequest();
|
new CreateAuthenticationRequest();
|
||||||
|
@ -62,7 +62,7 @@ describe('CreateAuthenticationUseCase', () => {
|
||||||
useValue: mockUsernameRepository,
|
useValue: mockUsernameRepository,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
provide: LoggingMessager,
|
provide: Messager,
|
||||||
useValue: mockMessager,
|
useValue: mockMessager,
|
||||||
},
|
},
|
||||||
CreateAuthenticationUseCase,
|
CreateAuthenticationUseCase,
|
||||||
|
|
|
@ -2,7 +2,7 @@ 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 { AuthenticationRepository } from '../../adapters/secondaries/authentication.repository';
|
import { AuthenticationRepository } from '../../adapters/secondaries/authentication.repository';
|
||||||
import { LoggingMessager } from '../../adapters/secondaries/logging.messager';
|
import { Messager } from '../../adapters/secondaries/messager';
|
||||||
import { UsernameRepository } from '../../adapters/secondaries/username.repository';
|
import { UsernameRepository } from '../../adapters/secondaries/username.repository';
|
||||||
import { DeleteAuthenticationCommand } from '../../commands/delete-authentication.command';
|
import { DeleteAuthenticationCommand } from '../../commands/delete-authentication.command';
|
||||||
import { DeleteAuthenticationRequest } from '../../domain/dtos/delete-authentication.request';
|
import { DeleteAuthenticationRequest } from '../../domain/dtos/delete-authentication.request';
|
||||||
|
@ -69,7 +69,7 @@ describe('DeleteAuthenticationUseCase', () => {
|
||||||
useValue: mockUsernameRepository,
|
useValue: mockUsernameRepository,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
provide: LoggingMessager,
|
provide: Messager,
|
||||||
useValue: mockMessager,
|
useValue: mockMessager,
|
||||||
},
|
},
|
||||||
DeleteAuthenticationUseCase,
|
DeleteAuthenticationUseCase,
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { classes } from '@automapper/classes';
|
||||||
import { AutomapperModule } from '@automapper/nestjs';
|
import { AutomapperModule } from '@automapper/nestjs';
|
||||||
import { UnauthorizedException } from '@nestjs/common';
|
import { UnauthorizedException } from '@nestjs/common';
|
||||||
import { Test, TestingModule } from '@nestjs/testing';
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
import { LoggingMessager } from '../../adapters/secondaries/logging.messager';
|
import { Messager } from '../../adapters/secondaries/messager';
|
||||||
import { UsernameRepository } from '../../adapters/secondaries/username.repository';
|
import { UsernameRepository } from '../../adapters/secondaries/username.repository';
|
||||||
import { DeleteUsernameCommand } from '../../commands/delete-username.command';
|
import { DeleteUsernameCommand } from '../../commands/delete-username.command';
|
||||||
import { DeleteUsernameRequest } from '../../domain/dtos/delete-username.request';
|
import { DeleteUsernameRequest } from '../../domain/dtos/delete-username.request';
|
||||||
|
@ -82,7 +82,7 @@ describe('DeleteUsernameUseCase', () => {
|
||||||
useValue: mockUsernameRepository,
|
useValue: mockUsernameRepository,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
provide: LoggingMessager,
|
provide: Messager,
|
||||||
useValue: mockMessager,
|
useValue: mockMessager,
|
||||||
},
|
},
|
||||||
DeleteUsernameUseCase,
|
DeleteUsernameUseCase,
|
||||||
|
|
|
@ -1,36 +0,0 @@
|
||||||
import { AmqpConnection } from '@golevelup/nestjs-rabbitmq';
|
|
||||||
import { Test, TestingModule } from '@nestjs/testing';
|
|
||||||
import { LoggingMessager } from '../../adapters/secondaries/logging.messager';
|
|
||||||
|
|
||||||
const mockAmqpConnection = {
|
|
||||||
publish: jest.fn().mockImplementation(),
|
|
||||||
};
|
|
||||||
|
|
||||||
describe('LoggingMessager', () => {
|
|
||||||
let loggingMessager: LoggingMessager;
|
|
||||||
|
|
||||||
beforeAll(async () => {
|
|
||||||
const module: TestingModule = await Test.createTestingModule({
|
|
||||||
imports: [],
|
|
||||||
providers: [
|
|
||||||
LoggingMessager,
|
|
||||||
{
|
|
||||||
provide: AmqpConnection,
|
|
||||||
useValue: mockAmqpConnection,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
}).compile();
|
|
||||||
|
|
||||||
loggingMessager = module.get<LoggingMessager>(LoggingMessager);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should be defined', () => {
|
|
||||||
expect(LoggingMessager).toBeDefined();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should publish a message', async () => {
|
|
||||||
jest.spyOn(mockAmqpConnection, 'publish');
|
|
||||||
await loggingMessager.publish('authentication.create.info', 'my-test');
|
|
||||||
expect(mockAmqpConnection.publish).toHaveBeenCalledTimes(1);
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -1,41 +1,47 @@
|
||||||
import { AmqpConnection } from '@golevelup/nestjs-rabbitmq';
|
import { AmqpConnection } from '@golevelup/nestjs-rabbitmq';
|
||||||
|
import { ConfigService } from '@nestjs/config';
|
||||||
import { Test, TestingModule } from '@nestjs/testing';
|
import { Test, TestingModule } from '@nestjs/testing';
|
||||||
import { AuthenticationMessager } from '../../adapters/secondaries/authentication.messager';
|
import { Messager } from '../../adapters/secondaries/messager';
|
||||||
|
|
||||||
const mockAmqpConnection = {
|
const mockAmqpConnection = {
|
||||||
publish: jest.fn().mockImplementation(),
|
publish: jest.fn().mockImplementation(),
|
||||||
};
|
};
|
||||||
|
|
||||||
describe('AuthenticationMessager', () => {
|
const mockConfigService = {
|
||||||
let authenticationMessager: AuthenticationMessager;
|
get: jest.fn().mockResolvedValue({
|
||||||
|
RMQ_EXCHANGE: 'mobicoop',
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
|
||||||
|
describe('Messager', () => {
|
||||||
|
let messager: Messager;
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const module: TestingModule = await Test.createTestingModule({
|
const module: TestingModule = await Test.createTestingModule({
|
||||||
imports: [],
|
imports: [],
|
||||||
providers: [
|
providers: [
|
||||||
AuthenticationMessager,
|
Messager,
|
||||||
{
|
{
|
||||||
provide: AmqpConnection,
|
provide: AmqpConnection,
|
||||||
useValue: mockAmqpConnection,
|
useValue: mockAmqpConnection,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
provide: ConfigService,
|
||||||
|
useValue: mockConfigService,
|
||||||
|
},
|
||||||
],
|
],
|
||||||
}).compile();
|
}).compile();
|
||||||
|
|
||||||
authenticationMessager = module.get<AuthenticationMessager>(
|
messager = module.get<Messager>(Messager);
|
||||||
AuthenticationMessager,
|
|
||||||
);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be defined', () => {
|
it('should be defined', () => {
|
||||||
expect(authenticationMessager).toBeDefined();
|
expect(messager).toBeDefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should publish a message', async () => {
|
it('should publish a message', async () => {
|
||||||
jest.spyOn(mockAmqpConnection, 'publish');
|
jest.spyOn(mockAmqpConnection, 'publish');
|
||||||
await authenticationMessager.publish(
|
messager.publish('authentication.create.info', 'my-test');
|
||||||
'authentication.create.info',
|
|
||||||
'my-test',
|
|
||||||
);
|
|
||||||
expect(mockAmqpConnection.publish).toHaveBeenCalledTimes(1);
|
expect(mockAmqpConnection.publish).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
|
@ -7,7 +7,7 @@ import * as bcrypt from 'bcrypt';
|
||||||
import { UpdatePasswordRequest } from '../../domain/dtos/update-password.request';
|
import { UpdatePasswordRequest } from '../../domain/dtos/update-password.request';
|
||||||
import { UpdatePasswordCommand } from '../../commands/update-password.command';
|
import { UpdatePasswordCommand } from '../../commands/update-password.command';
|
||||||
import { UpdatePasswordUseCase } from '../../domain/usecases/update-password.usecase';
|
import { UpdatePasswordUseCase } from '../../domain/usecases/update-password.usecase';
|
||||||
import { LoggingMessager } from '../../adapters/secondaries/logging.messager';
|
import { Messager } from '../../adapters/secondaries/messager';
|
||||||
|
|
||||||
const updatePasswordRequest: UpdatePasswordRequest =
|
const updatePasswordRequest: UpdatePasswordRequest =
|
||||||
new UpdatePasswordRequest();
|
new UpdatePasswordRequest();
|
||||||
|
@ -46,7 +46,7 @@ describe('UpdatePasswordUseCase', () => {
|
||||||
useValue: mockAuthenticationRepository,
|
useValue: mockAuthenticationRepository,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
provide: LoggingMessager,
|
provide: Messager,
|
||||||
useValue: mockMessager,
|
useValue: mockMessager,
|
||||||
},
|
},
|
||||||
UpdatePasswordUseCase,
|
UpdatePasswordUseCase,
|
||||||
|
|
|
@ -10,7 +10,7 @@ import { UpdateUsernameUseCase } from '../../domain/usecases/update-username.use
|
||||||
import { CommandBus } from '@nestjs/cqrs';
|
import { CommandBus } from '@nestjs/cqrs';
|
||||||
import { UsernameProfile } from '../../mappers/username.profile';
|
import { UsernameProfile } from '../../mappers/username.profile';
|
||||||
import { BadRequestException } from '@nestjs/common';
|
import { BadRequestException } from '@nestjs/common';
|
||||||
import { LoggingMessager } from '../../adapters/secondaries/logging.messager';
|
import { Messager } from '../../adapters/secondaries/messager';
|
||||||
|
|
||||||
const existingUsername = {
|
const existingUsername = {
|
||||||
uuid: 'bb281075-1b98-4456-89d6-c643d3044a91',
|
uuid: 'bb281075-1b98-4456-89d6-c643d3044a91',
|
||||||
|
@ -100,7 +100,7 @@ describe('UpdateUsernameUseCase', () => {
|
||||||
useValue: mockAddUsernameCommand,
|
useValue: mockAddUsernameCommand,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
provide: LoggingMessager,
|
provide: Messager,
|
||||||
useValue: mockMessager,
|
useValue: mockMessager,
|
||||||
},
|
},
|
||||||
UpdateUsernameUseCase,
|
UpdateUsernameUseCase,
|
||||||
|
|
Loading…
Reference in New Issue