mirror of
https://github.com/photoprism/photoprism.git
synced 2026-07-17 16:49:04 +00:00
Mirror the lens make/model editing surface for cameras: entity UpdateMakeModel/SaveForm, form validation, query, search, the GET/PUT /api/v1/cameras endpoints, and the cameras CLI command, plus a cameras ACL resource and scope. Also tidy the lens surface for parity: self-validating SaveForm, empty make/model guard, X-Count search header, service-role grant, the empty-id/slug docs, and order cameras before lenses everywhere.
55 lines
1.9 KiB
Go
55 lines
1.9 KiB
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/tidwall/gjson"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/photoprism/photoprism/internal/entity"
|
|
)
|
|
|
|
func TestUpdateCamera(t *testing.T) {
|
|
t.Run("Success", func(t *testing.T) {
|
|
defer func() {
|
|
entity.FlushCameraCache()
|
|
assert.NoError(t, entity.UnscopedDb().Save(entity.CameraFixtures.Pointer("canon-eos-7d")).Error)
|
|
}()
|
|
app, router, _ := NewApiTest()
|
|
UpdateCamera(router)
|
|
r := PerformRequestWithBody(app, "PUT", "/api/v1/cameras/1000002", `{"Make": "Pentax", "Model": "K-1"}`)
|
|
val := gjson.Get(r.Body.String(), "Name")
|
|
assert.Equal(t, "PENTAX K-1", val.String())
|
|
val2 := gjson.Get(r.Body.String(), "Model")
|
|
assert.Equal(t, "K-1", val2.String())
|
|
val3 := gjson.Get(r.Body.String(), "Make")
|
|
assert.Equal(t, "PENTAX", val3.String())
|
|
assert.Equal(t, http.StatusOK, r.Code)
|
|
})
|
|
t.Run("InvalidRequest", func(t *testing.T) {
|
|
app, router, _ := NewApiTest()
|
|
UpdateCamera(router)
|
|
r := PerformRequestWithBody(app, "PUT", "/api/v1/cameras/1000002", `{"Make": 123, "Model": ""}`)
|
|
val := gjson.Get(r.Body.String(), "error")
|
|
assert.Equal(t, "Unable to do that", val.String())
|
|
assert.Equal(t, http.StatusBadRequest, r.Code)
|
|
})
|
|
t.Run("BadModel", func(t *testing.T) {
|
|
app, router, _ := NewApiTest()
|
|
UpdateCamera(router)
|
|
r := PerformRequestWithBody(app, "PUT", "/api/v1/cameras/1000002", `{"Make": "123", "Model": ""}`)
|
|
val := gjson.Get(r.Body.String(), "error")
|
|
assert.Equal(t, "Invalid name", val.String())
|
|
assert.Equal(t, http.StatusBadRequest, r.Code)
|
|
})
|
|
t.Run("NotFound", func(t *testing.T) {
|
|
app, router, _ := NewApiTest()
|
|
UpdateCamera(router)
|
|
r := PerformRequestWithBody(app, "PUT", "/api/v1/cameras/199000002", `{"Make": "Pentax", "Model": "K-1"}`)
|
|
val := gjson.Get(r.Body.String(), "error")
|
|
assert.Equal(t, "Camera not found", val.String())
|
|
assert.Equal(t, http.StatusNotFound, r.Code)
|
|
})
|
|
}
|