navidrome/server/jellyfin/images_test.go
Deluan Quintão 549dfa7f30
feat(jellyfin): advertise Jellyfin 12.1.0 and add the missing 12.x quick wins (#6163)
* 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.
2026-09-19 13:19:48 -04:00

479 lines
17 KiB
Go

package jellyfin
import (
"bytes"
"context"
"encoding/base64"
"errors"
"image"
"image/gif"
"image/jpeg"
"image/png"
"io"
"net/http"
"net/http/httptest"
"strconv"
"strings"
"time"
"github.com/go-chi/chi/v5"
"github.com/navidrome/navidrome/conf"
"github.com/navidrome/navidrome/conf/configtest"
"github.com/navidrome/navidrome/core/artwork"
"github.com/navidrome/navidrome/model"
"github.com/navidrome/navidrome/model/request"
"github.com/navidrome/navidrome/server/jellyfin/dto"
"github.com/navidrome/navidrome/tests"
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)
type fakeArtwork struct {
artwork.Artwork
recvId string
recvSize int
recvCtx context.Context
data []byte
hash string
}
func (f *fakeArtwork) GetOrPlaceholder(ctx context.Context, id string, size int, square bool) (*artwork.Image, error) {
f.recvId = id
f.recvSize = size
f.recvCtx = ctx
data := f.data
if data == nil {
data = []byte("IMG")
}
return &artwork.Image{
ReadCloser: io.NopCloser(bytes.NewReader(data)),
Hash: f.hash,
LastUpdated: time.Now(),
}, nil
}
func newImageRequest(itemId string) (*httptest.ResponseRecorder, *http.Request) {
w := httptest.NewRecorder()
r := httptest.NewRequest("GET", "/Items/"+itemId+"/Images/Primary", nil)
rctx := chi.NewRouteContext()
rctx.URLParams.Add("itemId", itemId)
rctx.URLParams.Add("type", "Primary")
r = r.WithContext(context.WithValue(r.Context(), chi.RouteCtxKey, rctx))
return w, r
}
var _ = Describe("Images", func() {
// Real Jellyfin fits the image inside either bound, so a client that sends only MaxHeight must
// still get a resized image rather than the full-size original.
DescribeTable("derives the requested size from the Jellyfin size params",
func(query string, wantSize int) {
ds := &tests.MockDataStore{}
ds.Album(context.Background()).(*tests.MockAlbumRepo).SetData(model.Albums{{ID: testID("a1"), Name: "One"}})
fa := &fakeArtwork{}
api := &Router{ds: ds, artwork: fa}
w, r := newImageRequest(dto.EncodeID(testID("a1")))
r.URL.RawQuery = query
api.getItemImage(w, r)
Expect(w.Code).To(Equal(http.StatusOK))
Expect(fa.recvSize).To(Equal(wantSize))
},
Entry("MaxWidth only", "maxwidth=300", 300),
Entry("MaxHeight only", "maxheight=300", 300),
Entry("both, smaller bound wins", "maxwidth=200&maxheight=300", 200),
Entry("both, smaller bound wins regardless of order", "maxwidth=300&maxheight=200", 200),
Entry("neither", "", 0),
Entry("Width only", "width=300", 300),
Entry("Height only", "height=300", 300),
Entry("Width capped by MaxWidth", "width=500&maxwidth=300", 300),
Entry("FillWidth only", "fillwidth=300", 300),
Entry("FillHeight only", "fillheight=300", 300),
Entry("both fill sides, larger one covers the box", "fillwidth=200&fillheight=300", 300),
Entry("fill smaller than MaxWidth wins", "maxwidth=500&fillwidth=300&fillheight=300", 300),
Entry("MaxWidth smaller than fill wins", "maxwidth=200&fillwidth=300&fillheight=300", 200),
Entry("non-positive values are ignored", "fillwidth=0&maxwidth=-5&height=250", 250),
)
It("streams album artwork", func() {
ds := &tests.MockDataStore{}
ds.Album(context.Background()).(*tests.MockAlbumRepo).SetData(model.Albums{{ID: testID("a1"), Name: "One"}})
fa := &fakeArtwork{}
api := &Router{ds: ds, artwork: fa}
w, r := newImageRequest(dto.EncodeID(testID("a1")))
api.getItemImage(w, r)
Expect(w.Code).To(Equal(http.StatusOK))
Expect(w.Body.String()).To(Equal("IMG"))
Expect(fa.recvId).To(ContainSubstring(testID("a1")))
})
// A malformed itemId now 404s via itemIDParam instead of falling through to a placeholder image.
It("404s a malformed itemId instead of serving a placeholder", func() {
ds := &tests.MockDataStore{}
fa := &fakeArtwork{}
api := &Router{ds: ds, artwork: fa}
w, r := newImageRequest("not-a-valid-id")
api.getItemImage(w, r)
Expect(w.Code).To(Equal(http.StatusNotFound))
Expect(fa.recvId).To(BeEmpty(), "artwork resolution must not run for an undecodable id")
})
// resolveArtworkID probes the entity tables, so a deleted item yields no artwork id at all.
It("asks for no artwork once the item is deleted, rather than its lingering state", func() {
ds := &tests.MockDataStore{} // no albums/artists/tracks/playlists at all
fa := &fakeArtwork{}
api := &Router{ds: ds, artwork: fa}
w, r := newImageRequest(dto.EncodeID(testID("deleted-item")))
api.getItemImage(w, r)
// 200 here is what separates a well-formed unknown id from a malformed one, which 404s.
Expect(w.Code).To(Equal(http.StatusOK))
Expect(fa.recvId).To(BeEmpty(), "an empty artwork id can only yield a placeholder")
})
It("sniffs the Content-Type instead of hardcoding it", func() {
ds := &tests.MockDataStore{}
ds.Album(context.Background()).(*tests.MockAlbumRepo).SetData(model.Albums{{ID: testID("a1"), Name: "One"}})
png := append([]byte{0x89, 'P', 'N', 'G', '\r', '\n', 0x1a, '\n'}, make([]byte, 512)...)
fa := &fakeArtwork{data: png}
api := &Router{ds: ds, artwork: fa}
w, r := newImageRequest(dto.EncodeID(testID("a1")))
api.getItemImage(w, r)
Expect(w.Code).To(Equal(http.StatusOK))
Expect(w.Header().Get("Content-Type")).To(Equal("image/png"))
})
It("resolves a playlist's cover regardless of visibility, even for an anonymous caller", func() {
ds := &tests.MockDataStore{}
ds.Playlist(context.Background()).(*tests.MockPlaylistRepo).SetData(model.Playlists{{ID: testID("pl1"), Name: "Mix", OwnerID: testID("someone")}})
fa := &fakeArtwork{}
api := &Router{ds: ds, artwork: fa}
w, r := newImageRequest(dto.EncodeID(testID("pl1")))
api.getItemImage(w, r)
Expect(w.Code).To(Equal(http.StatusOK))
Expect(fa.recvId).To(ContainSubstring(testID("pl1")))
})
// This endpoint is public (no user in the request), so artwork must be resolved under an
// elevated context; otherwise a private playlist's cover fails its visibility filter and
// silently falls back to the placeholder.
It("resolves artwork under an elevated admin context", func() {
ds := &tests.MockDataStore{}
ds.Album(context.Background()).(*tests.MockAlbumRepo).SetData(model.Albums{{ID: testID("a1"), Name: "One"}})
fa := &fakeArtwork{}
api := &Router{ds: ds, artwork: fa}
w, r := newImageRequest(dto.EncodeID(testID("a1")))
api.getItemImage(w, r)
Expect(w.Code).To(Equal(http.StatusOK))
u, ok := request.UserFrom(fa.recvCtx)
Expect(ok).To(BeTrue())
Expect(u.IsAdmin).To(BeTrue())
})
It("serves immutable when the tag param asserts the current hash", func() {
const hash = "0123456789abcdef"
ds := &tests.MockDataStore{}
ds.Album(context.Background()).(*tests.MockAlbumRepo).SetData(model.Albums{{ID: testID("a1"), Name: "One"}})
fa := &fakeArtwork{hash: hash}
api := &Router{ds: ds, artwork: fa}
w, r := newImageRequest(dto.EncodeID(testID("a1")))
q := r.URL.Query()
q.Set("tag", hash)
r.URL.RawQuery = q.Encode()
api.getItemImage(w, r)
Expect(w.Code).To(Equal(http.StatusOK))
Expect(w.Header().Get("Cache-Control")).To(Equal("public, max-age=31536000, immutable"))
Expect(w.Header().Get("ETag")).To(Equal(`"` + hash + `"`))
})
It("revalidates via no-cache when no tag is provided", func() {
const hash = "0123456789abcdef"
ds := &tests.MockDataStore{}
ds.Album(context.Background()).(*tests.MockAlbumRepo).SetData(model.Albums{{ID: testID("a1"), Name: "One"}})
fa := &fakeArtwork{hash: hash}
api := &Router{ds: ds, artwork: fa}
w, r := newImageRequest(dto.EncodeID(testID("a1")))
api.getItemImage(w, r)
Expect(w.Code).To(Equal(http.StatusOK))
Expect(w.Header().Get("Cache-Control")).To(Equal("public, no-cache"))
})
})
// Real image fixtures: postItemImage validates uploads by decoding them.
func pngBytes() []byte {
var b bytes.Buffer
Expect(png.Encode(&b, image.NewRGBA(image.Rect(0, 0, 1, 1)))).To(Succeed())
return b.Bytes()
}
func jpegBytes() []byte {
var b bytes.Buffer
Expect(jpeg.Encode(&b, image.NewRGBA(image.Rect(0, 0, 1, 1)), nil)).To(Succeed())
return b.Bytes()
}
func gifBytes() []byte {
var b bytes.Buffer
Expect(gif.Encode(&b, image.NewRGBA(image.Rect(0, 0, 1, 1)), nil)).To(Succeed())
return b.Bytes()
}
// 1x1 WebP (Go's webp support is decode-only, so this one is pre-encoded).
func webpBytes() []byte {
b, err := base64.StdEncoding.DecodeString(
"UklGRjwAAABXRUJQVlA4IDAAAADQAQCdASoBAAEAAgA0JaACdLoB+AADsAD+8Oj3/yC5YXXI1/8gP+QH/ID/+PIAAAA=")
Expect(err).ToNot(HaveOccurred())
return b
}
var _ = Describe("postItemImage", func() {
var api *Router
var fp *fakePlaylists
BeforeEach(func() {
fp = &fakePlaylists{getByIDPls: &model.Playlist{ID: testID("pl1")}}
api = &Router{playlists: fp}
})
It("uploads a raw JPEG body and returns 204", func() {
body := jpegBytes()
w := httptest.NewRecorder()
r := httptest.NewRequest("POST", "/Items/"+dto.EncodeID(testID("pl1"))+"/Images/Primary", bytes.NewReader(body))
r.Header.Set("Content-Type", "image/jpeg")
r = withChiURLParam(r, "itemId", dto.EncodeID(testID("pl1")))
api.postItemImage(w, r)
Expect(w.Code).To(Equal(http.StatusNoContent))
Expect(fp.setImagePlaylistID).To(Equal(testID("pl1")))
Expect(fp.setImageBytes).To(Equal(body))
Expect(fp.setImageExt).To(Equal(".jpeg"))
})
It("base64-decodes the body and derives the extension from the actual format, not Content-Type", func() {
raw := pngBytes()
encoded := base64.StdEncoding.EncodeToString(raw)
w := httptest.NewRecorder()
r := httptest.NewRequest("POST", "/Items/"+dto.EncodeID(testID("pl1"))+"/Images/Primary", bytes.NewReader([]byte(encoded)))
r.Header.Set("Content-Type", "image/jpeg") // lies: the payload is a PNG
r = withChiURLParam(r, "itemId", dto.EncodeID(testID("pl1")))
api.postItemImage(w, r)
Expect(w.Code).To(Equal(http.StatusNoContent))
Expect(fp.setImageBytes).To(Equal(raw))
Expect(fp.setImageExt).To(Equal(".png"))
})
It("returns 501 for a non-playlist item, draining the body first", func() {
fp.getByIDPls = nil
fp.getByIDErr = model.ErrNotFound
bodyReader := bytes.NewReader([]byte("some-bytes-that-must-be-drained"))
w := httptest.NewRecorder()
r := httptest.NewRequest("POST", "/Items/"+dto.EncodeID(testID("al1"))+"/Images/Primary", bodyReader)
r.Header.Set("Content-Type", "image/jpeg")
r = withChiURLParam(r, "itemId", dto.EncodeID(testID("al1")))
api.postItemImage(w, r)
Expect(w.Code).To(Equal(http.StatusNotImplemented))
Expect(bodyReader.Len()).To(Equal(0))
})
It("returns 500 when the service fails", func() {
fp.setImageErr = errors.New("boom")
w := httptest.NewRecorder()
r := httptest.NewRequest("POST", "/Items/"+dto.EncodeID(testID("pl1"))+"/Images/Primary", bytes.NewReader(jpegBytes()))
r.Header.Set("Content-Type", "image/jpeg")
r = withChiURLParam(r, "itemId", dto.EncodeID(testID("pl1")))
api.postItemImage(w, r)
Expect(w.Code).To(Equal(http.StatusInternalServerError))
})
It("accepts a raw WebP body", func() {
body := webpBytes()
w := httptest.NewRecorder()
r := httptest.NewRequest("POST", "/Items/"+dto.EncodeID(testID("pl1"))+"/Images/Primary", bytes.NewReader(body))
r.Header.Set("Content-Type", "image/webp")
r = withChiURLParam(r, "itemId", dto.EncodeID(testID("pl1")))
api.postItemImage(w, r)
Expect(w.Code).To(Equal(http.StatusNoContent))
Expect(fp.setImageBytes).To(Equal(body))
Expect(fp.setImageExt).To(Equal(".webp"))
})
It("accepts a raw GIF body", func() {
body := gifBytes()
w := httptest.NewRecorder()
r := httptest.NewRequest("POST", "/Items/"+dto.EncodeID(testID("pl1"))+"/Images/Primary", bytes.NewReader(body))
r.Header.Set("Content-Type", "image/gif")
r = withChiURLParam(r, "itemId", dto.EncodeID(testID("pl1")))
api.postItemImage(w, r)
Expect(w.Code).To(Equal(http.StatusNoContent))
Expect(fp.setImageBytes).To(Equal(body))
Expect(fp.setImageExt).To(Equal(".gif"))
})
It("rejects an oversized body with 400, like the native endpoint", func() {
DeferCleanup(configtest.SetupConfig())
conf.Server.MaxImageUploadSize = "16" // 16 bytes
w := httptest.NewRecorder()
r := httptest.NewRequest("POST", "/Items/"+dto.EncodeID(testID("pl1"))+"/Images/Primary", bytes.NewReader(jpegBytes()))
r.Header.Set("Content-Type", "image/jpeg")
r = withChiURLParam(r, "itemId", dto.EncodeID(testID("pl1")))
api.postItemImage(w, r)
Expect(w.Code).To(Equal(http.StatusBadRequest))
Expect(fp.setImagePlaylistID).To(BeEmpty(), "must not persist an over-limit upload")
})
It("applies the size limit to the decoded image, not the base64 body", func() {
DeferCleanup(configtest.SetupConfig())
img := pngBytes()
// The raw image is exactly at the limit; its base64 form is 4/3 bigger.
conf.Server.MaxImageUploadSize = strconv.Itoa(len(img))
body := []byte(base64.StdEncoding.EncodeToString(img))
Expect(len(body)).To(BeNumerically(">", len(img)))
w := httptest.NewRecorder()
r := httptest.NewRequest("POST", "/Items/"+dto.EncodeID(testID("pl1"))+"/Images/Primary", bytes.NewReader(body))
r.Header.Set("Content-Type", "image/png")
r = withChiURLParam(r, "itemId", dto.EncodeID(testID("pl1")))
api.postItemImage(w, r)
Expect(w.Code).To(Equal(http.StatusNoContent))
Expect(fp.setImageBytes).To(Equal(img))
})
It("rejects a base64 body whose decoded image exceeds the limit with 400", func() {
DeferCleanup(configtest.SetupConfig())
img := pngBytes()
conf.Server.MaxImageUploadSize = strconv.Itoa(len(img) - 1)
body := []byte(base64.StdEncoding.EncodeToString(img))
w := httptest.NewRecorder()
r := httptest.NewRequest("POST", "/Items/"+dto.EncodeID(testID("pl1"))+"/Images/Primary", bytes.NewReader(body))
r.Header.Set("Content-Type", "image/png")
r = withChiURLParam(r, "itemId", dto.EncodeID(testID("pl1")))
api.postItemImage(w, r)
Expect(w.Code).To(Equal(http.StatusBadRequest))
Expect(fp.setImagePlaylistID).To(BeEmpty())
})
It("rejects a body that is neither an image nor base64 with 400", func() {
w := httptest.NewRecorder()
r := httptest.NewRequest("POST", "/Items/"+dto.EncodeID(testID("pl1"))+"/Images/Primary", strings.NewReader("!!not base64!!"))
r.Header.Set("Content-Type", "image/jpeg")
r = withChiURLParam(r, "itemId", dto.EncodeID(testID("pl1")))
api.postItemImage(w, r)
Expect(w.Code).To(Equal(http.StatusBadRequest))
Expect(fp.setImagePlaylistID).To(BeEmpty())
})
It("rejects bytes that sniff as an image but don't decode (e.g. a truncated or renamed file)", func() {
body := []byte{0xFF, 0xD8, 0xFF, 0xE0, 0x00, 0x10, 'J', 'F', 'I', 'F'} // JPEG magic, not a JPEG
w := httptest.NewRecorder()
r := httptest.NewRequest("POST", "/Items/"+dto.EncodeID(testID("pl1"))+"/Images/Primary", bytes.NewReader(body))
r.Header.Set("Content-Type", "image/jpeg")
r = withChiURLParam(r, "itemId", dto.EncodeID(testID("pl1")))
api.postItemImage(w, r)
Expect(w.Code).To(Equal(http.StatusBadRequest))
Expect(fp.setImagePlaylistID).To(BeEmpty())
})
It("forbids a non-admin upload when artwork upload is disabled", func() {
DeferCleanup(configtest.SetupConfig())
conf.Server.EnableArtworkUpload = false
w := httptest.NewRecorder()
r := httptest.NewRequest("POST", "/Items/"+dto.EncodeID(testID("pl1"))+"/Images/Primary", bytes.NewReader(jpegBytes()))
r.Header.Set("Content-Type", "image/jpeg")
r = withChiURLParam(r, "itemId", dto.EncodeID(testID("pl1")))
r = r.WithContext(request.WithUser(r.Context(), model.User{ID: testID("u1"), IsAdmin: false}))
api.postItemImage(w, r)
Expect(w.Code).To(Equal(http.StatusForbidden))
Expect(fp.setImagePlaylistID).To(BeEmpty())
})
It("still allows an admin upload when artwork upload is disabled", func() {
DeferCleanup(configtest.SetupConfig())
conf.Server.EnableArtworkUpload = false
w := httptest.NewRecorder()
r := httptest.NewRequest("POST", "/Items/"+dto.EncodeID(testID("pl1"))+"/Images/Primary", bytes.NewReader(jpegBytes()))
r.Header.Set("Content-Type", "image/jpeg")
r = withChiURLParam(r, "itemId", dto.EncodeID(testID("pl1")))
r = r.WithContext(request.WithUser(r.Context(), model.User{ID: testID("admin"), IsAdmin: true}))
api.postItemImage(w, r)
Expect(w.Code).To(Equal(http.StatusNoContent))
})
})
var _ = Describe("deleteItemImage", func() {
It("removes the playlist image and returns 204", func() {
fp := &fakePlaylists{getByIDPls: &model.Playlist{ID: testID("pl1")}}
api := &Router{playlists: fp}
w := httptest.NewRecorder()
r := httptest.NewRequest("DELETE", "/Items/"+dto.EncodeID(testID("pl1"))+"/Images/Primary", nil)
r = withChiURLParam(r, "itemId", dto.EncodeID(testID("pl1")))
api.deleteItemImage(w, r)
Expect(w.Code).To(Equal(http.StatusNoContent))
Expect(fp.removeImagePlaylistID).To(Equal(testID("pl1")))
})
It("returns 501 for a non-playlist item", func() {
fp := &fakePlaylists{getByIDErr: model.ErrNotFound}
api := &Router{playlists: fp}
w := httptest.NewRecorder()
r := httptest.NewRequest("DELETE", "/Items/"+dto.EncodeID(testID("al1"))+"/Images/Primary", nil)
r = withChiURLParam(r, "itemId", dto.EncodeID(testID("al1")))
api.deleteItemImage(w, r)
Expect(w.Code).To(Equal(http.StatusNotImplemented))
})
It("returns 500 when the service fails", func() {
fp := &fakePlaylists{getByIDPls: &model.Playlist{ID: testID("pl1")}, removeImageErr: errors.New("boom")}
api := &Router{playlists: fp}
w := httptest.NewRecorder()
r := httptest.NewRequest("DELETE", "/Items/"+dto.EncodeID(testID("pl1"))+"/Images/Primary", nil)
r = withChiURLParam(r, "itemId", dto.EncodeID(testID("pl1")))
api.deleteItemImage(w, r)
Expect(w.Code).To(Equal(http.StatusInternalServerError))
})
})