People: Add unit tests #22

This commit is contained in:
theresa 2021-08-31 14:59:53 +02:00
parent 408ee3402d
commit 6b10ae5511
2 changed files with 151 additions and 1 deletions

View file

@ -59,6 +59,147 @@ func TestUpdateMarker(t *testing.T) {
assert.Equal(t, http.StatusOK, r.Code)
})
t.Run("bad request non- primary file", func(t *testing.T) {
app, router, _ := NewApiTest()
UpdateMarker(router)
r := PerformRequestWithBody(app, "PUT", "/api/v1/photos/pt9jtdre2lvl0y17/files/ft72s39w45bnlqdw/markers/12", "test")
assert.Equal(t, http.StatusBadRequest, r.Code)
})
t.Run("bad request file and photouid not matching", func(t *testing.T) {
app, router, _ := NewApiTest()
UpdateMarker(router)
r := PerformRequestWithBody(app, "PUT", "/api/v1/photos/pt9jtdre2lvl0y16/files/fikjs39w45bnlqdw/markers/12", "test")
assert.Equal(t, http.StatusBadRequest, r.Code)
})
t.Run("file not existing", func(t *testing.T) {
app, router, _ := NewApiTest()
UpdateMarker(router)
r := PerformRequestWithBody(app, "PUT", "/api/v1/photos/pt9jtdre2lvl0y17/files/fxxxx39w45bnlqdw/markers/1112", "test")
assert.Equal(t, http.StatusNotFound, r.Code)
})
t.Run("marker not existing", func(t *testing.T) {
app, router, _ := NewApiTest()
UpdateMarker(router)
r := PerformRequestWithBody(app, "PUT", "/api/v1/photos/pt9jtdre2lvl0y17/files/fikjs39w45bnlqdw/markers/1112", "test")
assert.Equal(t, http.StatusNotFound, r.Code)
})
t.Run("empty photouid", func(t *testing.T) {
app, router, _ := NewApiTest()
UpdateMarker(router)
r := PerformRequestWithBody(app, "PUT", "/api/v1/photos//files/fikjs39w45bnlqdw/markers/1112", "test")
assert.Equal(t, http.StatusBadRequest, r.Code)
})
t.Run("update cluster with existing subject", func(t *testing.T) {
app, router, _ := NewApiTest()
UpdateMarker(router)
var m = struct {
ID int
Type string
Src string
Name string
SubjectUID string
SubjectSrc string
FaceID string
}{ID: 8,
Type: "face",
Src: "image",
Name: "Actress A",
SubjectUID: "jqy1y111h1njaaac",
SubjectSrc: "manual",
FaceID: "GMH5NISEEULNJL6RATITOA3TMZXMTMCI"}
if b, err := json.Marshal(m); err != nil {
t.Fatal(err)
} else {
r := PerformRequestWithBody(app, "PUT", "/api/v1/photos/pt9jtdre2lvl0y12/files/ft3es39w45bnlqdw/markers/8", string(b))
assert.Equal(t, http.StatusOK, r.Code)
ClearMarkerSubject(router)
r = PerformRequestWithBody(app, "DELETE", "/api/v1/photos/pt9jtdre2lvl0y12/files/ft3es39w45bnlqdw/markers/8/subject", "")
assert.Equal(t, http.StatusOK, r.Code)
}
})
t.Run("update cluster with existing subject", func(t *testing.T) {
app, router, _ := NewApiTest()
UpdateMarker(router)
var m = struct {
ID int
Type string
Src string
Name string
SubjectUID string
SubjectSrc string
FaceID string
}{ID: 8,
Type: "face",
Src: "image",
Name: "Actress A",
SubjectUID: "jqy1y111h1njaaac",
SubjectSrc: "manual",
FaceID: "GMH5NISEEULNJL6RATITOA3TMZXMTMCI"}
if b, err := json.Marshal(m); err != nil {
t.Fatal(err)
} else {
r := PerformRequestWithBody(app, "PUT", "/api/v1/photos/pt9jtdre2lvl0y12/files/ft3es39w45bnlqdw/markers/8", string(b))
assert.Equal(t, http.StatusOK, r.Code)
ClearMarkerSubject(router)
r = PerformRequestWithBody(app, "DELETE", "/api/v1/photos/pt9jtdre2lvl0y12/files/ft3es39w45bnlqdw/markers/8/subject", "")
assert.Equal(t, http.StatusOK, r.Code)
}
})
t.Run("invalid body", func(t *testing.T) {
app, router, _ := NewApiTest()
UpdateMarker(router)
var m = struct {
ID int
Type string
Src int
Name int
SubjectUID string
SubjectSrc string
FaceID string
}{ID: 8,
Type: "face",
Src: 123,
Name: 456,
SubjectUID: "jqy1y111h1njaaac",
SubjectSrc: "manual",
FaceID: "GMH5NISEEULNJL6RATITOA3TMZXMTMCI"}
if b, err := json.Marshal(m); err != nil {
t.Fatal(err)
} else {
r := PerformRequestWithBody(app, "PUT", "/api/v1/photos/pt9jtdre2lvl0y12/files/ft3es39w45bnlqdw/markers/8", string(b))
assert.Equal(t, http.StatusBadRequest, r.Code)
}
})
}
func TestClearMarkerSubject(t *testing.T) {
@ -88,4 +229,13 @@ func TestClearMarkerSubject(t *testing.T) {
assert.Equal(t, http.StatusOK, resp.Code)
})
t.Run("bad request non- primary file", func(t *testing.T) {
app, router, _ := NewApiTest()
ClearMarkerSubject(router)
r := PerformRequestWithBody(app, "DELETE", "/api/v1/photos/pt9jtdre2lvl0y17/files/ft72s39w45bnlqdw/markers/12/subject", "")
assert.Equal(t, http.StatusBadRequest, r.Code)
})
}

View file

@ -135,7 +135,7 @@ var MarkerFixtures = MarkerMap{
},
"fa-gr-1": Marker{ // file id 6
ID: 8,
FileID: 1000005,
FileID: 1000004,
FaceID: FaceFixtures.Get("fa-gr").ID,
FaceDist: 0.6,
SubjectSrc: SrcAuto,