fix(web): a failed like reverts only itself

A like or unlike that failed restored the whole liked list from before it
started, undoing any like made while it was in flight. Now only its own id
goes back to how it was.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-25 22:02:00 -05:00
co-authored by Claude Opus 5.5
parent 785b15ab5f
commit 987c2a68fa
2 changed files with 50 additions and 20 deletions
+22
View File
@@ -69,4 +69,26 @@ describe('likes mutations', () => {
| { track_ids: string[] } | undefined;
expect(cached?.track_ids).not.toContain('t2');
});
test('a failed like reverts only itself, not a like made while it was out', async () => {
let fail!: (e: Error) => void;
(api.post as ReturnType<typeof vi.fn>)
.mockImplementationOnce(() => new Promise((_, reject) => { fail = reject; }))
.mockResolvedValueOnce(null);
const first = likeEntity(client, 'track', 'tA');
await likeEntity(client, 'track', 'tB');
fail(new Error('boom'));
await expect(first).rejects.toThrow('boom');
const cached = client.getQueryData(qk.likedIds()) as { track_ids: string[] } | undefined;
expect(cached?.track_ids).toContain('tB');
expect(cached?.track_ids).not.toContain('tA');
expect(cached?.track_ids).toContain('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');
const cached = client.getQueryData(qk.likedIds()) as { track_ids: string[] } | undefined;
expect(cached?.track_ids).toEqual(['t1']);
});
});