2020-02-03 15:49:32 +01:00
|
|
|
package api
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2020-04-17 21:20:38 +02:00
|
|
|
"github.com/tidwall/gjson"
|
2020-02-03 15:49:32 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestRemovePhotoLabel(t *testing.T) {
|
|
|
|
t.Run("photo with label", func(t *testing.T) {
|
|
|
|
app, router, ctx := NewApiTest()
|
|
|
|
RemovePhotoLabel(router, ctx)
|
|
|
|
result := PerformRequest(app, "DELETE", "/api/v1/photos/654/label/1")
|
|
|
|
assert.Equal(t, http.StatusOK, result.Code)
|
2020-04-19 01:13:55 +02:00
|
|
|
val := gjson.Get(result.Body.String(), "Labels.#(LabelID==1).Uncertainty")
|
2020-04-17 21:20:38 +02:00
|
|
|
assert.Equal(t, "100", val.String())
|
2020-02-03 15:49:32 +01:00
|
|
|
})
|
|
|
|
t.Run("try to remove wrong label", func(t *testing.T) {
|
|
|
|
app, router, ctx := NewApiTest()
|
|
|
|
RemovePhotoLabel(router, ctx)
|
|
|
|
result := PerformRequest(app, "DELETE", "/api/v1/photos/654/label/3")
|
2020-04-17 21:20:38 +02:00
|
|
|
assert.Equal(t, http.StatusNotFound, result.Code)
|
2020-02-03 15:49:32 +01:00
|
|
|
})
|
|
|
|
t.Run("not existing photo", func(t *testing.T) {
|
|
|
|
app, router, ctx := NewApiTest()
|
|
|
|
RemovePhotoLabel(router, ctx)
|
|
|
|
result := PerformRequest(app, "DELETE", "/api/v1/photos/xx/label/")
|
|
|
|
assert.Equal(t, http.StatusNotFound, result.Code)
|
|
|
|
})
|
|
|
|
}
|