fix(subsonic): updatePlaylist checks the songs to add before changing anything (#8123)
The name, comment, removals and additions are separate writes, and the songs to add were only found missing when the last of them ran, so an unknown songIdToAdd answered error 70 over a playlist already renamed and trimmed. Every song to add is now looked up first, alongside the index check, and an unknown one answers 70 with nothing changed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -149,6 +149,18 @@ func TestUpdatePlaylist_IndexesCountTheSongsTheAppWasShown(t *testing.T) {
|
||||
if d := stored(t, h.playlists, f.user, id); d.Name != "Night Drive" || len(d.Tracks) != 2 {
|
||||
t.Errorf("after a refused update: name %q, %d songs; want it unchanged", d.Name, len(d.Tracks))
|
||||
}
|
||||
|
||||
// So does a song to add that isn't in the library, though it comes
|
||||
// after a rename and a removal that would each have worked.
|
||||
unknown := uuidToID(pgtype.UUID{Bytes: [16]byte{0xee}, Valid: true})
|
||||
q = "playlistId=" + pid + "&name=Changed&songIndexToRemove=0&songIdToAdd=" + unknown
|
||||
if code := call(t, h.updatePlaylist, f.user, q, nil); code != ErrDataNotFound {
|
||||
t.Errorf("unknown song to add: error %d, want %d", code, ErrDataNotFound)
|
||||
}
|
||||
d = stored(t, h.playlists, f.user, id)
|
||||
if got, want := storedTitles(d), []string{"Jetty", "Gale"}; d.Name != "Night Drive" || !slices.Equal(got, want) {
|
||||
t.Errorf("after an unknown song: name %q, songs %v; want Night Drive, %v", d.Name, got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestPlaylistWrites_OnlyTheOwnersOwnLists(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user