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:
Daniel Dietzler 2024-03-17 20:16:02 +01:00 committed by GitHub
parent 14da671bf9
commit 148428a564
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
14 changed files with 170 additions and 81 deletions

View file

@ -148,6 +148,26 @@ describe(LibraryService.name, () => {
});
});
describe('validateConfig', () => {
it('should allow a valid cron expression', () => {
expect(() =>
sut.validateConfig({
newConfig: { library: { scan: { cronExpression: '0 0 * * *' } } } as SystemConfig,
oldConfig: {} as SystemConfig,
}),
).not.toThrow(expect.stringContaining('Invalid cron expression'));
});
it('should fail for an invalid cron expression', () => {
expect(() =>
sut.validateConfig({
newConfig: { library: { scan: { cronExpression: 'foo' } } } as SystemConfig,
oldConfig: {} as SystemConfig,
}),
).toThrow(/Invalid cron expression.*/);
});
});
describe('handleQueueAssetRefresh', () => {
it('should queue new assets', async () => {
const mockLibraryJob: ILibraryRefreshJob = {