Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
danieldietzler committed Mar 17, 2024
1 parent 7dff742 commit 1bfd568
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
20 changes: 20 additions & 0 deletions server/src/domain/library/library.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 }]);
Expand Down

0 comments on commit 1bfd568

Please sign in to comment.