2019-07-17 17:16:33 +02:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
2019-12-11 14:10:20 +01:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2019-07-17 17:16:33 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestGetLabels(t *testing.T) {
|
|
|
|
t.Run("successful request", func(t *testing.T) {
|
|
|
|
app, router, ctx := NewApiTest()
|
|
|
|
GetLabels(router, ctx)
|
|
|
|
result := PerformRequest(app, "GET", "/api/v1/labels?count=15")
|
|
|
|
t.Log(result.Body)
|
|
|
|
assert.Equal(t, http.StatusOK, result.Code)
|
|
|
|
})
|
|
|
|
t.Run("invalid request", func(t *testing.T) {
|
|
|
|
app, router, ctx := NewApiTest()
|
|
|
|
GetLabels(router, ctx)
|
|
|
|
result := PerformRequest(app, "GET", "/api/v1/labels?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/labels?xxx=10")
|
|
|
|
t.Log(result.Body)
|
|
|
|
|
|
|
|
assert.Equal(t, http.StatusNotFound, result.Code)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestLikeLabel(t *testing.T) {
|
2020-02-02 19:39:49 +01:00
|
|
|
t.Run("like not existing label", func(t *testing.T) {
|
2019-07-17 17:16:33 +02:00
|
|
|
app, router, ctx := NewApiTest()
|
|
|
|
|
|
|
|
LikeLabel(router, ctx)
|
|
|
|
|
2020-02-02 19:39:49 +01:00
|
|
|
result := PerformRequest(app, "POST", "/api/v1/labels/8775789/like")
|
|
|
|
assert.Equal(t, http.StatusNotFound, result.Code)
|
|
|
|
})
|
|
|
|
t.Run("like existing label", func(t *testing.T) {
|
|
|
|
app, router, ctx := NewApiTest()
|
|
|
|
|
|
|
|
LikeLabel(router, ctx)
|
|
|
|
|
|
|
|
result := PerformRequest(app, "POST", "/api/v1/labels/12/like")
|
|
|
|
assert.Equal(t, http.StatusOK, result.Code)
|
2019-07-17 17:16:33 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestDislikeLabel(t *testing.T) {
|
2020-02-02 19:39:49 +01:00
|
|
|
t.Run("dislike not existing label", func(t *testing.T) {
|
2019-07-17 17:16:33 +02:00
|
|
|
app, router, ctx := NewApiTest()
|
|
|
|
|
2020-02-02 19:39:49 +01:00
|
|
|
DislikeLabel(router, ctx)
|
2019-07-17 17:16:33 +02:00
|
|
|
|
|
|
|
result := PerformRequest(app, "DELETE", "/api/v1/labels/5678/like")
|
|
|
|
assert.Equal(t, http.StatusNotFound, result.Code)
|
|
|
|
})
|
2020-02-02 19:39:49 +01:00
|
|
|
t.Run("dislike existing label", func(t *testing.T) {
|
|
|
|
app, router, ctx := NewApiTest()
|
|
|
|
|
|
|
|
DislikeLabel(router, ctx)
|
|
|
|
|
|
|
|
result := PerformRequest(app, "DELETE", "/api/v1/labels/13/like")
|
|
|
|
assert.Equal(t, http.StatusOK, result.Code)
|
|
|
|
})
|
2019-07-17 17:16:33 +02:00
|
|
|
}
|
2019-12-16 11:04:49 +01:00
|
|
|
|
|
|
|
func TestLabelThumbnail(t *testing.T) {
|
|
|
|
t.Run("invalid type", func(t *testing.T) {
|
|
|
|
app, router, ctx := NewApiTest()
|
|
|
|
LabelThumbnail(router, ctx)
|
|
|
|
result := PerformRequest(app, "GET", "/api/v1/labels/dog/thumbnail/xxx")
|
|
|
|
|
2019-12-17 04:39:23 +01:00
|
|
|
assert.Equal(t, http.StatusOK, result.Code)
|
2019-12-16 11:04:49 +01:00
|
|
|
})
|
|
|
|
t.Run("invalid label", func(t *testing.T) {
|
|
|
|
app, router, ctx := NewApiTest()
|
|
|
|
LabelThumbnail(router, ctx)
|
|
|
|
result := PerformRequest(app, "GET", "/api/v1/labels/xxx/thumbnail/tile_500")
|
|
|
|
|
2019-12-17 04:39:23 +01:00
|
|
|
assert.Equal(t, http.StatusOK, result.Code)
|
2019-12-16 11:04:49 +01:00
|
|
|
})
|
2020-02-02 19:39:49 +01:00
|
|
|
t.Run("could not find original", func(t *testing.T) {
|
|
|
|
app, router, ctx := NewApiTest()
|
|
|
|
LabelThumbnail(router, ctx)
|
|
|
|
result := PerformRequest(app, "GET", "/api/v1/labels/12/thumbnail/tile_500")
|
|
|
|
assert.Equal(t, http.StatusOK, result.Code)
|
|
|
|
})
|
2019-12-16 11:04:49 +01:00
|
|
|
}
|