Started the implementation of getMusicDirectory. Probably will need to introduce a new 'service' layer...
This commit is contained in:
@@ -3,7 +3,6 @@ package api_test
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"encoding/xml"
|
||||
"github.com/deluan/gosonic/api/responses"
|
||||
"github.com/deluan/gosonic/consts"
|
||||
"github.com/deluan/gosonic/domain"
|
||||
@@ -39,17 +38,13 @@ func TestGetIndexes(t *testing.T) {
|
||||
mockRepo.SetError(true)
|
||||
_, w := Get(AddParams("/rest/getIndexes.view", "ifModifiedSince=0"), "TestGetIndexes")
|
||||
|
||||
v := responses.Subsonic{}
|
||||
xml.Unmarshal(w.Body.Bytes(), &v)
|
||||
So(v.Status, ShouldEqual, "fail")
|
||||
So(w.Body, ShouldReceiveError, responses.ERROR_GENERIC)
|
||||
})
|
||||
Convey("Return fail on Property Table error", func() {
|
||||
propRepo.SetError(true)
|
||||
_, w := Get(AddParams("/rest/getIndexes.view"), "TestGetIndexes")
|
||||
|
||||
v := responses.Subsonic{}
|
||||
xml.Unmarshal(w.Body.Bytes(), &v)
|
||||
So(v.Status, ShouldEqual, "fail")
|
||||
So(w.Body, ShouldReceiveError, responses.ERROR_GENERIC)
|
||||
})
|
||||
Convey("When the index is empty", func() {
|
||||
_, w := Get(AddParams("/rest/getIndexes.view"), "TestGetIndexes")
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"github.com/deluan/gosonic/api/responses"
|
||||
"github.com/deluan/gosonic/domain"
|
||||
"github.com/deluan/gosonic/utils"
|
||||
"github.com/karlkfi/inject"
|
||||
"github.com/astaxie/beego"
|
||||
)
|
||||
|
||||
type GetMusicDirectoryController struct {
|
||||
BaseAPIController
|
||||
artistRepo domain.ArtistRepository
|
||||
}
|
||||
|
||||
func (c *GetMusicDirectoryController) Prepare() {
|
||||
inject.ExtractAssignable(utils.Graph, &c.artistRepo)
|
||||
}
|
||||
|
||||
func (c *GetMusicDirectoryController) Get() {
|
||||
id := c.Input().Get("id")
|
||||
|
||||
if id == "" {
|
||||
c.SendError(responses.ERROR_MISSING_PARAMETER, "id parameter required")
|
||||
}
|
||||
|
||||
found, err := c.artistRepo.Exists(id)
|
||||
if err != nil {
|
||||
beego.Error("Error searching for Artist:", err)
|
||||
c.SendError(responses.ERROR_GENERIC, "Internal Error")
|
||||
}
|
||||
|
||||
if found {
|
||||
_, err := c.artistRepo.Get(id)
|
||||
if err != nil {
|
||||
beego.Error("Error reading Artist from DB", err)
|
||||
c.SendError(responses.ERROR_GENERIC, "Internal Error")
|
||||
}
|
||||
}
|
||||
|
||||
response := c.NewEmpty()
|
||||
response.Directory = &responses.Directory{}
|
||||
c.SendResponse(response)
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package api_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/deluan/gosonic/domain"
|
||||
"github.com/deluan/gosonic/tests/mocks"
|
||||
"github.com/deluan/gosonic/utils"
|
||||
. "github.com/deluan/gosonic/tests"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
"github.com/deluan/gosonic/api/responses"
|
||||
)
|
||||
|
||||
func TestGetMusicDirectory(t *testing.T) {
|
||||
Init(t, false)
|
||||
|
||||
mockRepo := mocks.CreateMockArtistRepo()
|
||||
utils.DefineSingleton(new(domain.ArtistRepository), func() domain.ArtistRepository {
|
||||
return mockRepo
|
||||
})
|
||||
|
||||
mockRepo.SetData("[]")
|
||||
mockRepo.SetError(false)
|
||||
|
||||
Convey("Subject: GetMusicDirectory Endpoint", t, func() {
|
||||
Convey("Should fail if missing Id parameter", func() {
|
||||
_, w := Get(AddParams("/rest/getMusicDirectory.view"), "TestGetMusicDirectory")
|
||||
|
||||
So(w.Body, ShouldReceiveError, responses.ERROR_MISSING_PARAMETER)
|
||||
})
|
||||
Convey("Id is for an artist", func() {
|
||||
Convey("Return fail on Artist Table error", func() {
|
||||
mockRepo.SetError(true)
|
||||
_, w := Get(AddParams("/rest/getMusicDirectory.view", "id=1"), "TestGetMusicDirectory")
|
||||
|
||||
So(w.Body, ShouldReceiveError, responses.ERROR_GENERIC)
|
||||
})
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -6,7 +6,7 @@ type Subsonic struct {
|
||||
XMLName xml.Name `xml:"http://subsonic.org/restapi subsonic-response" json:"-"`
|
||||
Status string `xml:"status,attr" json:"status"`
|
||||
Version string `xml:"version,attr" json:"version"`
|
||||
Error *Error `xml:",omitempty" json:"error,omitempty"`
|
||||
Error *Error `xml:"error,omitempty" json:"error,omitempty"`
|
||||
License *License `xml:"license,omitempty" json:"license,omitempty"`
|
||||
MusicFolders *MusicFolders `xml:"musicFolders,omitempty" json:"musicFolders,omitempty"`
|
||||
Indexes *Indexes `xml:"indexes,omitempty" json:"indexes,omitempty"`
|
||||
@@ -18,8 +18,8 @@ type JsonWrapper struct {
|
||||
}
|
||||
|
||||
type Error struct {
|
||||
Code int `xml:"code,attr"`
|
||||
Message string `xml:"message,attr"`
|
||||
Code int `xml:"code,attr" json:"code"`
|
||||
Message string `xml:"message,attr" json:"message"`
|
||||
}
|
||||
|
||||
type License struct {
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
package responses
|
||||
package responses_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
. "github.com/smartystreets/goconvey/convey"
|
||||
. "github.com/deluan/gosonic/tests"
|
||||
. "github.com/deluan/gosonic/api/responses"
|
||||
)
|
||||
|
||||
func TestSubsonicResponses(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user