refactor: repository mocks (#16785)

This commit is contained in:
Jason Rasmussen
2025-03-10 16:52:44 -04:00
committed by GitHub
parent 1b35400043
commit 1382b27349
59 changed files with 320 additions and 550 deletions
@@ -36,6 +36,9 @@ describe(LibraryService.name, () => {
describe('onConfigInit', () => {
it('should init cron job and handle config changes', async () => {
mocks.cron.create.mockResolvedValue();
mocks.cron.update.mockResolvedValue();
await sut.onConfigInit({ newConfig: defaults });
expect(mocks.cron.create).toHaveBeenCalled();
@@ -65,6 +68,7 @@ describe(LibraryService.name, () => {
mocks.library.get.mockImplementation((id) =>
Promise.resolve([library1, library2].find((library) => library.id === id)),
);
mocks.cron.create.mockResolvedValue();
await sut.onConfigInit({ newConfig: systemConfigStub.libraryWatchEnabled as SystemConfig });
@@ -74,6 +78,8 @@ describe(LibraryService.name, () => {
});
it('should not initialize watcher when watching is disabled', async () => {
mocks.cron.create.mockResolvedValue();
await sut.onConfigInit({ newConfig: systemConfigStub.libraryWatchDisabled as SystemConfig });
expect(mocks.storage.watch).not.toHaveBeenCalled();
@@ -99,6 +105,8 @@ describe(LibraryService.name, () => {
describe('onConfigUpdateEvent', () => {
beforeEach(async () => {
mocks.database.tryLock.mockResolvedValue(true);
mocks.cron.create.mockResolvedValue();
await sut.onConfigInit({ newConfig: defaults });
});
@@ -111,6 +119,9 @@ describe(LibraryService.name, () => {
it('should update cron job and enable watching', async () => {
mocks.library.getAll.mockResolvedValue([]);
mocks.cron.create.mockResolvedValue();
mocks.cron.update.mockResolvedValue();
await sut.onConfigUpdate({
newConfig: systemConfigStub.libraryScanAndWatch as SystemConfig,
oldConfig: defaults,
@@ -125,6 +136,9 @@ describe(LibraryService.name, () => {
it('should update cron job and disable watching', async () => {
mocks.library.getAll.mockResolvedValue([]);
mocks.cron.create.mockResolvedValue();
mocks.cron.update.mockResolvedValue();
await sut.onConfigUpdate({
newConfig: systemConfigStub.libraryScanAndWatch as SystemConfig,
oldConfig: defaults,
@@ -620,6 +634,7 @@ describe(LibraryService.name, () => {
const mockClose = vitest.fn();
mocks.storage.watch.mockImplementation(makeMockWatcher({ close: mockClose }));
mocks.cron.create.mockResolvedValue();
await sut.onConfigInit({ newConfig: systemConfigStub.libraryWatchEnabled as SystemConfig });
await sut.delete(library.id);
@@ -765,6 +780,7 @@ describe(LibraryService.name, () => {
mocks.library.create.mockResolvedValue(library);
mocks.library.get.mockResolvedValue(library);
mocks.library.getAll.mockResolvedValue([]);
mocks.cron.create.mockResolvedValue();
await sut.onConfigInit({ newConfig: systemConfigStub.libraryWatchEnabled as SystemConfig });
await sut.create({ ownerId: authStub.admin.user.id, importPaths: library.importPaths });
@@ -832,6 +848,7 @@ describe(LibraryService.name, () => {
describe('update', () => {
beforeEach(async () => {
mocks.library.getAll.mockResolvedValue([]);
mocks.cron.create.mockResolvedValue();
await sut.onConfigInit({ newConfig: systemConfigStub.libraryWatchEnabled as SystemConfig });
});
@@ -878,6 +895,8 @@ describe(LibraryService.name, () => {
describe('watching disabled', () => {
beforeEach(async () => {
mocks.cron.create.mockResolvedValue();
await sut.onConfigInit({ newConfig: systemConfigStub.libraryWatchDisabled as SystemConfig });
});
@@ -895,6 +914,8 @@ describe(LibraryService.name, () => {
describe('watching enabled', () => {
beforeEach(async () => {
mocks.library.getAll.mockResolvedValue([]);
mocks.cron.create.mockResolvedValue();
await sut.onConfigInit({ newConfig: systemConfigStub.libraryWatchEnabled as SystemConfig });
});
@@ -1067,6 +1088,7 @@ describe(LibraryService.name, () => {
const mockClose = vitest.fn();
mocks.storage.watch.mockImplementation(makeMockWatcher({ close: mockClose }));
mocks.cron.create.mockResolvedValue();
await sut.onConfigInit({ newConfig: systemConfigStub.libraryWatchEnabled as SystemConfig });
await sut.onShutdown();