map for delete

This commit is contained in:
Gsk54 2023-01-26 16:15:45 +01:00
parent 8cd53a0736
commit 05ea965ce4
3 changed files with 16 additions and 2 deletions

View File

@ -1,4 +1,7 @@
import { Mapper } from '@automapper/core';
import { InjectMapper } from '@automapper/nestjs';
import { CommandHandler } from '@nestjs/cqrs';
import { ConfigurationMessagerPresenter } from '../../adapters/secondaries/configuration-messager.presenter';
import { ConfigurationMessager } from '../../adapters/secondaries/configuration.messager';
import { ConfigurationRepository } from '../../adapters/secondaries/configuration.repository';
import { LoggingMessager } from '../../adapters/secondaries/logging.messager';
@ -11,6 +14,7 @@ export class DeleteConfigurationUseCase {
private readonly _repository: ConfigurationRepository,
private readonly _configurationMessager: ConfigurationMessager,
private readonly _loggingMessager: LoggingMessager,
@InjectMapper() private readonly _mapper: Mapper,
) {}
async execute(command: DeleteConfigurationCommand): Promise<Configuration> {
@ -18,7 +22,13 @@ export class DeleteConfigurationUseCase {
const configuration = await this._repository.delete(command.uuid);
this._configurationMessager.publish(
'delete',
JSON.stringify({ uuid: configuration.uuid }),
JSON.stringify(
this._mapper.map(
configuration,
Configuration,
ConfigurationMessagerPresenter,
),
),
);
this._loggingMessager.publish(
'configuration.delete.info',

View File

@ -1,3 +1,5 @@
import { classes } from '@automapper/classes';
import { AutomapperModule } from '@automapper/nestjs';
import { Test, TestingModule } from '@nestjs/testing';
import { ConfigurationMessager } from '../../adapters/secondaries/configuration.messager';
import { ConfigurationRepository } from '../../adapters/secondaries/configuration.repository';
@ -5,6 +7,7 @@ import { LoggingMessager } from '../../adapters/secondaries/logging.messager';
import { DeleteConfigurationCommand } from '../../commands/delete-configuration.command';
import { Domain } from '../../domain/dtos/domain.enum';
import { DeleteConfigurationUseCase } from '../../domain/usecases/delete-configuration.usecase';
import { ConfigurationProfile } from '../../mappers/configuration.profile';
const mockConfigurations = [
{
@ -54,12 +57,14 @@ describe('DeleteConfigurationUseCase', () => {
beforeAll(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [AutomapperModule.forRoot({ strategyInitializer: classes() })],
providers: [
{
provide: ConfigurationRepository,
useValue: mockConfigurationRepository,
},
DeleteConfigurationUseCase,
ConfigurationProfile,
{
provide: ConfigurationMessager,
useValue: mockMessager,

View File

@ -48,7 +48,6 @@ describe('UpdateConfigurationUseCase', () => {
beforeAll(async () => {
const module: TestingModule = await Test.createTestingModule({
imports: [AutomapperModule.forRoot({ strategyInitializer: classes() })],
providers: [
{
provide: ConfigurationRepository,