chore(server): eslint await-thenable (#7545)

* await-thenable

* fix library watchers

* moar eslint

* fix test

* fix typo

* try to remove check void return

* fix checksVoidReturn

* move to domain utils

* remove eslint ignores

* chore: cleanup types

* chore: use logger

* fix: e2e

---------

Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
Co-authored-by: Jason Rasmussen <jrasm91@gmail.com>
This commit is contained in:
Jonathan Jogenfors 2024-03-05 23:23:06 +01:00 committed by GitHub
parent 972d5a3411
commit 5d377e5b0f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
40 changed files with 133 additions and 110 deletions

View file

@ -17,6 +17,7 @@ import {
systemConfigStub,
userStub,
} from '@test';
import { when } from 'jest-when';
import { Stats } from 'node:fs';
import { ILibraryFileJob, ILibraryRefreshJob, JobName } from '../job';
import {
@ -55,7 +56,7 @@ describe(LibraryService.name, () => {
storageMock = newStorageRepositoryMock();
// Always validate owner access for library.
accessMock.library.checkOwnerAccess.mockImplementation(async (_, libraryIds) => libraryIds);
accessMock.library.checkOwnerAccess.mockImplementation((_, libraryIds) => Promise.resolve(libraryIds));
sut = new LibraryService(
accessMock,
@ -106,19 +107,13 @@ describe(LibraryService.name, () => {
configMock.load.mockResolvedValue(systemConfigStub.libraryWatchEnabled);
libraryMock.get.mockResolvedValue(libraryStub.externalLibrary1);
libraryMock.get.mockImplementation(async (id) => {
switch (id) {
case libraryStub.externalLibraryWithImportPaths1.id: {
return libraryStub.externalLibraryWithImportPaths1;
}
case libraryStub.externalLibraryWithImportPaths2.id: {
return libraryStub.externalLibraryWithImportPaths2;
}
default: {
return null;
}
}
});
when(libraryMock.get)
.calledWith(libraryStub.externalLibraryWithImportPaths1.id)
.mockResolvedValue(libraryStub.externalLibraryWithImportPaths1);
when(libraryMock.get)
.calledWith(libraryStub.externalLibraryWithImportPaths2.id)
.mockResolvedValue(libraryStub.externalLibraryWithImportPaths2);
await sut.init();
@ -1278,19 +1273,13 @@ describe(LibraryService.name, () => {
configMock.load.mockResolvedValue(systemConfigStub.libraryWatchEnabled);
libraryMock.get.mockResolvedValue(libraryStub.externalLibrary1);
libraryMock.get.mockImplementation(async (id) => {
switch (id) {
case libraryStub.externalLibraryWithImportPaths1.id: {
return libraryStub.externalLibraryWithImportPaths1;
}
case libraryStub.externalLibraryWithImportPaths2.id: {
return libraryStub.externalLibraryWithImportPaths2;
}
default: {
return null;
}
}
});
when(libraryMock.get)
.calledWith(libraryStub.externalLibraryWithImportPaths1.id)
.mockResolvedValue(libraryStub.externalLibraryWithImportPaths1);
when(libraryMock.get)
.calledWith(libraryStub.externalLibraryWithImportPaths2.id)
.mockResolvedValue(libraryStub.externalLibraryWithImportPaths2);
const mockClose = jest.fn();
storageMock.watch.mockImplementation(makeMockWatcher({ close: mockClose }));
@ -1304,9 +1293,8 @@ describe(LibraryService.name, () => {
describe('handleDeleteLibrary', () => {
it('should not delete a nonexistent library', async () => {
libraryMock.get.mockImplementation(async () => {
return null;
});
libraryMock.get.mockResolvedValue(null);
libraryMock.getAssetIds.mockResolvedValue([]);
libraryMock.delete.mockImplementation(async () => {});