51 lines
1.6 KiB
TypeScript
51 lines
1.6 KiB
TypeScript
import { Test, TestingModule } from '@nestjs/testing';
|
|
import { RedisConfigurationRepository } from '../../adapters/secondaries/redis-configuration.repository';
|
|
import { SetConfigurationCommand } from '../../commands/set-configuration.command';
|
|
import { SetConfigurationRequest } from '../../domain/dtos/set-configuration.request';
|
|
import { SetConfigurationUseCase } from '../../domain/usecases/set-configuration.usecase';
|
|
|
|
const mockRedisConfigurationRepository = {
|
|
set: jest.fn().mockResolvedValue(undefined),
|
|
};
|
|
|
|
describe('SetConfigurationUseCase', () => {
|
|
let setConfigurationUseCase: SetConfigurationUseCase;
|
|
|
|
beforeAll(async () => {
|
|
const module: TestingModule = await Test.createTestingModule({
|
|
providers: [
|
|
{
|
|
provide: RedisConfigurationRepository,
|
|
useValue: mockRedisConfigurationRepository,
|
|
},
|
|
|
|
SetConfigurationUseCase,
|
|
],
|
|
}).compile();
|
|
|
|
setConfigurationUseCase = module.get<SetConfigurationUseCase>(
|
|
SetConfigurationUseCase,
|
|
);
|
|
});
|
|
|
|
it('should be defined', () => {
|
|
expect(setConfigurationUseCase).toBeDefined();
|
|
});
|
|
|
|
describe('execute', () => {
|
|
it('should set a value for a key', async () => {
|
|
jest.spyOn(mockRedisConfigurationRepository, 'set');
|
|
const setConfigurationRequest: SetConfigurationRequest = {
|
|
domain: 'my-domain',
|
|
key: 'my-key',
|
|
value: 'my-value',
|
|
};
|
|
await setConfigurationUseCase.execute(
|
|
new SetConfigurationCommand(setConfigurationRequest),
|
|
);
|
|
|
|
expect(mockRedisConfigurationRepository.set).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|
|
});
|