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 { IsEnum, IsNotEmpty, IsOptional, IsString } from 'class-validator';
import { Domain } from './domain.enum';
import { IsNotEmpty, IsOptional, IsString } from 'class-validator';
export class UpdateConfigurationRequest {
@IsString()
@ -8,18 +7,8 @@ export class UpdateConfigurationRequest {
@AutoMap()
uuid: string;
@IsEnum(Domain)
@IsOptional()
@AutoMap()
domain?: Domain;
@IsString()
@IsOptional()
@AutoMap()
key?: string;
@IsString()
@IsOptional()
@AutoMap()
value?: string;
value: string;
}

View File

@ -137,7 +137,7 @@ describe('ConfigurationRepository', () => {
});
describe('update', () => {
it('should update configuration key', async () => {
it('should update configuration value', async () => {
const configurationToUpdate = await prismaService.configuration.create({
data: {
domain: Domain.USER,
@ -147,14 +147,14 @@ describe('ConfigurationRepository', () => {
});
const toUpdate: Configuration = new Configuration();
toUpdate.key = 'key2';
toUpdate.value = 'value2';
const updatedConfiguration = await configurationRepository.update(
configurationToUpdate.uuid,
toUpdate,
);
expect(updatedConfiguration.uuid).toBe(configurationToUpdate.uuid);
expect(updatedConfiguration.key).toBe('key2');
expect(updatedConfiguration.value).toBe('value2');
});
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 { LoggingMessager } from '../../adapters/secondaries/logging.messager';
import { UpdateConfigurationCommand } from '../../commands/update-configuration.command';
import { Domain } from '../../domain/dtos/domain.enum';
import { UpdateConfigurationRequest } from '../../domain/dtos/update-configuration.request';
import { Configuration } from '../../domain/entities/configuration';
import { UpdateConfigurationUseCase } from '../../domain/usecases/update-configuration.usecase';
@ -12,11 +13,13 @@ import { ConfigurationProfile } from '../../mappers/configuration.profile';
const originalConfiguration: Configuration = new Configuration();
originalConfiguration.uuid = 'bb281075-1b98-4456-89d6-c643d3044a91';
originalConfiguration.domain = Domain.USER;
originalConfiguration.key = 'key1';
originalConfiguration.value = 'value1';
const updateConfigurationRequest: UpdateConfigurationRequest = {
uuid: 'bb281075-1b98-4456-89d6-c643d3044a91',
key: 'Dane',
value: 'value2',
};
const updateConfigurationCommand: UpdateConfigurationCommand =
@ -26,7 +29,7 @@ const mockConfigurationRepository = {
update: jest
.fn()
.mockImplementationOnce((uuid: string, params: any) => {
originalConfiguration.key = params.key;
originalConfiguration.value = params.value;
return Promise.resolve(originalConfiguration);
})
@ -74,11 +77,11 @@ describe('UpdateConfigurationUseCase', () => {
});
describe('execute', () => {
it('should update a configuration', async () => {
it('should update a configuration value', async () => {
const updatedConfiguration: Configuration =
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 () => {
await expect(