mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
feat(server): use nestjs events to validate config (#7986)
* use events for config validation * chore: better types * add unit tests --------- Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>
This commit is contained in:
parent
14da671bf9
commit
148428a564
14 changed files with 170 additions and 81 deletions
|
|
@ -16,7 +16,7 @@ import { BadRequestException } from '@nestjs/common';
|
|||
import { newCommunicationRepositoryMock, newSystemConfigRepositoryMock } from '@test';
|
||||
import { QueueName } from '../job';
|
||||
import { ICommunicationRepository, ISearchRepository, ISystemConfigRepository, ServerEvent } from '../repositories';
|
||||
import { defaults, SystemConfigValidator } from './system-config.core';
|
||||
import { defaults } from './system-config.core';
|
||||
import { SystemConfigService } from './system-config.service';
|
||||
|
||||
const updates: SystemConfigEntity[] = [
|
||||
|
|
@ -172,15 +172,6 @@ describe(SystemConfigService.name, () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('addValidator', () => {
|
||||
it('should call the validator on config changes', async () => {
|
||||
const validator: SystemConfigValidator = jest.fn();
|
||||
sut.addValidator(validator);
|
||||
await sut.updateConfig(defaults);
|
||||
expect(validator).toHaveBeenCalledWith(defaults, defaults);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getConfig', () => {
|
||||
let warnLog: jest.SpyInstance;
|
||||
|
||||
|
|
@ -341,17 +332,6 @@ describe(SystemConfigService.name, () => {
|
|||
expect(configMock.saveAll).toHaveBeenCalledWith(updates);
|
||||
});
|
||||
|
||||
it('should throw an error if the config is not valid', async () => {
|
||||
const validator = jest.fn().mockRejectedValue('invalid config');
|
||||
|
||||
sut.addValidator(validator);
|
||||
|
||||
await expect(sut.updateConfig(updatedConfig)).rejects.toBeInstanceOf(BadRequestException);
|
||||
|
||||
expect(validator).toHaveBeenCalledWith(updatedConfig, defaults);
|
||||
expect(configMock.saveAll).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should throw an error if a config file is in use', async () => {
|
||||
process.env.IMMICH_CONFIG_FILE = 'immich-config.json';
|
||||
configMock.readFile.mockResolvedValue(JSON.stringify({}));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue