Restore AlbumListController tests
This commit is contained in:
+103
-68
@@ -1,68 +1,103 @@
|
|||||||
package api_test
|
package api
|
||||||
//
|
|
||||||
//import (
|
import (
|
||||||
// "testing"
|
"errors"
|
||||||
//
|
"net/http/httptest"
|
||||||
// "github.com/cloudsonic/sonic-server/api/responses"
|
|
||||||
// "github.com/cloudsonic/sonic-server/domain"
|
"github.com/cloudsonic/sonic-server/engine"
|
||||||
// "github.com/cloudsonic/sonic-server/engine"
|
. "github.com/onsi/ginkgo"
|
||||||
// "github.com/cloudsonic/sonic-server/persistence"
|
. "github.com/onsi/gomega"
|
||||||
// . "github.com/cloudsonic/sonic-server/tests"
|
)
|
||||||
// "github.com/cloudsonic/sonic-server/utils"
|
|
||||||
// . "github.com/smartystreets/goconvey/convey"
|
type fakeListGen struct {
|
||||||
//)
|
engine.ListGenerator
|
||||||
//
|
data engine.Entries
|
||||||
//func TestGetAlbumList(t *testing.T) {
|
err error
|
||||||
// Init(t, false)
|
recvOffset int
|
||||||
//
|
recvSize int
|
||||||
// mockAlbumRepo := persistence.CreateMockAlbumRepo()
|
}
|
||||||
// utils.DefineSingleton(new(domain.AlbumRepository), func() domain.AlbumRepository {
|
|
||||||
// return mockAlbumRepo
|
func (lg *fakeListGen) GetNewest(offset int, size int) (engine.Entries, error) {
|
||||||
// })
|
if lg.err != nil {
|
||||||
//
|
return nil, lg.err
|
||||||
// mockNowPlayingRepo := engine.CreateMockNowPlayingRepo()
|
}
|
||||||
// utils.DefineSingleton(new(engine.NowPlayingRepository), func() engine.NowPlayingRepository {
|
lg.recvOffset = offset
|
||||||
// return mockNowPlayingRepo
|
lg.recvSize = size
|
||||||
// })
|
return lg.data, nil
|
||||||
//
|
}
|
||||||
// Convey("Subject: GetAlbumList Endpoint", t, func() {
|
|
||||||
// mockAlbumRepo.SetData(`[
|
var _ = Describe("AlbumListController", func() {
|
||||||
// {"Id":"A","Name":"Vagarosa","ArtistId":"2"},
|
var controller *AlbumListController
|
||||||
// {"Id":"C","Name":"Liberation: The Island Anthology","ArtistId":"3"},
|
var listGen *fakeListGen
|
||||||
// {"Id":"B","Name":"Planet Rock","ArtistId":"1"}]`, 1)
|
var w *httptest.ResponseRecorder
|
||||||
//
|
|
||||||
// Convey("Should fail if missing 'type' parameter", func() {
|
BeforeEach(func() {
|
||||||
// _, w := Get(AddParams("/rest/getAlbumList.view"), "TestGetAlbumList")
|
listGen = &fakeListGen{}
|
||||||
//
|
controller = NewAlbumListController(listGen)
|
||||||
// So(w.Body, ShouldReceiveError, responses.ErrorMissingParameter)
|
w = httptest.NewRecorder()
|
||||||
// })
|
})
|
||||||
// Convey("Return fail on Album Table error", func() {
|
|
||||||
// mockAlbumRepo.SetError(true)
|
Describe("GetAlbumList", func() {
|
||||||
// _, w := Get(AddParams("/rest/getAlbumList.view", "type=newest"), "TestGetAlbumList")
|
It("should return list of the type specified", func() {
|
||||||
//
|
r := newTestRequest("type=newest", "offset=10", "size=20")
|
||||||
// So(w.Body, ShouldReceiveError, responses.ErrorGeneric)
|
listGen.data = engine.Entries{
|
||||||
// })
|
{Id: "1"}, {Id: "2"},
|
||||||
// Convey("Type is invalid", func() {
|
}
|
||||||
// _, w := Get(AddParams("/rest/getAlbumList.view", "type=not_implemented"), "TestGetAlbumList")
|
resp, err := controller.GetAlbumList(w, r)
|
||||||
//
|
|
||||||
// So(w.Body, ShouldReceiveError, responses.ErrorGeneric)
|
Expect(err).To(BeNil())
|
||||||
// })
|
Expect(resp.AlbumList.Album[0].Id).To(Equal("1"))
|
||||||
// Convey("Max size = 500", func() {
|
Expect(resp.AlbumList.Album[1].Id).To(Equal("2"))
|
||||||
// _, w := Get(AddParams("/rest/getAlbumList.view", "type=newest", "size=501"), "TestGetAlbumList")
|
Expect(listGen.recvOffset).To(Equal(10))
|
||||||
// So(w.Body, ShouldBeAValid, responses.AlbumList{})
|
Expect(listGen.recvSize).To(Equal(20))
|
||||||
// So(mockAlbumRepo.Options.Size, ShouldEqual, 500)
|
})
|
||||||
// So(mockAlbumRepo.Options.Alpha, ShouldBeTrue)
|
|
||||||
// })
|
It("should fail if missing type parameter", func() {
|
||||||
// Convey("Type == newest", func() {
|
r := newTestRequest()
|
||||||
// _, w := Get(AddParams("/rest/getAlbumList.view", "type=newest"), "TestGetAlbumList")
|
_, err := controller.GetAlbumList(w, r)
|
||||||
// So(w.Body, ShouldBeAValid, responses.AlbumList{})
|
|
||||||
// So(mockAlbumRepo.Options.SortBy, ShouldEqual, "CreatedAt")
|
Expect(err).To(MatchError("Required string parameter 'type' is not present"))
|
||||||
// So(mockAlbumRepo.Options.Desc, ShouldBeTrue)
|
})
|
||||||
// So(mockAlbumRepo.Options.Alpha, ShouldBeTrue)
|
|
||||||
// })
|
It("should return error if call fails", func() {
|
||||||
// Reset(func() {
|
listGen.err = errors.New("some issue")
|
||||||
// mockAlbumRepo.SetData("[]", 0)
|
r := newTestRequest("type=newest")
|
||||||
// mockAlbumRepo.SetError(false)
|
|
||||||
// })
|
_, err := controller.GetAlbumList(w, r)
|
||||||
// })
|
|
||||||
//}
|
Expect(err).To(MatchError("Internal Error"))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
Describe("GetAlbumList2", func() {
|
||||||
|
It("should return list of the type specified", func() {
|
||||||
|
r := newTestRequest("type=newest", "offset=10", "size=20")
|
||||||
|
listGen.data = engine.Entries{
|
||||||
|
{Id: "1"}, {Id: "2"},
|
||||||
|
}
|
||||||
|
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(listGen.recvOffset).To(Equal(10))
|
||||||
|
Expect(listGen.recvSize).To(Equal(20))
|
||||||
|
})
|
||||||
|
|
||||||
|
It("should fail if missing type parameter", func() {
|
||||||
|
r := newTestRequest()
|
||||||
|
_, err := controller.GetAlbumList2(w, r)
|
||||||
|
|
||||||
|
Expect(err).To(MatchError("Required string parameter 'type' is not present"))
|
||||||
|
})
|
||||||
|
|
||||||
|
It("should return error if call fails", func() {
|
||||||
|
listGen.err = errors.New("some issue")
|
||||||
|
r := newTestRequest("type=newest")
|
||||||
|
|
||||||
|
_, err := controller.GetAlbumList2(w, r)
|
||||||
|
|
||||||
|
Expect(err).To(MatchError("Internal Error"))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|||||||
Reference in New Issue
Block a user