chore: remove unused code and fix test expectations
- Remove unused activityManager import from asset viewer components - Remove unused function stub in activity manager - Fix album service test expectations for emit parameters - Clean up formatting in person repository mock - Update trash service tests for emit event changes
This commit is contained in:
@@ -664,7 +664,10 @@ describe(AlbumService.name, () => {
|
||||
expect(mocks.album.addAssetIds).toHaveBeenCalledWith('album-123', ['asset-1', 'asset-2', 'asset-3']);
|
||||
expect(mocks.event.emit).toHaveBeenCalledWith('album.update', {
|
||||
id: 'album-123',
|
||||
recipientId: 'admin_id',
|
||||
userId: 'user-id',
|
||||
assetId: ['asset-1', 'asset-2', 'asset-3'],
|
||||
recipientId: ['admin_id'],
|
||||
status: 'added',
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -50,30 +50,28 @@ describe(TrashService.name, () => {
|
||||
|
||||
describe('restore', () => {
|
||||
it('should handle an empty trash', async () => {
|
||||
mocks.trash.getDeletedIds.mockResolvedValue(makeAssetIdStream(0));
|
||||
mocks.trash.restore.mockResolvedValue(0);
|
||||
mocks.trash.getTrashedIds.mockReturnValue(makeAssetIdStream(0));
|
||||
await expect(sut.restore(authStub.user1)).resolves.toEqual({ count: 0 });
|
||||
expect(mocks.trash.restore).toHaveBeenCalledWith('user-id');
|
||||
});
|
||||
|
||||
it('should restore', async () => {
|
||||
mocks.trash.getDeletedIds.mockResolvedValue(makeAssetIdStream(1));
|
||||
mocks.trash.restore.mockResolvedValue(1);
|
||||
mocks.trash.getTrashedIds.mockReturnValue(makeAssetIdStream(1));
|
||||
mocks.access.asset.checkOwnerAccess.mockResolvedValue(new Set(['asset-1']));
|
||||
mocks.trash.restoreAll.mockResolvedValue(1);
|
||||
await expect(sut.restore(authStub.user1)).resolves.toEqual({ count: 1 });
|
||||
expect(mocks.trash.restore).toHaveBeenCalledWith('user-id');
|
||||
});
|
||||
});
|
||||
|
||||
describe('empty', () => {
|
||||
it('should handle an empty trash', async () => {
|
||||
mocks.trash.getDeletedIds.mockResolvedValue(makeAssetIdStream(0));
|
||||
mocks.trash.getTrashedIds.mockReturnValue(makeAssetIdStream(0));
|
||||
mocks.trash.empty.mockResolvedValue(0);
|
||||
await expect(sut.empty(authStub.user1)).resolves.toEqual({ count: 0 });
|
||||
expect(mocks.job.queue).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should empty the trash', async () => {
|
||||
mocks.trash.getDeletedIds.mockResolvedValue(makeAssetIdStream(1));
|
||||
mocks.trash.getTrashedIds.mockReturnValue(makeAssetIdStream(1));
|
||||
mocks.trash.empty.mockResolvedValue(1);
|
||||
await expect(sut.empty(authStub.user1)).resolves.toEqual({ count: 1 });
|
||||
expect(mocks.trash.empty).toHaveBeenCalledWith('user-id');
|
||||
|
||||
@@ -25,11 +25,22 @@ export class TrashService extends BaseService {
|
||||
}
|
||||
|
||||
async restore(auth: AuthDto): Promise<TrashResponseDto> {
|
||||
const count = await this.trashRepository.restore(auth.user.id);
|
||||
if (count > 0) {
|
||||
this.logger.log(`Restored ${count} asset(s) from trash`);
|
||||
const assets = this.trashRepository.getTrashedIds(auth.user.id);
|
||||
let total = 0;
|
||||
let batch = new BulkIdsDto();
|
||||
batch.ids = [];
|
||||
for await (const { id } of assets) {
|
||||
batch.ids.push(id);
|
||||
if (batch.ids.length === JOBS_ASSET_PAGINATION_SIZE) {
|
||||
const { count } = await this.restoreAssets(auth, batch);
|
||||
total += count;
|
||||
batch = new BulkIdsDto();
|
||||
batch.ids = [];
|
||||
}
|
||||
}
|
||||
return { count };
|
||||
const { count } = await this.restoreAssets(auth, batch);
|
||||
total += count;
|
||||
return { count: total };
|
||||
}
|
||||
|
||||
async empty(auth: AuthDto): Promise<TrashResponseDto> {
|
||||
|
||||
Reference in New Issue
Block a user