mirror of
https://github.com/immich-app/immich.git
synced 2026-05-18 03:10:24 +03:00
refactor!: migrate class-validator to zod (#26597)
This commit is contained in:
@@ -311,9 +311,7 @@ describe(SystemConfigService.name, () => {
|
||||
mocks.config.getEnv.mockReturnValue(mockEnvData({ configFile: 'immich-config.json' }));
|
||||
mocks.systemMetadata.readFile.mockResolvedValue(JSON.stringify({ library: { scan: { cronExpression: 'foo' } } }));
|
||||
|
||||
await expect(sut.getSystemConfig()).rejects.toThrow(
|
||||
'library.scan.cronExpression has failed the following constraints: cronValidator',
|
||||
);
|
||||
await expect(sut.getSystemConfig()).rejects.toThrow('[library.scan.cronExpression] Invalid cron expression');
|
||||
});
|
||||
|
||||
it('should log errors with the config file', async () => {
|
||||
@@ -402,10 +400,26 @@ describe(SystemConfigService.name, () => {
|
||||
});
|
||||
|
||||
const tests = [
|
||||
{ should: 'validate numbers', config: { ffmpeg: { crf: 'not-a-number' } } },
|
||||
{ should: 'validate booleans', config: { oauth: { enabled: 'invalid' } } },
|
||||
{ should: 'validate enums', config: { ffmpeg: { transcode: 'unknown' } } },
|
||||
{ should: 'validate required oauth fields', config: { oauth: { enabled: true } } },
|
||||
{
|
||||
should: 'validate numbers',
|
||||
config: { ffmpeg: { crf: 'not-a-number' } },
|
||||
throws: '[ffmpeg.crf] Invalid input: expected number, received NaN',
|
||||
},
|
||||
{
|
||||
should: 'validate booleans',
|
||||
config: { oauth: { enabled: 'invalid' } },
|
||||
throws: '[oauth.enabled] Invalid input: expected boolean, received string',
|
||||
},
|
||||
{
|
||||
should: 'validate enums',
|
||||
config: { ffmpeg: { transcode: 'unknown' } },
|
||||
throws: '[ffmpeg.transcode] Invalid option: expected one of',
|
||||
},
|
||||
{
|
||||
should: 'validate required oauth fields',
|
||||
config: { oauth: { enabled: true } },
|
||||
check: (c: SystemConfig) => expect(c.oauth.enabled).toBe(true),
|
||||
},
|
||||
{ should: 'warn for top level unknown options', warn: true, config: { unknownOption: true } },
|
||||
{ should: 'warn for nested unknown options', warn: true, config: { ffmpeg: { unknownOption: true } } },
|
||||
];
|
||||
@@ -415,11 +429,14 @@ describe(SystemConfigService.name, () => {
|
||||
mocks.config.getEnv.mockReturnValue(mockEnvData({ configFile: 'immich-config.json' }));
|
||||
mocks.systemMetadata.readFile.mockResolvedValue(JSON.stringify(test.config));
|
||||
|
||||
if (test.warn) {
|
||||
if (test.throws) {
|
||||
await expect(sut.getSystemConfig()).rejects.toThrow(test.throws);
|
||||
} else if (test.warn) {
|
||||
await sut.getSystemConfig();
|
||||
expect(mocks.logger.warn).toHaveBeenCalled();
|
||||
} else {
|
||||
await expect(sut.getSystemConfig()).rejects.toBeInstanceOf(Error);
|
||||
const config = await sut.getSystemConfig();
|
||||
test.check!(config);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user