photoprism/internal/api/photo_label_test.go

33 lines
1,007 B
Go
Raw Normal View History

2020-02-03 15:49:32 +01:00
package api
import (
"net/http"
"testing"
"github.com/stretchr/testify/assert"
"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)
val := gjson.Get(result.Body.String(), "Labels.#(LabelID==1).Uncertainty")
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")
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)
})
}