mirror of
https://github.com/navidrome/navidrome.git
synced 2026-11-26 11:59:48 +01:00
* feat(jellyfin): advertise Jellyfin server version 12.1.0
Streamyfin, jellyfin-android and jellyfin-androidtv refuse servers older than
10.10, Swiftfin warns below 12.0, and @jellyfin/sdk flags anything below its
minimum as unsupported, so 10.9.11 locked those clients out. 12.1.0 is the
current Jellyfin release (after 10.11 Jellyfin renumbered to 12.0). No client
checked has an upper bound or assumes the major is 10, and the value keeps
three parts because the Kotlin SDK and Swiftfin reject two-part versions.
* feat(jellyfin): acknowledge POST /Sessions/Playing/Ping
Jellyfin clients ping this endpoint to keep a transcode job alive while
paused. Navidrome ties transcodes to the stream request, so there is nothing
to keep alive; answer 204 like Jellyfin instead of a 404. It shares one no-op
handler with Sessions/Capabilities, renamed to acknowledge.
* feat(jellyfin): reorder playlist entries via Items/{entryId}/Move
Adds POST /Playlists/{id}/Items/{entryId}/Move/{newIndex}, which clients use
to reorder playlists. It maps the entry's PlaylistItemId (its position) and
Jellyfin's zero-based newIndex onto the existing core ReorderTrack, which
enforces ownership. As in Jellyfin, an index past the end appends and an
unknown entry is a no-op; out-of-range positions never reach Reorder, which
would otherwise shift unrelated rows.
* feat(jellyfin): honor position when adding items to a playlist
POST /Playlists/{id}/Items takes an optional zero-based position (added to
the Jellyfin spec in 12.0). Match Jellyfin: zero or negative prepends, past
the end appends, otherwise the new items are inserted at that index in the
order they were added.
Adds PlaylistTrackRepository.Insert and core playlists.InsertTracks, which
shift the following entries and insert in one transaction, instead of
appending and moving each new track with its own ReorderTrack call.
* feat(jellyfin): add type-specific InstantMix routes
Jellyfin exposes InstantMix under Songs/, Albums/, Artists/ and Playlists/
as well as Items/, plus the legacy Artists/InstantMix and
MusicGenres/InstantMix forms that take the seed as ?id=. Clients generated
from the Jellyfin SDKs call the type-specific routes, which 404ed. All of them
now share the existing Items/{id}/InstantMix handler; the external provider
already builds mixes from song, album, artist, playlist and genre seeds.
* feat(jellyfin): honor Width, Height and Fill* image size params
The image endpoint only read MaxWidth/MaxHeight, so clients that size covers
with fillWidth/fillHeight (Manet, Finamp) or width/height got the full-size
original on a cold artwork cache: a 578 KB PNG instead of a 13 KB resize.
Jellyfin applies Width/Height, caps them with MaxWidth/MaxHeight, then
shrinks to the smallest size that still covers the Fill box. Navidrome
resizes on one dimension, so the tightest bound wins and a fill box counts
as its larger side.
* feat(jellyfin): answer HEAD on audio, file and image routes
Fintunes sends HEAD to /Audio/{id}/universal to read the content type and
detect direct play (a Content-Length means direct play), and to the audio and
image URLs before a download, aborting the download when it fails. Those routes
were GET-only, so HEAD got a 404. HEAD now reuses the GET handlers. Direct
play goes through Stream.Serve, which already answers HEAD; a transcode
answers with the target content type and no length without starting ffmpeg,
so a probe never costs a transcode.
* fix(jellyfin): clamp playlist move and insert positions before adding one
movePlaylistItem computed min(newIndex+1, SongCount): newIndex=MaxInt wrapped
to a negative position, and Reorder then left the playlist with a gap
(positions 2, 3, 999998), making the moved entry unmovable. Clamp against the
playlist length first. addToPlaylist's min(position, MaxInt32)+1 wrapped on
32-bit builds and req.Int truncated large values there, so a far-past-the-end
position prepended; parse as int64 and clamp before converting.
* fix(playlists): validate reorder positions inside the write transaction
Reorder never checked its positions, so a source outside the playlist or a
destination past its end shifted rows around a missing entry and left a gap
(e.g. ids 1 and 3), which made the moved entry unmovable afterwards. The
Jellyfin Move handler guarded this with a SongCount read before ReorderTrack,
but a concurrent removal between the two reopened it, and the native API
reorder endpoint passed client positions through unchecked.
Reorder now reads the last position in the same transaction, returns
ErrNotFound for a source outside the playlist and clamps the destination.
ReorderTrack uses an immediate transaction so that read and the updates are
atomic against other writers. The Jellyfin handler drops its pre-check and
maps ErrNotFound to Jellyfin's no-op 204; the native API now answers 404 for
an unknown track instead of corrupting the order.
438 lines
19 KiB
Go
438 lines
19 KiB
Go
package e2e
|
|
|
|
import (
|
|
"bytes"
|
|
"image"
|
|
jpeglib "image/jpeg"
|
|
"net/http"
|
|
"os"
|
|
|
|
"github.com/navidrome/navidrome/model"
|
|
"github.com/navidrome/navidrome/server/jellyfin/dto"
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
var _ = Describe("Playlists", func() {
|
|
BeforeEach(func() { setupTestDB() })
|
|
|
|
playlistItems := func(plID string) dto.QueryResult {
|
|
return queryResult(get("/Playlists/" + enc(plID) + "/Items"))
|
|
}
|
|
order := func(plID string) []string { return names(playlistItems(plID).Items) }
|
|
|
|
Describe("create", func() {
|
|
It("creates an empty playlist", func() {
|
|
plID := createPlaylist("Empty", nil)
|
|
var info dto.PlaylistInfo
|
|
parseInto(get("/Playlists/"+enc(plID)), &info)
|
|
Expect(info.OpenAccess).To(BeFalse())
|
|
Expect(info.Shares).To(BeEmpty())
|
|
Expect(info.ItemIds).To(BeEmpty())
|
|
})
|
|
|
|
It("creates a playlist from song ids", func() {
|
|
plID := createPlaylist("Songs", []string{enc(songID("Come Together")), enc(songID("So What"))})
|
|
Expect(playlistItems(plID).TotalRecordCount).To(Equal(2))
|
|
})
|
|
|
|
It("expands an album id into its tracks", func() {
|
|
plID := createPlaylist("From Album", []string{enc(albumID("Abbey Road"))})
|
|
q := playlistItems(plID)
|
|
Expect(q.TotalRecordCount).To(Equal(2))
|
|
Expect(names(q.Items)).To(ConsistOf("Come Together", "Something"))
|
|
})
|
|
|
|
It("expands an artist id into its tracks", func() {
|
|
plID := createPlaylist("From Artist", []string{enc(artistID("The Beatles"))})
|
|
Expect(playlistItems(plID).TotalRecordCount).To(Equal(3)) // Abbey Road (2) + Help! (1)
|
|
})
|
|
|
|
// dto.DecodeIDs is all-or-nothing: a malformed entry must 404 the whole request, not get
|
|
// dropped while the well-formed entries are still used to create a playlist.
|
|
It("404s when one of the Ids is malformed, without creating a playlist", func() {
|
|
before, err := ds.Playlist(ctx).CountAll()
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
body := `{"Name":"ShouldNotExist","Ids":["` + enc(songID("So What")) + `","not-a-valid-id"]}`
|
|
Expect(post("/Playlists", body).Code).To(Equal(http.StatusNotFound))
|
|
|
|
after, err := ds.Playlist(ctx).CountAll()
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(after).To(Equal(before))
|
|
})
|
|
})
|
|
|
|
Describe("items", func() {
|
|
It("tags each entry with a PlaylistItemId", func() {
|
|
plID := createPlaylist("Tagged", []string{enc(songID("Help!"))})
|
|
q := playlistItems(plID)
|
|
Expect(q.Items).To(HaveLen(1))
|
|
Expect(q.Items[0].Type).To(Equal("Audio"))
|
|
Expect(q.Items[0].PlaylistItemId).ToNot(BeEmpty())
|
|
})
|
|
})
|
|
|
|
Describe("add and remove", func() {
|
|
It("adds a song by id", func() {
|
|
plID := createPlaylist("Add", nil)
|
|
Expect(post("/Playlists/"+enc(plID)+"/Items?ids="+enc(songID("So What")), "").Code).To(Equal(http.StatusNoContent))
|
|
Expect(playlistItems(plID).TotalRecordCount).To(Equal(1))
|
|
})
|
|
|
|
It("adds an album (expanding to its tracks)", func() {
|
|
plID := createPlaylist("AddAlbum", []string{enc(songID("So What"))})
|
|
post("/Playlists/"+enc(plID)+"/Items?ids="+enc(albumID("Abbey Road")), "")
|
|
Expect(playlistItems(plID).TotalRecordCount).To(Equal(3)) // 1 + Abbey Road (2)
|
|
})
|
|
|
|
// Jellify's @jellyfin/sdk serializes id arrays as repeated params (ids=X&ids=Y), not a
|
|
// comma-joined value; all ids must be added, not just the first.
|
|
It("adds multiple songs sent as repeated ids params", func() {
|
|
plID := createPlaylist("Multi", nil)
|
|
url := "/Playlists/" + enc(plID) + "/Items?ids=" + enc(songID("So What")) +
|
|
"&ids=" + enc(songID("Come Together")) + "&ids=" + enc(songID("Help!"))
|
|
Expect(post(url, "").Code).To(Equal(http.StatusNoContent))
|
|
Expect(playlistItems(plID).TotalRecordCount).To(Equal(3))
|
|
})
|
|
|
|
It("404s when one of the ids to add is malformed, without adding any track", func() {
|
|
plID := createPlaylist("AddMalformed", nil)
|
|
url := "/Playlists/" + enc(plID) + "/Items?ids=" + enc(songID("So What")) + ",not-a-valid-id"
|
|
Expect(post(url, "").Code).To(Equal(http.StatusNotFound))
|
|
Expect(playlistItems(plID).TotalRecordCount).To(BeZero())
|
|
})
|
|
|
|
Describe("at a position", func() {
|
|
var plID string
|
|
addAt := func(position string, ids ...string) {
|
|
url := "/Playlists/" + enc(plID) + "/Items?position=" + position
|
|
for _, id := range ids {
|
|
url += "&ids=" + enc(id)
|
|
}
|
|
Expect(post(url, "").Code).To(Equal(http.StatusNoContent))
|
|
}
|
|
BeforeEach(func() {
|
|
plID = createPlaylist("Insert", []string{enc(songID("Come Together")), enc(songID("Something"))})
|
|
})
|
|
|
|
DescribeTable("inserts at Jellyfin's zero-based position",
|
|
func(position string, want []string) {
|
|
addAt(position, songID("So What"), songID("Help!"))
|
|
Expect(order(plID)).To(Equal(want))
|
|
},
|
|
Entry("in the middle", "1", []string{"Come Together", "So What", "Help!", "Something"}),
|
|
Entry("first, for zero or less", "-3", []string{"So What", "Help!", "Come Together", "Something"}),
|
|
Entry("last, past the end", "9", []string{"Come Together", "Something", "So What", "Help!"}),
|
|
)
|
|
|
|
It("keeps an expanded album's track order", func() {
|
|
albumOrder := order(createPlaylist("Album", []string{enc(albumID("Abbey Road"))}))
|
|
addAt("1", albumID("Abbey Road"))
|
|
Expect(order(plID)).To(Equal(append(append([]string{"Come Together"}, albumOrder...), "Something")))
|
|
})
|
|
})
|
|
|
|
It("removes an entry by its PlaylistItemId", func() {
|
|
plID := createPlaylist("Remove", []string{enc(songID("Come Together")), enc(songID("Something"))})
|
|
entryID := playlistItems(plID).Items[0].PlaylistItemId
|
|
Expect(del("/Playlists/" + enc(plID) + "/Items?entryIds=" + entryID).Code).To(Equal(http.StatusNoContent))
|
|
Expect(playlistItems(plID).TotalRecordCount).To(Equal(1))
|
|
})
|
|
|
|
It("removes multiple entries sent as repeated entryIds params", func() {
|
|
plID := createPlaylist("MultiRemove", []string{enc(songID("Come Together")), enc(songID("Something")), enc(songID("So What"))})
|
|
items := playlistItems(plID).Items
|
|
url := "/Playlists/" + enc(plID) + "/Items?entryIds=" + items[0].PlaylistItemId + "&entryIds=" + items[1].PlaylistItemId
|
|
Expect(del(url).Code).To(Equal(http.StatusNoContent))
|
|
Expect(playlistItems(plID).TotalRecordCount).To(Equal(1))
|
|
})
|
|
})
|
|
|
|
Describe("move", func() {
|
|
move := func(u model.User, plID, entryID string, newIndex string) int {
|
|
return jReq(u, "POST", "/Playlists/"+enc(plID)+"/Items/"+entryID+"/Move/"+newIndex, "").Code
|
|
}
|
|
var plID string
|
|
var entries []dto.BaseItemDto
|
|
BeforeEach(func() {
|
|
plID = createPlaylist("Move", []string{enc(songID("Come Together")), enc(songID("Something")), enc(songID("So What"))})
|
|
entries = playlistItems(plID).Items
|
|
})
|
|
|
|
DescribeTable("moves an entry to Jellyfin's zero-based index",
|
|
func(entry int, newIndex string, want []string) {
|
|
Expect(move(adminUser, plID, entries[entry].PlaylistItemId, newIndex)).To(Equal(http.StatusNoContent))
|
|
Expect(order(plID)).To(Equal(want))
|
|
var positions []string
|
|
for _, it := range playlistItems(plID).Items {
|
|
positions = append(positions, it.PlaylistItemId)
|
|
}
|
|
Expect(positions).To(Equal([]string{dto.EncodePlaylistEntryID("1"), dto.EncodePlaylistEntryID("2"), dto.EncodePlaylistEntryID("3")}))
|
|
},
|
|
Entry("towards the end", 0, "2", []string{"Something", "So What", "Come Together"}),
|
|
Entry("towards the start", 2, "0", []string{"So What", "Come Together", "Something"}),
|
|
Entry("to the end, past the last index", 0, "99", []string{"Something", "So What", "Come Together"}),
|
|
Entry("to the end, for the largest int", 0, "9223372036854775807", []string{"Something", "So What", "Come Together"}),
|
|
)
|
|
|
|
It("ignores an entry that is not in the playlist", func() {
|
|
Expect(move(adminUser, plID, dto.EncodePlaylistEntryID("42"), "0")).To(Equal(http.StatusNoContent))
|
|
Expect(order(plID)).To(Equal([]string{"Come Together", "Something", "So What"}))
|
|
})
|
|
|
|
It("404s on a malformed entry id", func() {
|
|
Expect(move(adminUser, plID, enc(songID("So What")), "0")).To(Equal(http.StatusNotFound))
|
|
})
|
|
|
|
It("hides another user's private playlist", func() {
|
|
Expect(move(regularUser, plID, entries[0].PlaylistItemId, "2")).To(Equal(http.StatusNotFound))
|
|
Expect(order(plID)).To(Equal([]string{"Come Together", "Something", "So What"}))
|
|
})
|
|
|
|
It("forbids a non-owner on a public playlist", func() {
|
|
Expect(post("/Playlists/"+enc(plID), `{"Name":"Move","IsPublic":true}`).Code).To(Equal(http.StatusNoContent))
|
|
Expect(move(regularUser, plID, entries[0].PlaylistItemId, "2")).To(Equal(http.StatusForbidden))
|
|
Expect(order(plID)).To(Equal([]string{"Come Together", "Something", "So What"}))
|
|
})
|
|
|
|
It("rejects a negative index", func() {
|
|
Expect(move(adminUser, plID, entries[0].PlaylistItemId, "-1")).To(Equal(http.StatusBadRequest))
|
|
})
|
|
})
|
|
|
|
Describe("users", func() {
|
|
It("reports the current user as an editor", func() {
|
|
plID := createPlaylist("Perms", nil)
|
|
var perms []dto.PlaylistUserPermissions
|
|
parseInto(get("/Playlists/"+enc(plID)+"/Users"), &perms)
|
|
Expect(perms).To(HaveLen(1))
|
|
Expect(perms[0].UserId).To(Equal(enc(testID("admin-1"))))
|
|
Expect(perms[0].CanEdit).To(BeTrue())
|
|
})
|
|
})
|
|
|
|
Describe("listing", func() {
|
|
It("lists a created playlist advertising a Primary image tag", func() {
|
|
createPlaylist("Listed", nil)
|
|
q := queryResult(get("/Items?IncludeItemTypes=Playlist&Recursive=true"))
|
|
Expect(q.TotalRecordCount).To(Equal(1))
|
|
Expect(q.Items[0].Name).To(Equal("Listed"))
|
|
Expect(q.Items[0].ImageTags).To(HaveKey("Primary"))
|
|
})
|
|
|
|
It("sorts playlists by name when SortBy=SortName", func() {
|
|
createPlaylist("Charlie", nil)
|
|
createPlaylist("Alpha", nil)
|
|
createPlaylist("Bravo", nil)
|
|
q := queryResult(get("/Items?IncludeItemTypes=Playlist&Recursive=true&SortBy=SortName"))
|
|
Expect(names(q.Items)).To(Equal([]string{"Alpha", "Bravo", "Charlie"}))
|
|
})
|
|
})
|
|
|
|
// Jellify resolves the "playlists library" via a ManualPlaylistsFolder query, then lists
|
|
// playlists with ParentId set to that folder's id (no IncludeItemTypes). Without a folder item
|
|
// whose CollectionType is "playlists", its query resolves undefined and React Query retries in a
|
|
// backoff loop that stalls the home screen.
|
|
Describe("playlists library folder (ManualPlaylistsFolder)", func() {
|
|
It("returns a synthetic playlists folder with CollectionType=playlists", func() {
|
|
q := queryResult(get("/Items?includeItemTypes=ManualPlaylistsFolder&excludeItemTypes=CollectionFolder"))
|
|
Expect(q.Items).To(HaveLen(1))
|
|
Expect(q.Items[0].CollectionType).To(Equal("playlists"))
|
|
Expect(q.Items[0].Id).To(Equal(dto.PlaylistsFolderGUID))
|
|
})
|
|
|
|
It("lists the user's playlists when browsing the folder by ParentId (no IncludeItemTypes)", func() {
|
|
createPlaylist("My Mix", nil)
|
|
q := queryResult(get("/Items?parentId=" + dto.PlaylistsFolderGUID))
|
|
Expect(names(q.Items)).To(ContainElement("My Mix"))
|
|
Expect(q.Items[0].Type).To(Equal("Playlist"))
|
|
// Jellify keeps only playlists whose Path contains "data".
|
|
Expect(q.Items[0].Path).To(ContainSubstring("data"))
|
|
})
|
|
|
|
It("resolves the synthetic playlists folder by its own advertised id", func() {
|
|
var item dto.BaseItemDto
|
|
parseInto(get("/Items/"+dto.PlaylistsFolderGUID), &item)
|
|
Expect(item.Type).To(Equal("ManualPlaylistsFolder"))
|
|
Expect(item.CollectionType).To(Equal("playlists"))
|
|
Expect(item.Id).To(Equal(dto.PlaylistsFolderGUID))
|
|
})
|
|
})
|
|
|
|
// Real Jellyfin returns a playlist's children for /Items?ParentId=<playlistId> with no
|
|
// IncludeItemTypes; generic clients (not Finamp/Jellify) browse playlists this way.
|
|
Describe("browsing a playlist via the generic /Items path", func() {
|
|
It("lists the playlist's tracks for a typeless ParentId query", func() {
|
|
plID := createPlaylist("Browse Me", []string{enc(songID("Come Together")), enc(songID("So What"))})
|
|
q := queryResult(get("/Items?parentId=" + enc(plID)))
|
|
Expect(q.TotalRecordCount).To(Equal(2))
|
|
Expect(names(q.Items)).To(ConsistOf("Come Together", "So What"))
|
|
Expect(q.Items[0].Type).To(Equal("Audio"))
|
|
})
|
|
|
|
It("pages the playlist's tracks", func() {
|
|
plID := createPlaylist("Browse Paged", []string{enc(songID("Come Together")), enc(songID("So What"))})
|
|
q := queryResult(get("/Items?parentId=" + enc(plID) + "&startIndex=1&limit=1"))
|
|
Expect(q.Items).To(HaveLen(1))
|
|
Expect(q.TotalRecordCount).To(Equal(2))
|
|
})
|
|
|
|
// Jellify opens a playlist with ParentId=<playlist>&IncludeItemTypes=Audio&Recursive=false.
|
|
// The playlist id must resolve to its tracks, not be treated as an album id (which returns none).
|
|
It("lists the playlist's tracks even when IncludeItemTypes=Audio is set", func() {
|
|
plID := createPlaylist("Typed Browse", []string{enc(songID("Come Together")), enc(songID("So What"))})
|
|
q := queryResult(get("/Items?parentId=" + enc(plID) + "&includeItemTypes=Audio&recursive=false"))
|
|
Expect(q.TotalRecordCount).To(Equal(2))
|
|
Expect(names(q.Items)).To(ConsistOf("Come Together", "So What"))
|
|
})
|
|
})
|
|
|
|
Describe("cover art", func() {
|
|
// A real (decodable) image: the upload endpoint validates by decoding, like the native one.
|
|
var jpeg []byte
|
|
BeforeEach(func() {
|
|
var buf bytes.Buffer
|
|
Expect(jpeglib.Encode(&buf, image.NewRGBA(image.Rect(0, 0, 1, 1)), nil)).To(Succeed())
|
|
jpeg = buf.Bytes()
|
|
})
|
|
|
|
It("uploads and removes a playlist cover", func() {
|
|
plID := createPlaylist("Cover", nil)
|
|
|
|
Expect(upload(adminUser, "/Items/"+enc(plID)+"/Images/Primary", "image/jpeg", jpeg).Code).
|
|
To(Equal(http.StatusNoContent))
|
|
|
|
pls, err := ds.Playlist(ctx).Get(plID)
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(pls.UploadedImage).ToNot(BeEmpty())
|
|
_, statErr := os.Stat(pls.UploadedImagePath())
|
|
Expect(statErr).ToNot(HaveOccurred(), "cover file should exist on disk")
|
|
|
|
Expect(del("/Items/" + enc(plID) + "/Images/Primary").Code).To(Equal(http.StatusNoContent))
|
|
pls, _ = ds.Playlist(ctx).Get(plID)
|
|
Expect(pls.UploadedImage).To(BeEmpty())
|
|
})
|
|
|
|
It("rejects cover upload for a non-playlist item", func() {
|
|
Expect(upload(adminUser, "/Items/"+enc(albumID("IV"))+"/Images/Primary", "image/jpeg", jpeg).Code).
|
|
To(Equal(http.StatusNotImplemented))
|
|
})
|
|
|
|
// An upload must clear the resolved artwork state, or clients keep serving the stale cover
|
|
// from their tag-keyed cache until the next scan.
|
|
It("clears the resolved image tag after a cover upload", func() {
|
|
plID := createPlaylist("Cover Tag", nil)
|
|
Expect(ds.Artwork(ctx).PutItemArtwork(&model.ItemArtwork{
|
|
ItemKind: model.KindPlaylistArtwork.Prefix(), ItemID: plID, Hash: "1111111111111111",
|
|
})).To(Succeed())
|
|
|
|
imageTag := func() string {
|
|
q := queryResult(get("/Items?ids=" + enc(plID)))
|
|
Expect(q.Items).To(HaveLen(1))
|
|
return q.Items[0].ImageTags["Primary"]
|
|
}
|
|
Expect(imageTag()).To(Equal("1111111111111111"))
|
|
|
|
Expect(upload(adminUser, "/Items/"+enc(plID)+"/Images/Primary", "image/jpeg", jpeg).Code).
|
|
To(Equal(http.StatusNoContent))
|
|
|
|
// The upload re-queues resolution instead of resolving inline, so the tag goes bare.
|
|
Expect(imageTag()).ToNot(Equal("1111111111111111"))
|
|
})
|
|
})
|
|
|
|
Describe("update", func() {
|
|
It("404s when one of the replacement Ids is malformed, leaving the track list unchanged", func() {
|
|
plID := createPlaylist("UpdateMalformed", []string{enc(songID("Come Together"))})
|
|
body := `{"Ids":["` + enc(songID("So What")) + `","not-a-valid-id"]}`
|
|
Expect(post("/Playlists/"+enc(plID), body).Code).To(Equal(http.StatusNotFound))
|
|
q := playlistItems(plID)
|
|
Expect(q.TotalRecordCount).To(Equal(1))
|
|
Expect(names(q.Items)).To(ConsistOf("Come Together"))
|
|
})
|
|
|
|
It("makes a playlist public", func() {
|
|
plID := createPlaylist("Make Public", nil)
|
|
Expect(post("/Playlists/"+enc(plID), `{"Name":"Make Public","IsPublic":true}`).Code).To(Equal(http.StatusNoContent))
|
|
|
|
var info dto.PlaylistInfo
|
|
parseInto(get("/Playlists/"+enc(plID)), &info)
|
|
Expect(info.OpenAccess).To(BeTrue())
|
|
// Now visible to other users.
|
|
Expect(queryResult(getAs(regularUser, "/Items?IncludeItemTypes=Playlist&Recursive=true")).TotalRecordCount).To(Equal(1))
|
|
})
|
|
|
|
It("renames a playlist", func() {
|
|
plID := createPlaylist("Old Name", nil)
|
|
Expect(post("/Playlists/"+enc(plID), `{"Name":"New Name"}`).Code).To(Equal(http.StatusNoContent))
|
|
pls, _ := ds.Playlist(ctx).Get(plID)
|
|
Expect(pls.Name).To(Equal("New Name"))
|
|
})
|
|
|
|
It("replaces the track list when Ids are provided", func() {
|
|
plID := createPlaylist("Reorder", []string{enc(songID("Come Together")), enc(songID("Something"))})
|
|
// Replace with a single different track.
|
|
Expect(post("/Playlists/"+enc(plID), `{"Ids":["`+enc(songID("So What"))+`"]}`).Code).To(Equal(http.StatusNoContent))
|
|
q := playlistItems(plID)
|
|
Expect(q.TotalRecordCount).To(Equal(1))
|
|
Expect(q.Items[0].Name).To(Equal("So What"))
|
|
})
|
|
|
|
It("clears the track list when an explicit empty Ids array is sent", func() {
|
|
plID := createPlaylist("Clear Me", []string{enc(songID("Come Together")), enc(songID("Something"))})
|
|
Expect(post("/Playlists/"+enc(plID), `{"Ids":[]}`).Code).To(Equal(http.StatusNoContent))
|
|
Expect(playlistItems(plID).TotalRecordCount).To(Equal(0))
|
|
})
|
|
|
|
It("leaves the track list intact when Ids is omitted (metadata-only update)", func() {
|
|
plID := createPlaylist("Keep Tracks", []string{enc(songID("Come Together")), enc(songID("Something"))})
|
|
Expect(post("/Playlists/"+enc(plID), `{"Name":"Renamed"}`).Code).To(Equal(http.StatusNoContent))
|
|
Expect(playlistItems(plID).TotalRecordCount).To(Equal(2))
|
|
})
|
|
|
|
It("applies Name and IsPublic sent together with a track replacement", func() {
|
|
plID := createPlaylist("Combo", []string{enc(songID("Come Together"))})
|
|
body := `{"Name":"Combo Renamed","IsPublic":true,"Ids":["` + enc(songID("So What")) + `"]}`
|
|
Expect(post("/Playlists/"+enc(plID), body).Code).To(Equal(http.StatusNoContent))
|
|
q := playlistItems(plID)
|
|
Expect(q.TotalRecordCount).To(Equal(1))
|
|
Expect(q.Items[0].Name).To(Equal("So What"))
|
|
pls, _ := ds.Playlist(ctx).Get(plID)
|
|
Expect(pls.Name).To(Equal("Combo Renamed"))
|
|
Expect(pls.Public).To(BeTrue())
|
|
})
|
|
|
|
It("forbids a non-owner from updating a public playlist", func() {
|
|
plID := createPlaylist("Owned", nil)
|
|
post("/Playlists/"+enc(plID), `{"IsPublic":true}`) // make it visible to the regular user
|
|
Expect(postAs(regularUser, "/Playlists/"+enc(plID), `{"Name":"Hijacked"}`).Code).To(Equal(http.StatusForbidden))
|
|
})
|
|
|
|
// An id that decodes to "" would tell Create to make a new playlist instead of updating one —
|
|
// itemIDParam must 404 before that decode ever runs, not silently create one.
|
|
It("404s for a malformed playlist id, without creating a playlist", func() {
|
|
before, err := ds.Playlist(ctx).CountAll()
|
|
Expect(err).ToNot(HaveOccurred())
|
|
|
|
w := post("/Playlists/00000000000000000000000000000000", `{"Ids":["`+enc(songID("So What"))+`"]}`)
|
|
Expect(w.Code).To(Equal(http.StatusNotFound))
|
|
|
|
after, err := ds.Playlist(ctx).CountAll()
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(after).To(Equal(before))
|
|
})
|
|
})
|
|
|
|
Describe("delete", func() {
|
|
It("deletes a playlist", func() {
|
|
plID := createPlaylist("ToDelete", nil)
|
|
Expect(del("/Items/" + enc(plID)).Code).To(Equal(http.StatusNoContent))
|
|
Expect(queryResult(get("/Items?IncludeItemTypes=Playlist&Recursive=true")).TotalRecordCount).To(Equal(0))
|
|
})
|
|
|
|
It("returns 404 when deleting a non-playlist item", func() {
|
|
Expect(del("/Items/" + enc(albumID("IV"))).Code).To(Equal(http.StatusNotFound))
|
|
})
|
|
})
|
|
})
|