forked from Cutlery/immich
improve tests
This commit is contained in:
parent
247429c3e4
commit
0803458d40
@ -242,27 +242,6 @@ describe(LibraryService.name, () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should set missing assets offline', async () => {
|
|
||||||
const mockLibraryJob: ILibraryRefreshJob = {
|
|
||||||
id: libraryStub.externalLibrary1.id,
|
|
||||||
refreshModifiedFiles: false,
|
|
||||||
refreshAllFiles: false,
|
|
||||||
};
|
|
||||||
|
|
||||||
libraryMock.get.mockResolvedValue(libraryStub.externalLibrary1);
|
|
||||||
storageMock.crawl.mockResolvedValue([]);
|
|
||||||
assetMock.getLibraryAssetPaths.mockResolvedValue({
|
|
||||||
items: [assetStub.image],
|
|
||||||
hasNextPage: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
await sut.handleQueueAssetRefresh(mockLibraryJob);
|
|
||||||
|
|
||||||
expect(assetMock.updateAll).toHaveBeenCalledWith([assetStub.image.id], { isOffline: true });
|
|
||||||
expect(assetMock.updateAll).not.toHaveBeenCalledWith(expect.anything(), { isOffline: false });
|
|
||||||
expect(jobMock.queueAll).not.toHaveBeenCalled();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should set crawled assets that were previously offline back online', async () => {
|
it('should set crawled assets that were previously offline back online', async () => {
|
||||||
const mockLibraryJob: ILibraryRefreshJob = {
|
const mockLibraryJob: ILibraryRefreshJob = {
|
||||||
id: libraryStub.externalLibrary1.id,
|
id: libraryStub.externalLibrary1.id,
|
||||||
@ -1445,6 +1424,45 @@ describe(LibraryService.name, () => {
|
|||||||
],
|
],
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should queue an offline file scan', async () => {
|
||||||
|
libraryMock.get.mockResolvedValue(libraryStub.externalLibrary1);
|
||||||
|
|
||||||
|
await sut.queueScan(authStub.admin, libraryStub.externalLibrary1.id, { checkForOffline: true });
|
||||||
|
|
||||||
|
expect(jobMock.queue.mock.calls).toEqual([
|
||||||
|
[
|
||||||
|
{
|
||||||
|
name: JobName.LIBRARY_SCAN_OFFLINE,
|
||||||
|
data: {
|
||||||
|
id: libraryStub.externalLibrary1.id,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should error when queuing a scan with checkOffline and refreshAll', async () => {
|
||||||
|
libraryMock.get.mockResolvedValue(libraryStub.externalLibrary1);
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
sut.queueScan(authStub.admin, libraryStub.externalLibrary1.id, {
|
||||||
|
refreshAllFiles: true,
|
||||||
|
checkForOffline: true,
|
||||||
|
}),
|
||||||
|
).rejects.toBeInstanceOf(BadRequestException);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should error when queuing a scan with checkOffline and refreshModified', async () => {
|
||||||
|
libraryMock.get.mockResolvedValue(libraryStub.externalLibrary1);
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
sut.queueScan(authStub.admin, libraryStub.externalLibrary1.id, {
|
||||||
|
refreshModifiedFiles: true,
|
||||||
|
checkForOffline: true,
|
||||||
|
}),
|
||||||
|
).rejects.toBeInstanceOf(BadRequestException);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('queueEmptyTrash', () => {
|
describe('queueEmptyTrash', () => {
|
||||||
|
@ -656,14 +656,6 @@ export class LibraryService extends EventEmitter {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if a given path is in a user's external path. Both arguments are assumed to be normalized
|
|
||||||
private isInExternalPath(filePath: string, externalPath: string | null): boolean {
|
|
||||||
if (externalPath === null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return filePath.startsWith(externalPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
async handleQueueAssetRefresh(job: ILibraryRefreshJob): Promise<boolean> {
|
async handleQueueAssetRefresh(job: ILibraryRefreshJob): Promise<boolean> {
|
||||||
const library = await this.repository.get(job.id);
|
const library = await this.repository.get(job.id);
|
||||||
if (!library || library.type !== LibraryType.EXTERNAL) {
|
if (!library || library.type !== LibraryType.EXTERNAL) {
|
||||||
|
@ -146,26 +146,6 @@ export class LibraryRepository implements ILibraryRepository {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@GenerateSql({ params: [DummyValue.UUID] })
|
|
||||||
async getOnlineAssetPaths(libraryId: string): Promise<string[]> {
|
|
||||||
// Return all non-offline asset paths for a given library
|
|
||||||
const rawResults = await this.repository
|
|
||||||
.createQueryBuilder('library')
|
|
||||||
.innerJoinAndSelect('library.assets', 'assets')
|
|
||||||
.where('library.id = :id', { id: libraryId })
|
|
||||||
.andWhere('assets.isOffline = false')
|
|
||||||
.select('assets.originalPath')
|
|
||||||
.getRawMany();
|
|
||||||
|
|
||||||
const results: string[] = [];
|
|
||||||
|
|
||||||
for (const rawPath of rawResults) {
|
|
||||||
results.push(rawPath.assets_originalPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
return results;
|
|
||||||
}
|
|
||||||
|
|
||||||
@GenerateSql({ params: [DummyValue.UUID] })
|
@GenerateSql({ params: [DummyValue.UUID] })
|
||||||
async getAssetIds(libraryId: string, withDeleted = false): Promise<string[]> {
|
async getAssetIds(libraryId: string, withDeleted = false): Promise<string[]> {
|
||||||
let query = this.repository
|
let query = this.repository
|
||||||
|
Loading…
x
Reference in New Issue
Block a user