diff --git a/e2e/src/api/specs/album.e2e-spec.ts b/e2e/src/api/specs/album.e2e-spec.ts index f7d05aac50..ec5238f376 100644 --- a/e2e/src/api/specs/album.e2e-spec.ts +++ b/e2e/src/api/specs/album.e2e-spec.ts @@ -434,6 +434,20 @@ describe('/album', () => { expect(status).toBe(400); expect(body).toEqual(errorDto.badRequest('Not found or no album.addAsset access')); }); + + it('should add duplicate assets only once', async () => { + const asset = await utils.createAsset(user1.accessToken); + const { status, body } = await request(app) + .put(`/album/${user1Albums[0].id}/assets`) + .set('Authorization', `Bearer ${user1.accessToken}`) + .send({ ids: [asset.id, asset.id] }); + + expect(status).toBe(200); + expect(body).toEqual([ + expect.objectContaining({ id: asset.id, success: true }), + expect.objectContaining({ id: asset.id, success: false, error: 'duplicate' }), + ]); + }); }); describe('PATCH /album/:id', () => { @@ -557,6 +571,19 @@ describe('/album', () => { expect(status).toBe(400); expect(body).toEqual(errorDto.badRequest('Not found or no album.removeAsset access')); }); + + it('should remove duplicate assets only once', async () => { + const { status, body } = await request(app) + .delete(`/album/${user1Albums[1].id}/assets`) + .set('Authorization', `Bearer ${user1.accessToken}`) + .send({ ids: [user1Asset1.id, user1Asset1.id] }); + + expect(status).toBe(200); + expect(body).toEqual([ + expect.objectContaining({ id: user1Asset1.id, success: true }), + expect.objectContaining({ id: user1Asset1.id, success: false, error: 'not_found' }), + ]); + }); }); describe('PUT :id/users', () => { diff --git a/server/src/utils/asset.util.ts b/server/src/utils/asset.util.ts index 253073919f..a55156e679 100644 --- a/server/src/utils/asset.util.ts +++ b/server/src/utils/asset.util.ts @@ -36,6 +36,7 @@ export const addAssets = async ( continue; } + existingAssetIds.add(assetId); results.push({ id: assetId, success: true }); } @@ -79,6 +80,7 @@ export const removeAssets = async ( continue; } + existingAssetIds.delete(assetId); results.push({ id: assetId, success: true }); }