fix(likes): the web marks every copy of a liked song, not only the one tapped (#8126)
A like is on the song: the server likes every copy sharing its song_key, but the web's optimistic update marked only the tapped track, so the same song on another album or a compilation showed an empty heart until the liked ids were fetched again. A track like or unlike now answers 200 with the ids of every copy it changed, the asked one first, and the web marks them all. Clients that ignore the body (Android) are unaffected. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -85,6 +85,18 @@ describe('likes mutations', () => {
|
||||
expect(cached?.track_ids).toContain('t1');
|
||||
});
|
||||
|
||||
test('a like marks every copy of the song the server names, and an unlike clears them', async () => {
|
||||
(api.post as ReturnType<typeof vi.fn>).mockResolvedValueOnce({ track_ids: ['t2', 't2-best-of'] });
|
||||
await likeEntity(client, 'track', 't2');
|
||||
let cached = client.getQueryData(qk.likedIds()) as { track_ids: string[] } | undefined;
|
||||
expect(cached?.track_ids).toEqual(['t1', 't2', 't2-best-of']);
|
||||
|
||||
(api.del as ReturnType<typeof vi.fn>).mockResolvedValueOnce({ track_ids: ['t2-best-of', 't2'] });
|
||||
await unlikeEntity(client, 'track', 't2-best-of');
|
||||
cached = client.getQueryData(qk.likedIds()) as { track_ids: string[] } | undefined;
|
||||
expect(cached?.track_ids).toEqual(['t1']);
|
||||
});
|
||||
|
||||
test('a failed unlike puts back only its own like', async () => {
|
||||
(api.del as ReturnType<typeof vi.fn>).mockRejectedValueOnce(new Error('boom'));
|
||||
await expect(unlikeEntity(client, 'track', 't1')).rejects.toThrow('boom');
|
||||
|
||||
Reference in New Issue
Block a user