navidrome/server/subsonic/album_lists_test.go

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

92 lines
2.4 KiB
Go
Raw Normal View History

package subsonic
2020-01-10 04:39:42 +01:00
import (
2020-01-22 05:01:43 +01:00
"context"
2020-01-10 04:39:42 +01:00
"net/http/httptest"
"github.com/navidrome/navidrome/log"
"github.com/navidrome/navidrome/model"
2020-10-27 16:01:40 +01:00
"github.com/navidrome/navidrome/tests"
2020-01-10 04:39:42 +01:00
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("AlbumListController", func() {
var controller *AlbumListController
var ds model.DataStore
2021-06-08 22:30:19 +02:00
var mockRepo *tests.MockAlbumRepo
2020-01-10 04:39:42 +01:00
var w *httptest.ResponseRecorder
ctx := log.NewContext(context.TODO())
2020-01-10 04:39:42 +01:00
BeforeEach(func() {
2020-10-27 16:01:40 +01:00
ds = &tests.MockDataStore{}
2021-06-08 22:30:19 +02:00
mockRepo = ds.Album(ctx).(*tests.MockAlbumRepo)
controller = NewAlbumListController(ds, nil)
2020-01-10 04:39:42 +01:00
w = httptest.NewRecorder()
})
Describe("GetAlbumList", func() {
It("should return list of the type specified", func() {
r := newGetRequest("type=newest", "offset=10", "size=20")
2020-10-27 15:48:37 +01:00
mockRepo.SetData(model.Albums{
{ID: "1"}, {ID: "2"},
})
2020-01-10 04:39:42 +01: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"))
Expect(mockRepo.Options.Offset).To(Equal(10))
Expect(mockRepo.Options.Max).To(Equal(20))
2020-01-10 04:39:42 +01:00
})
It("should fail if missing type parameter", func() {
r := newGetRequest()
2020-01-10 04:39:42 +01:00
_, err := controller.GetAlbumList(w, r)
2020-10-27 20:23:29 +01:00
Expect(err).To(MatchError("required 'type' parameter is missing"))
2020-01-10 04:39:42 +01:00
})
It("should return error if call fails", func() {
mockRepo.SetError(true)
r := newGetRequest("type=newest")
2020-01-10 04:39:42 +01:00
_, err := controller.GetAlbumList(w, r)
Expect(err).ToNot(BeNil())
2020-01-10 04:39:42 +01:00
})
})
Describe("GetAlbumList2", func() {
It("should return list of the type specified", func() {
r := newGetRequest("type=newest", "offset=10", "size=20")
2020-10-27 15:48:37 +01:00
mockRepo.SetData(model.Albums{
{ID: "1"}, {ID: "2"},
})
2020-01-10 04:39:42 +01: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"))
Expect(mockRepo.Options.Offset).To(Equal(10))
Expect(mockRepo.Options.Max).To(Equal(20))
2020-01-10 04:39:42 +01:00
})
It("should fail if missing type parameter", func() {
r := newGetRequest()
2020-01-10 04:39:42 +01:00
_, err := controller.GetAlbumList2(w, r)
2020-10-27 20:23:29 +01:00
Expect(err).To(MatchError("required 'type' parameter is missing"))
2020-01-10 04:39:42 +01:00
})
It("should return error if call fails", func() {
mockRepo.SetError(true)
r := newGetRequest("type=newest")
2020-01-10 04:39:42 +01:00
_, err := controller.GetAlbumList2(w, r)
Expect(err).ToNot(BeNil())
2020-01-10 04:39:42 +01:00
})
})
})