update value only

This commit is contained in:
Gsk54 2023-01-26 15:39:51 +01:00
parent a526b1521c
commit 1b7c131d1c
3 changed files with 12 additions and 20 deletions

View File

@ -1,6 +1,5 @@
import { AutoMap } from '@automapper/classes'; import { AutoMap } from '@automapper/classes';
import { IsEnum, IsNotEmpty, IsOptional, IsString } from 'class-validator'; import { IsNotEmpty, IsOptional, IsString } from 'class-validator';
import { Domain } from './domain.enum';
export class UpdateConfigurationRequest { export class UpdateConfigurationRequest {
@IsString() @IsString()
@ -8,18 +7,8 @@ export class UpdateConfigurationRequest {
@AutoMap() @AutoMap()
uuid: string; uuid: string;
@IsEnum(Domain)
@IsOptional()
@AutoMap()
domain?: Domain;
@IsString() @IsString()
@IsOptional() @IsOptional()
@AutoMap() @AutoMap()
key?: string; value: string;
@IsString()
@IsOptional()
@AutoMap()
value?: string;
} }

View File

@ -137,7 +137,7 @@ describe('ConfigurationRepository', () => {
}); });
describe('update', () => { describe('update', () => {
it('should update configuration key', async () => { it('should update configuration value', async () => {
const configurationToUpdate = await prismaService.configuration.create({ const configurationToUpdate = await prismaService.configuration.create({
data: { data: {
domain: Domain.USER, domain: Domain.USER,
@ -147,14 +147,14 @@ describe('ConfigurationRepository', () => {
}); });
const toUpdate: Configuration = new Configuration(); const toUpdate: Configuration = new Configuration();
toUpdate.key = 'key2'; toUpdate.value = 'value2';
const updatedConfiguration = await configurationRepository.update( const updatedConfiguration = await configurationRepository.update(
configurationToUpdate.uuid, configurationToUpdate.uuid,
toUpdate, toUpdate,
); );
expect(updatedConfiguration.uuid).toBe(configurationToUpdate.uuid); expect(updatedConfiguration.uuid).toBe(configurationToUpdate.uuid);
expect(updatedConfiguration.key).toBe('key2'); expect(updatedConfiguration.value).toBe('value2');
}); });
it('should throw DatabaseException', async () => { it('should throw DatabaseException', async () => {

View File

@ -5,6 +5,7 @@ import { ConfigurationMessager } from '../../adapters/secondaries/configuration.
import { ConfigurationRepository } from '../../adapters/secondaries/configuration.repository'; import { ConfigurationRepository } from '../../adapters/secondaries/configuration.repository';
import { LoggingMessager } from '../../adapters/secondaries/logging.messager'; import { LoggingMessager } from '../../adapters/secondaries/logging.messager';
import { UpdateConfigurationCommand } from '../../commands/update-configuration.command'; import { UpdateConfigurationCommand } from '../../commands/update-configuration.command';
import { Domain } from '../../domain/dtos/domain.enum';
import { UpdateConfigurationRequest } from '../../domain/dtos/update-configuration.request'; import { UpdateConfigurationRequest } from '../../domain/dtos/update-configuration.request';
import { Configuration } from '../../domain/entities/configuration'; import { Configuration } from '../../domain/entities/configuration';
import { UpdateConfigurationUseCase } from '../../domain/usecases/update-configuration.usecase'; import { UpdateConfigurationUseCase } from '../../domain/usecases/update-configuration.usecase';
@ -12,11 +13,13 @@ import { ConfigurationProfile } from '../../mappers/configuration.profile';
const originalConfiguration: Configuration = new Configuration(); const originalConfiguration: Configuration = new Configuration();
originalConfiguration.uuid = 'bb281075-1b98-4456-89d6-c643d3044a91'; originalConfiguration.uuid = 'bb281075-1b98-4456-89d6-c643d3044a91';
originalConfiguration.domain = Domain.USER;
originalConfiguration.key = 'key1'; originalConfiguration.key = 'key1';
originalConfiguration.value = 'value1';
const updateConfigurationRequest: UpdateConfigurationRequest = { const updateConfigurationRequest: UpdateConfigurationRequest = {
uuid: 'bb281075-1b98-4456-89d6-c643d3044a91', uuid: 'bb281075-1b98-4456-89d6-c643d3044a91',
key: 'Dane', value: 'value2',
}; };
const updateConfigurationCommand: UpdateConfigurationCommand = const updateConfigurationCommand: UpdateConfigurationCommand =
@ -26,7 +29,7 @@ const mockConfigurationRepository = {
update: jest update: jest
.fn() .fn()
.mockImplementationOnce((uuid: string, params: any) => { .mockImplementationOnce((uuid: string, params: any) => {
originalConfiguration.key = params.key; originalConfiguration.value = params.value;
return Promise.resolve(originalConfiguration); return Promise.resolve(originalConfiguration);
}) })
@ -74,11 +77,11 @@ describe('UpdateConfigurationUseCase', () => {
}); });
describe('execute', () => { describe('execute', () => {
it('should update a configuration', async () => { it('should update a configuration value', async () => {
const updatedConfiguration: Configuration = const updatedConfiguration: Configuration =
await updateConfigurationUseCase.execute(updateConfigurationCommand); await updateConfigurationUseCase.execute(updateConfigurationCommand);
expect(updatedConfiguration.key).toBe(updateConfigurationRequest.key); expect(updatedConfiguration.value).toBe(updateConfigurationRequest.value);
}); });
it('should throw an error if configuration does not exist', async () => { it('should throw an error if configuration does not exist', async () => {
await expect( await expect(