People: Add unit test #22

This commit is contained in:
theresa 2021-09-20 09:31:30 +02:00
parent d56f89611a
commit 68dbcf4039

View file

@ -111,3 +111,28 @@ func TestDislikeSubject(t *testing.T) {
assert.Equal(t, "false", val4.String())
})
}
func TestUpdateSubject(t *testing.T) {
t.Run("successful request person", func(t *testing.T) {
app, router, _ := NewApiTest()
UpdateSubject(router)
r := PerformRequestWithBody(app, "PUT", "/api/v1/subjects/jqu0xs11qekk9jx8", `{"Name": "Updated Name"}`)
val := gjson.Get(r.Body.String(), "Name")
assert.Equal(t, "Updated Name", val.String())
assert.Equal(t, http.StatusOK, r.Code)
})
t.Run("invalid request", func(t *testing.T) {
app, router, _ := NewApiTest()
UpdateSubject(router)
r := PerformRequestWithBody(app, "PUT", "/api/v1/subjects/jqu0xs11qekk9jx8", `{"Name": 123}`)
assert.Equal(t, http.StatusBadRequest, r.Code)
})
t.Run("not found", func(t *testing.T) {
app, router, _ := NewApiTest()
UpdateSubject(router)
r := PerformRequestWithBody(app, "PUT", "/api/v1/subjectss/xxx", `{"Name": "Updated Name"}`)
assert.Equal(t, http.StatusNotFound, r.Code)
})
}