photoprism/internal/api/photo_label_test.go

33 lines
1 KiB
Go
Raw Normal View History

2020-02-03 14:49:32 +00:00
package api
import (
"net/http"
"testing"
"github.com/stretchr/testify/assert"
"github.com/tidwall/gjson"
2020-02-03 14:49:32 +00:00
)
func TestRemovePhotoLabel(t *testing.T) {
t.Run("photo with label", func(t *testing.T) {
app, router, ctx := NewApiTest()
RemovePhotoLabel(router, ctx)
2020-05-01 12:15:15 +00:00
result := PerformRequest(app, "DELETE", "/api/v1/photos/pt9jtdre2lvl0yh7/label/1000001")
2020-02-03 14:49:32 +00:00
assert.Equal(t, http.StatusOK, result.Code)
2020-05-01 12:15:15 +00:00
val := gjson.Get(result.Body.String(), "Labels.#(LabelID==1000001).Uncertainty")
assert.Equal(t, "100", val.String())
2020-02-03 14:49:32 +00:00
})
t.Run("try to remove wrong label", func(t *testing.T) {
app, router, ctx := NewApiTest()
RemovePhotoLabel(router, ctx)
2020-05-01 12:15:15 +00:00
result := PerformRequest(app, "DELETE", "/api/v1/photos/pt9jtdre2lvl0yh7/label/1000000")
assert.Equal(t, http.StatusNotFound, result.Code)
2020-02-03 14:49:32 +00: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)
})
}