Added size parameter to getCoverArt.view endpoint

This commit is contained in:
Deluan
2016-03-08 23:31:48 -05:00
parent 00b4c44010
commit 371d0ea711
5 changed files with 53 additions and 16 deletions
+2 -2
View File
@@ -17,11 +17,11 @@ func (c *GetCoverArtController) Prepare() {
inject.ExtractAssignable(utils.Graph, &c.cover)
}
// TODO accept size parameter
func (c *GetCoverArtController) Get() {
id := c.RequiredParamString("id", "id parameter required")
size := c.ParamInt("size")
err := c.cover.GetCover(id, 0, c.Ctx.ResponseWriter)
err := c.cover.Get(id, size, c.Ctx.ResponseWriter)
switch {
case err == engine.DataNotFound:
+12 -4
View File
@@ -3,16 +3,17 @@ package api_test
import (
"testing"
"fmt"
"net/http"
"net/http/httptest"
"github.com/astaxie/beego"
"github.com/deluan/gosonic/api/responses"
"github.com/deluan/gosonic/domain"
. "github.com/deluan/gosonic/tests"
"github.com/deluan/gosonic/tests/mocks"
"github.com/deluan/gosonic/utils"
. "github.com/smartystreets/goconvey/convey"
"net/http"
"net/http/httptest"
"github.com/astaxie/beego"
"fmt"
)
func getCoverArt(params ...string) (*http.Request, *httptest.ResponseRecorder) {
@@ -52,6 +53,13 @@ func TestGetCoverArt(t *testing.T) {
So(w.Body.Bytes(), ShouldMatchMD5, "e859a71cd1b1aaeb1ad437d85b306668")
So(w.Header().Get("Content-Type"), ShouldEqual, "image/jpeg")
})
Convey("When specifying a size", func() {
mockMediaFileRepo.SetData(`[{"Id":"2","HasCoverArt":true,"Path":"tests/fixtures/01 Invisible (RED) Edit Version.mp3"}]`, 1)
_, w := getCoverArt("id=2", "size=100")
So(w.Body.Bytes(), ShouldMatchMD5, "04378f523ca3e8ead33bf7140d39799e")
So(w.Header().Get("Content-Type"), ShouldEqual, "image/jpeg")
})
Reset(func() {
mockMediaFileRepo.SetData("[]", 0)
mockMediaFileRepo.SetError(false)