From 6f37ab6a9ebae4da191b853109f89df2317d1118 Mon Sep 17 00:00:00 2001 From: Alex Date: Tue, 3 Sep 2024 16:04:35 -0500 Subject: [PATCH] fix(server): empty trash for archived assets (#12281) * fix(server): empty trash for archived assets * use withArchived * add e2e test --- e2e/src/api/specs/trash.e2e-spec.ts | 17 +++++++++++++++++ e2e/src/utils.ts | 4 ++++ server/src/services/trash.service.ts | 1 + 3 files changed, 22 insertions(+) diff --git a/e2e/src/api/specs/trash.e2e-spec.ts b/e2e/src/api/specs/trash.e2e-spec.ts index 3049ff1511..0c28a72825 100644 --- a/e2e/src/api/specs/trash.e2e-spec.ts +++ b/e2e/src/api/specs/trash.e2e-spec.ts @@ -42,6 +42,23 @@ describe('/trash', () => { const after = await getAssetStatistics({ isTrashed: true }, { headers: asBearerAuth(admin.accessToken) }); expect(after.total).toBe(0); }); + + it('should empty the trash with archived assets', async () => { + const { id: assetId } = await utils.createAsset(admin.accessToken); + await utils.archiveAssets(admin.accessToken, [assetId]); + await utils.deleteAssets(admin.accessToken, [assetId]); + + const before = await getAssetInfo({ id: assetId }, { headers: asBearerAuth(admin.accessToken) }); + expect(before).toStrictEqual(expect.objectContaining({ id: assetId, isTrashed: true, isArchived: true })); + + const { status } = await request(app).post('/trash/empty').set('Authorization', `Bearer ${admin.accessToken}`); + expect(status).toBe(204); + + await utils.waitForWebsocketEvent({ event: 'assetDelete', id: assetId }); + + const after = await getAssetStatistics({ isTrashed: true }, { headers: asBearerAuth(admin.accessToken) }); + expect(after.total).toBe(0); + }); }); describe('POST /trash/restore', () => { diff --git a/e2e/src/utils.ts b/e2e/src/utils.ts index e2f05d5261..c67e569697 100644 --- a/e2e/src/utils.ts +++ b/e2e/src/utils.ts @@ -30,6 +30,7 @@ import { signUpAdmin, updateAdminOnboarding, updateAlbumUser, + updateAssets, updateConfig, validate, } from '@immich/sdk'; @@ -389,6 +390,9 @@ export const utils = { return searchMetadata({ metadataSearchDto: dto }, { headers: asBearerAuth(accessToken) }); }, + archiveAssets: (accessToken: string, ids: string[]) => + updateAssets({ assetBulkUpdateDto: { ids, isArchived: true } }, { headers: asBearerAuth(accessToken) }), + deleteAssets: (accessToken: string, ids: string[]) => deleteAssets({ assetBulkDeleteDto: { ids } }, { headers: asBearerAuth(accessToken) }), diff --git a/server/src/services/trash.service.ts b/server/src/services/trash.service.ts index 8376ba9221..ac141521dd 100644 --- a/server/src/services/trash.service.ts +++ b/server/src/services/trash.service.ts @@ -41,6 +41,7 @@ export class TrashService { const assetPagination = usePagination(JOBS_ASSET_PAGINATION_SIZE, (pagination) => this.assetRepository.getByUserId(pagination, auth.user.id, { trashedBefore: DateTime.now().toJSDate(), + withArchived: true, }), );