mirror of
https://github.com/navidrome/navidrome.git
synced 2026-03-04 06:35:52 +00:00
* test(e2e): add comprehensive tests for Subsonic API endpoints Signed-off-by: Deluan <deluan@navidrome.org> * fix(e2e): improve database handling and snapshot restoration in tests Signed-off-by: Deluan <deluan@navidrome.org> * test(e2e): add tests for album sharing and user isolation scenarios Signed-off-by: Deluan <deluan@navidrome.org> * test(e2e): add tests for multi-library support and user access control Signed-off-by: Deluan <deluan@navidrome.org> * test(e2e): tests are fast, no need to skip on -short Signed-off-by: Deluan <deluan@navidrome.org> * address gemini comments Signed-off-by: Deluan <deluan@navidrome.org> * fix(tests): prevent MockDataStore from caching repos with stale context When RealDS is set, MockDataStore previously cached repository instances on first access, binding them to the initial caller's context. This meant repos created with an admin context would skip library filtering for all subsequent non-admin calls, silently masking access control bugs. Changed MockDataStore to delegate to RealDS on every call without caching, so each caller gets a fresh repo with the correct context. Removed the pre-warm calls in e2e setupTestDB that were working around the old caching behavior. * test(e2e): route subsonic tests through full HTTP middleware stack Replace direct router method calls with full HTTP round-trips via router.ServeHTTP(w, r) across all 15 e2e test files. Tests now exercise the complete chi middleware chain including postFormToQueryParams, checkRequiredParameters, authenticate, UpdateLastAccessMiddleware, getPlayer, and sendResponse/sendError serialization. New helpers (doReq, doReqWithUser, doRawReq, buildReq, parseJSONResponse) use plaintext password auth and JSON response format. Old helpers that injected context directly (newReq, newReqWithUser, newRawReq) are removed. Sharing tests now set conf.Server.EnableSharing before router creation to ensure sharing routes are registered. --------- Signed-off-by: Deluan <deluan@navidrome.org>
161 lines
4.3 KiB
Go
161 lines
4.3 KiB
Go
package e2e
|
|
|
|
import (
|
|
"github.com/navidrome/navidrome/model"
|
|
"github.com/navidrome/navidrome/server/subsonic/responses"
|
|
. "github.com/onsi/ginkgo/v2"
|
|
. "github.com/onsi/gomega"
|
|
)
|
|
|
|
var _ = Describe("Media Annotation Endpoints", Ordered, func() {
|
|
BeforeAll(func() {
|
|
setupTestDB()
|
|
})
|
|
|
|
Describe("Star/Unstar", Ordered, func() {
|
|
var songID, albumID, artistID string
|
|
|
|
BeforeAll(func() {
|
|
// Look up a song from the scanned data
|
|
songs, err := ds.MediaFile(ctx).GetAll(model.QueryOptions{Max: 1, Sort: "title"})
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(songs).ToNot(BeEmpty())
|
|
songID = songs[0].ID
|
|
|
|
// Look up an album
|
|
albums, err := ds.Album(ctx).GetAll(model.QueryOptions{Max: 1, Sort: "name"})
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(albums).ToNot(BeEmpty())
|
|
albumID = albums[0].ID
|
|
|
|
// Look up an artist
|
|
artists, err := ds.Artist(ctx).GetAll(model.QueryOptions{Max: 1, Sort: "name"})
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(artists).ToNot(BeEmpty())
|
|
artistID = artists[0].ID
|
|
})
|
|
|
|
It("stars a song by id", func() {
|
|
resp := doReq("star", "id", songID)
|
|
|
|
Expect(resp.Status).To(Equal(responses.StatusOK))
|
|
})
|
|
|
|
It("starred song appears in getStarred response", func() {
|
|
resp := doReq("getStarred")
|
|
|
|
Expect(resp.Status).To(Equal(responses.StatusOK))
|
|
Expect(resp.Starred).ToNot(BeNil())
|
|
Expect(resp.Starred.Song).To(HaveLen(1))
|
|
Expect(resp.Starred.Song[0].Id).To(Equal(songID))
|
|
})
|
|
|
|
It("unstars a previously starred song", func() {
|
|
resp := doReq("unstar", "id", songID)
|
|
|
|
Expect(resp.Status).To(Equal(responses.StatusOK))
|
|
|
|
// Verify song no longer appears in starred
|
|
resp = doReq("getStarred")
|
|
|
|
Expect(resp.Starred.Song).To(BeEmpty())
|
|
})
|
|
|
|
It("stars an album by albumId", func() {
|
|
resp := doReq("star", "albumId", albumID)
|
|
|
|
Expect(resp.Status).To(Equal(responses.StatusOK))
|
|
|
|
// Verify album appears in starred
|
|
resp = doReq("getStarred")
|
|
|
|
Expect(resp.Starred.Album).To(HaveLen(1))
|
|
Expect(resp.Starred.Album[0].Id).To(Equal(albumID))
|
|
})
|
|
|
|
It("stars an artist by artistId", func() {
|
|
resp := doReq("star", "artistId", artistID)
|
|
|
|
Expect(resp.Status).To(Equal(responses.StatusOK))
|
|
|
|
// Verify artist appears in starred
|
|
resp = doReq("getStarred")
|
|
|
|
Expect(resp.Starred.Artist).To(HaveLen(1))
|
|
Expect(resp.Starred.Artist[0].Id).To(Equal(artistID))
|
|
})
|
|
|
|
It("returns error when no id provided", func() {
|
|
resp := doReq("star")
|
|
|
|
Expect(resp.Status).To(Equal(responses.StatusFailed))
|
|
Expect(resp.Error).ToNot(BeNil())
|
|
})
|
|
})
|
|
|
|
Describe("SetRating", Ordered, func() {
|
|
var songID, albumID string
|
|
|
|
BeforeAll(func() {
|
|
songs, err := ds.MediaFile(ctx).GetAll(model.QueryOptions{Max: 1, Sort: "title"})
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(songs).ToNot(BeEmpty())
|
|
songID = songs[0].ID
|
|
|
|
albums, err := ds.Album(ctx).GetAll(model.QueryOptions{Max: 1, Sort: "name"})
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(albums).ToNot(BeEmpty())
|
|
albumID = albums[0].ID
|
|
})
|
|
|
|
It("sets rating on a song", func() {
|
|
resp := doReq("setRating", "id", songID, "rating", "4")
|
|
|
|
Expect(resp.Status).To(Equal(responses.StatusOK))
|
|
})
|
|
|
|
It("rated song has correct userRating in getSong", func() {
|
|
resp := doReq("getSong", "id", songID)
|
|
|
|
Expect(resp.Status).To(Equal(responses.StatusOK))
|
|
Expect(resp.Song).ToNot(BeNil())
|
|
Expect(resp.Song.UserRating).To(Equal(int32(4)))
|
|
})
|
|
|
|
It("sets rating on an album", func() {
|
|
resp := doReq("setRating", "id", albumID, "rating", "3")
|
|
|
|
Expect(resp.Status).To(Equal(responses.StatusOK))
|
|
})
|
|
|
|
It("returns error for missing parameters", func() {
|
|
// Missing both id and rating
|
|
resp := doReq("setRating")
|
|
Expect(resp.Status).To(Equal(responses.StatusFailed))
|
|
|
|
// Missing rating
|
|
resp = doReq("setRating", "id", songID)
|
|
Expect(resp.Status).To(Equal(responses.StatusFailed))
|
|
})
|
|
})
|
|
|
|
Describe("Scrobble", func() {
|
|
It("submits a scrobble for a song", func() {
|
|
songs, err := ds.MediaFile(ctx).GetAll(model.QueryOptions{Max: 1, Sort: "title"})
|
|
Expect(err).ToNot(HaveOccurred())
|
|
Expect(songs).ToNot(BeEmpty())
|
|
|
|
resp := doReq("scrobble", "id", songs[0].ID, "submission", "true")
|
|
|
|
Expect(resp.Status).To(Equal(responses.StatusOK))
|
|
})
|
|
|
|
It("returns error when id is missing", func() {
|
|
resp := doReq("scrobble")
|
|
|
|
Expect(resp.Status).To(Equal(responses.StatusFailed))
|
|
Expect(resp.Error).ToNot(BeNil())
|
|
})
|
|
})
|
|
})
|