diff --git a/internal/api/subject_test.go b/internal/api/subject_test.go index 29754b4a2..25b2d9419 100644 --- a/internal/api/subject_test.go +++ b/internal/api/subject_test.go @@ -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) + }) +}