2019-07-17 16:46:54 +02:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetAlbums(t *testing.T) {
|
|
|
|
t.Run("successful request", func(t *testing.T) {
|
|
|
|
app, router, ctx := NewApiTest()
|
|
|
|
GetAlbums(router, ctx)
|
|
|
|
result := PerformRequest(app, "GET", "/api/v1/albums?count=10")
|
|
|
|
|
|
|
|
assert.Equal(t, http.StatusOK, result.Code)
|
|
|
|
})
|
|
|
|
t.Run("invalid request", func(t *testing.T) {
|
|
|
|
app, router, ctx := NewApiTest()
|
|
|
|
GetAlbums(router, ctx)
|
|
|
|
result := PerformRequest(app, "GET", "/api/v1/albums?xxx=10")
|
|
|
|
t.Log(result.Body)
|
|
|
|
|
|
|
|
assert.Equal(t, http.StatusBadRequest, result.Code)
|
|
|
|
})
|
|
|
|
t.Run("invalid request", func(t *testing.T) {
|
|
|
|
app, router, ctx := NewApiTest()
|
|
|
|
t.Log(router)
|
|
|
|
t.Log(ctx)
|
|
|
|
result := PerformRequest(app, "GET", "/api/v1/albums?xxx=10")
|
|
|
|
t.Log(result.Body)
|
|
|
|
|
|
|
|
assert.Equal(t, http.StatusNotFound, result.Code)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLikeAlbum(t *testing.T) {
|
|
|
|
t.Run("like not existing album", func(t *testing.T) {
|
|
|
|
app, router, ctx := NewApiTest()
|
|
|
|
|
|
|
|
LikeAlbum(router, ctx)
|
|
|
|
|
|
|
|
result := PerformRequest(app, "POST", "/api/v1/albums/98789876/like")
|
|
|
|
assert.Equal(t, http.StatusNotFound, result.Code)
|
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDislikeAlbum(t *testing.T) {
|
|
|
|
t.Run("dislike not existing album", func(t *testing.T) {
|
|
|
|
app, router, ctx := NewApiTest()
|
|
|
|
|
|
|
|
LikeAlbum(router, ctx)
|
|
|
|
|
2019-07-17 17:16:33 +02:00
|
|
|
result := PerformRequest(app, "DELETE", "/api/v1/albums/5678/like")
|
2019-07-17 16:46:54 +02:00
|
|
|
t.Log(result.Body)
|
|
|
|
assert.Equal(t, http.StatusNotFound, result.Code)
|
|
|
|
})
|
|
|
|
}
|