mirror of
https://github.com/Art051/immich.git
synced 2025-08-11 19:29:00 +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:
@@ -12,7 +12,7 @@ import {
|
||||
StorageTemplateService,
|
||||
defaults,
|
||||
} from '@app/domain';
|
||||
import { AssetPathType, SystemConfigKey } from '@app/infra/entities';
|
||||
import { AssetPathType, SystemConfig, SystemConfigKey } from '@app/infra/entities';
|
||||
import {
|
||||
assetStub,
|
||||
newAlbumRepositoryMock,
|
||||
@@ -74,6 +74,35 @@ describe(StorageTemplateService.name, () => {
|
||||
SystemConfigCore.create(configMock).config$.next(defaults);
|
||||
});
|
||||
|
||||
describe('validate', () => {
|
||||
it('should allow valid templates', () => {
|
||||
expect(() =>
|
||||
sut.validate({
|
||||
newConfig: {
|
||||
storageTemplate: {
|
||||
template:
|
||||
'{{y}}{{M}}{{W}}{{d}}{{h}}{{m}}{{s}}{{filename}}{{ext}}{{filetype}}{{filetypefull}}{{assetId}}{{album}}',
|
||||
},
|
||||
} as SystemConfig,
|
||||
oldConfig: {} as SystemConfig,
|
||||
}),
|
||||
).not.toThrow();
|
||||
});
|
||||
|
||||
it('should fail for an invalid template', () => {
|
||||
expect(() =>
|
||||
sut.validate({
|
||||
newConfig: {
|
||||
storageTemplate: {
|
||||
template: '{{foo}}',
|
||||
},
|
||||
} as SystemConfig,
|
||||
oldConfig: {} as SystemConfig,
|
||||
}),
|
||||
).toThrow(/Invalid storage template.*/);
|
||||
});
|
||||
});
|
||||
|
||||
describe('handleMigrationSingle', () => {
|
||||
it('should skip when storage template is disabled', async () => {
|
||||
configMock.load.mockResolvedValue([{ key: SystemConfigKey.STORAGE_TEMPLATE_ENABLED, value: false }]);
|
||||
|
||||
Reference in New Issue
Block a user