mirror of
https://github.com/immich-app/immich.git
synced 2024-11-24 08:52:28 +02:00
fix(server): addAssets and removeAssets handle duplicate assetIds (#9436)
* fix(server): addAssets and removeAssets handle duplicate assetIds * chore(server): Add e2e tests for duplicate album additions and removals
This commit is contained in:
parent
e479e556bc
commit
6fd6a8ba15
@ -434,6 +434,20 @@ describe('/album', () => {
|
|||||||
expect(status).toBe(400);
|
expect(status).toBe(400);
|
||||||
expect(body).toEqual(errorDto.badRequest('Not found or no album.addAsset access'));
|
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', () => {
|
describe('PATCH /album/:id', () => {
|
||||||
@ -557,6 +571,19 @@ describe('/album', () => {
|
|||||||
expect(status).toBe(400);
|
expect(status).toBe(400);
|
||||||
expect(body).toEqual(errorDto.badRequest('Not found or no album.removeAsset access'));
|
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', () => {
|
describe('PUT :id/users', () => {
|
||||||
|
@ -36,6 +36,7 @@ export const addAssets = async (
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
existingAssetIds.add(assetId);
|
||||||
results.push({ id: assetId, success: true });
|
results.push({ id: assetId, success: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,6 +80,7 @@ export const removeAssets = async (
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
existingAssetIds.delete(assetId);
|
||||||
results.push({ id: assetId, success: true });
|
results.push({ id: assetId, success: true });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user