mirror of
https://github.com/immich-app/immich.git
synced 2026-03-23 23:09:45 +03:00
* refactor: library scanning fix tests remove offline files step cleanup library service improve tests cleanup tests add db migration fix e2e cleanup openapi fix tests fix tests update docs update docs update mobile code fix formatting don't remove assets from library with invalid import path use trash for offline files add migration simplify scan endpoint cleanup library panel fix library tests e2e lint fix e2e trash e2e fix lint add asset trash tests add more tests ensure thumbs are generated cleanup svelte cleanup queue names fix tests fix lint add warning due to trash fix trash tests fix lint fix tests Admin message for offline asset fix comments Update web/src/lib/components/asset-viewer/asset-viewer-nav-bar.svelte Co-authored-by: Daniel Dietzler <36593685+danieldietzler@users.noreply.github.com> add permission to library scan endpoint revert asset interface sort add trash reason to shared link stub improve path view in offline update docs improve trash performance fix comments remove stray comment * refactor: add back isOffline and remove trashReason from asset, change sync job flow * chore(server): drop coverage to 80% for functions * chore: rebase and generated files --------- Co-authored-by: Zack Pollard <zackpollard@ymail.com>
114 lines
4.6 KiB
TypeScript
114 lines
4.6 KiB
TypeScript
import { BadRequestException } from '@nestjs/common';
|
|
import { IEventRepository } from 'src/interfaces/event.interface';
|
|
import { IJobRepository, JobName, JobStatus } from 'src/interfaces/job.interface';
|
|
import { ILoggerRepository } from 'src/interfaces/logger.interface';
|
|
import { ITrashRepository } from 'src/interfaces/trash.interface';
|
|
import { TrashService } from 'src/services/trash.service';
|
|
import { authStub } from 'test/fixtures/auth.stub';
|
|
import { IAccessRepositoryMock, newAccessRepositoryMock } from 'test/repositories/access.repository.mock';
|
|
import { newEventRepositoryMock } from 'test/repositories/event.repository.mock';
|
|
import { newJobRepositoryMock } from 'test/repositories/job.repository.mock';
|
|
import { newLoggerRepositoryMock } from 'test/repositories/logger.repository.mock';
|
|
import { newTrashRepositoryMock } from 'test/repositories/trash.repository.mock';
|
|
import { Mocked } from 'vitest';
|
|
|
|
describe(TrashService.name, () => {
|
|
let sut: TrashService;
|
|
let accessMock: IAccessRepositoryMock;
|
|
let eventMock: Mocked<IEventRepository>;
|
|
let jobMock: Mocked<IJobRepository>;
|
|
let trashMock: Mocked<ITrashRepository>;
|
|
let loggerMock: Mocked<ILoggerRepository>;
|
|
|
|
it('should work', () => {
|
|
expect(sut).toBeDefined();
|
|
});
|
|
|
|
beforeEach(() => {
|
|
accessMock = newAccessRepositoryMock();
|
|
eventMock = newEventRepositoryMock();
|
|
jobMock = newJobRepositoryMock();
|
|
trashMock = newTrashRepositoryMock();
|
|
loggerMock = newLoggerRepositoryMock();
|
|
|
|
sut = new TrashService(accessMock, eventMock, jobMock, trashMock, loggerMock);
|
|
});
|
|
|
|
describe('restoreAssets', () => {
|
|
it('should require asset restore access for all ids', async () => {
|
|
await expect(
|
|
sut.restoreAssets(authStub.user1, {
|
|
ids: ['asset-1'],
|
|
}),
|
|
).rejects.toBeInstanceOf(BadRequestException);
|
|
});
|
|
|
|
it('should handle an empty list', async () => {
|
|
await expect(sut.restoreAssets(authStub.user1, { ids: [] })).resolves.toEqual({ count: 0 });
|
|
expect(accessMock.asset.checkOwnerAccess).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('should restore a batch of assets', async () => {
|
|
accessMock.asset.checkOwnerAccess.mockResolvedValue(new Set(['asset1', 'asset2']));
|
|
|
|
await sut.restoreAssets(authStub.user1, { ids: ['asset1', 'asset2'] });
|
|
|
|
expect(trashMock.restoreAll).toHaveBeenCalledWith(['asset1', 'asset2']);
|
|
expect(jobMock.queue.mock.calls).toEqual([]);
|
|
});
|
|
});
|
|
|
|
describe('restore', () => {
|
|
it('should handle an empty trash', async () => {
|
|
trashMock.getDeletedIds.mockResolvedValue({ items: [], hasNextPage: false });
|
|
trashMock.restore.mockResolvedValue(0);
|
|
await expect(sut.restore(authStub.user1)).resolves.toEqual({ count: 0 });
|
|
expect(trashMock.restore).toHaveBeenCalledWith('user-id');
|
|
});
|
|
|
|
it('should restore', async () => {
|
|
trashMock.getDeletedIds.mockResolvedValue({ items: ['asset-1'], hasNextPage: false });
|
|
trashMock.restore.mockResolvedValue(1);
|
|
await expect(sut.restore(authStub.user1)).resolves.toEqual({ count: 1 });
|
|
expect(trashMock.restore).toHaveBeenCalledWith('user-id');
|
|
});
|
|
});
|
|
|
|
describe('empty', () => {
|
|
it('should handle an empty trash', async () => {
|
|
trashMock.getDeletedIds.mockResolvedValue({ items: [], hasNextPage: false });
|
|
trashMock.empty.mockResolvedValue(0);
|
|
await expect(sut.empty(authStub.user1)).resolves.toEqual({ count: 0 });
|
|
expect(jobMock.queue).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it('should empty the trash', async () => {
|
|
trashMock.getDeletedIds.mockResolvedValue({ items: ['asset-1'], hasNextPage: false });
|
|
trashMock.empty.mockResolvedValue(1);
|
|
await expect(sut.empty(authStub.user1)).resolves.toEqual({ count: 1 });
|
|
expect(trashMock.empty).toHaveBeenCalledWith('user-id');
|
|
expect(jobMock.queue).toHaveBeenCalledWith({ name: JobName.QUEUE_TRASH_EMPTY, data: {} });
|
|
});
|
|
});
|
|
|
|
describe('onAssetsDelete', () => {
|
|
it('should queue the empty trash job', async () => {
|
|
await expect(sut.onAssetsDelete()).resolves.toBeUndefined();
|
|
expect(jobMock.queue).toHaveBeenCalledWith({ name: JobName.QUEUE_TRASH_EMPTY, data: {} });
|
|
});
|
|
});
|
|
|
|
describe('handleQueueEmptyTrash', () => {
|
|
it('should queue asset delete jobs', async () => {
|
|
trashMock.getDeletedIds.mockResolvedValue({ items: ['asset-1'], hasNextPage: false });
|
|
await expect(sut.handleQueueEmptyTrash()).resolves.toEqual(JobStatus.SUCCESS);
|
|
expect(jobMock.queueAll).toHaveBeenCalledWith([
|
|
{
|
|
name: JobName.ASSET_DELETION,
|
|
data: { id: 'asset-1', deleteOnDisk: true },
|
|
},
|
|
]);
|
|
});
|
|
});
|
|
});
|