People: Add unit test #22
This commit is contained in:
parent
d56f89611a
commit
68dbcf4039
1 changed files with 25 additions and 0 deletions
|
@ -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)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue