2020-01-19 14:21:44 -09:00
|
|
|
package subsonic
|
2020-01-09 18:39:42 -09:00
|
|
|
|
|
|
|
|
import (
|
2020-01-21 19:01:43 -09:00
|
|
|
"context"
|
2020-01-09 18:39:42 -09:00
|
|
|
"net/http/httptest"
|
|
|
|
|
|
2021-11-02 17:38:08 -08:00
|
|
|
"github.com/navidrome/navidrome/server/subsonic/responses"
|
|
|
|
|
|
2020-10-27 06:03:10 -08:00
|
|
|
"github.com/navidrome/navidrome/log"
|
|
|
|
|
"github.com/navidrome/navidrome/model"
|
2020-10-27 07:01:40 -08:00
|
|
|
"github.com/navidrome/navidrome/tests"
|
2022-07-26 12:47:16 -08:00
|
|
|
. "github.com/onsi/ginkgo/v2"
|
2020-01-09 18:39:42 -09:00
|
|
|
. "github.com/onsi/gomega"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var _ = Describe("AlbumListController", func() {
|
|
|
|
|
var controller *AlbumListController
|
2020-10-27 06:03:10 -08:00
|
|
|
var ds model.DataStore
|
2021-06-08 12:30:19 -08:00
|
|
|
var mockRepo *tests.MockAlbumRepo
|
2020-01-09 18:39:42 -09:00
|
|
|
var w *httptest.ResponseRecorder
|
2020-10-27 06:03:10 -08:00
|
|
|
ctx := log.NewContext(context.TODO())
|
2020-01-09 18:39:42 -09:00
|
|
|
|
|
|
|
|
BeforeEach(func() {
|
2020-10-27 07:01:40 -08:00
|
|
|
ds = &tests.MockDataStore{}
|
2021-06-08 12:30:19 -08:00
|
|
|
mockRepo = ds.Album(ctx).(*tests.MockAlbumRepo)
|
2020-10-27 06:03:10 -08:00
|
|
|
controller = NewAlbumListController(ds, nil)
|
2020-01-09 18:39:42 -09:00
|
|
|
w = httptest.NewRecorder()
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
Describe("GetAlbumList", func() {
|
|
|
|
|
It("should return list of the type specified", func() {
|
2020-01-27 11:10:46 -09:00
|
|
|
r := newGetRequest("type=newest", "offset=10", "size=20")
|
2020-10-27 06:48:37 -08:00
|
|
|
mockRepo.SetData(model.Albums{
|
|
|
|
|
{ID: "1"}, {ID: "2"},
|
|
|
|
|
})
|
2020-01-09 18:39:42 -09:00
|
|
|
resp, err := controller.GetAlbumList(w, r)
|
|
|
|
|
|
|
|
|
|
Expect(err).To(BeNil())
|
|
|
|
|
Expect(resp.AlbumList.Album[0].Id).To(Equal("1"))
|
|
|
|
|
Expect(resp.AlbumList.Album[1].Id).To(Equal("2"))
|
2021-09-21 16:40:39 -08:00
|
|
|
Expect(w.Header().Get("x-total-count")).To(Equal("2"))
|
2020-10-27 06:03:10 -08:00
|
|
|
Expect(mockRepo.Options.Offset).To(Equal(10))
|
|
|
|
|
Expect(mockRepo.Options.Max).To(Equal(20))
|
2020-01-09 18:39:42 -09:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
It("should fail if missing type parameter", func() {
|
2020-01-27 11:10:46 -09:00
|
|
|
r := newGetRequest()
|
2020-01-09 18:39:42 -09:00
|
|
|
_, err := controller.GetAlbumList(w, r)
|
|
|
|
|
|
2020-10-27 11:23:29 -08:00
|
|
|
Expect(err).To(MatchError("required 'type' parameter is missing"))
|
2021-11-02 17:38:08 -08:00
|
|
|
Expect(err.(subError).code).To(Equal(responses.ErrorMissingParameter))
|
2020-01-09 18:39:42 -09:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
It("should return error if call fails", func() {
|
2020-10-27 06:03:10 -08:00
|
|
|
mockRepo.SetError(true)
|
2020-01-27 11:10:46 -09:00
|
|
|
r := newGetRequest("type=newest")
|
2020-01-09 18:39:42 -09:00
|
|
|
|
|
|
|
|
_, err := controller.GetAlbumList(w, r)
|
|
|
|
|
|
2020-10-27 06:03:10 -08:00
|
|
|
Expect(err).ToNot(BeNil())
|
2021-11-02 17:38:08 -08:00
|
|
|
Expect(err.(subError).code).To(Equal(responses.ErrorGeneric))
|
2020-01-09 18:39:42 -09:00
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
Describe("GetAlbumList2", func() {
|
|
|
|
|
It("should return list of the type specified", func() {
|
2020-01-27 11:10:46 -09:00
|
|
|
r := newGetRequest("type=newest", "offset=10", "size=20")
|
2020-10-27 06:48:37 -08:00
|
|
|
mockRepo.SetData(model.Albums{
|
|
|
|
|
{ID: "1"}, {ID: "2"},
|
|
|
|
|
})
|
2020-01-09 18:39:42 -09:00
|
|
|
resp, err := controller.GetAlbumList2(w, r)
|
|
|
|
|
|
|
|
|
|
Expect(err).To(BeNil())
|
|
|
|
|
Expect(resp.AlbumList2.Album[0].Id).To(Equal("1"))
|
|
|
|
|
Expect(resp.AlbumList2.Album[1].Id).To(Equal("2"))
|
2021-09-21 16:40:39 -08:00
|
|
|
Expect(w.Header().Get("x-total-count")).To(Equal("2"))
|
2020-10-27 06:03:10 -08:00
|
|
|
Expect(mockRepo.Options.Offset).To(Equal(10))
|
|
|
|
|
Expect(mockRepo.Options.Max).To(Equal(20))
|
2020-01-09 18:39:42 -09:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
It("should fail if missing type parameter", func() {
|
2020-01-27 11:10:46 -09:00
|
|
|
r := newGetRequest()
|
2020-01-09 18:39:42 -09:00
|
|
|
_, err := controller.GetAlbumList2(w, r)
|
|
|
|
|
|
2020-10-27 11:23:29 -08:00
|
|
|
Expect(err).To(MatchError("required 'type' parameter is missing"))
|
2021-11-02 17:38:08 -08:00
|
|
|
Expect(err.(subError).code).To(Equal(responses.ErrorMissingParameter))
|
2020-01-09 18:39:42 -09:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
It("should return error if call fails", func() {
|
2020-10-27 06:03:10 -08:00
|
|
|
mockRepo.SetError(true)
|
2020-01-27 11:10:46 -09:00
|
|
|
r := newGetRequest("type=newest")
|
2020-01-09 18:39:42 -09:00
|
|
|
|
|
|
|
|
_, err := controller.GetAlbumList2(w, r)
|
|
|
|
|
|
2020-10-27 06:03:10 -08:00
|
|
|
Expect(err).ToNot(BeNil())
|
2021-11-02 17:38:08 -08:00
|
|
|
Expect(err.(subError).code).To(Equal(responses.ErrorGeneric))
|
2020-01-09 18:39:42 -09:00
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
})
|