diff --git a/handlers/api.go b/handlers/api.go index 55e29d1c..0df59c96 100644 --- a/handlers/api.go +++ b/handlers/api.go @@ -235,7 +235,6 @@ func apiNotifierUpdateHandler(w http.ResponseWriter, r *http.Request) { } vars := mux.Vars(r) var notification *notifier.Notification - fmt.Println(r.Body) decoder := json.NewDecoder(r.Body) err := decoder.Decode(¬ification) if err != nil { @@ -247,7 +246,6 @@ func apiNotifierUpdateHandler(w http.ResponseWriter, r *http.Request) { sendErrorJson(err, w, r) return } - notifer.Var1 = notification.Var1 notifer.Var2 = notification.Var2 notifer.Host = notification.Host diff --git a/handlers/handlers_test.go b/handlers/handlers_test.go index a3ec869c..03bd4cd3 100644 --- a/handlers/handlers_test.go +++ b/handlers/handlers_test.go @@ -363,6 +363,18 @@ func TestPrometheusHandler(t *testing.T) { assert.True(t, isRouteAuthenticated(req)) } +func TestUpdateNotificationHandler(t *testing.T) { + t.SkipNow() + data := `{"limits": 7, "enabled": true, "method": "email", "host": "smtp.emailserver.com", "username": "exampleuser", "password": "password123", "port": 543, "var1": "info@betatude.com", "var2": "sendto@gmail.com"}` + rr, err := httpRequestAPI(t, "POST", "/api/notifier/email", strings.NewReader(data)) + assert.Nil(t, err) + body := rr.Body.String() + var obj apiResponse + formatJSON(body, &obj) + assert.Equal(t, 200, rr.Code) + assert.Equal(t, "success", obj.Status) +} + func TestViewNotificationSettingsHandler(t *testing.T) { t.SkipNow() req, err := http.NewRequest("GET", "/settings", nil) diff --git a/handlers/route_api_test.go b/handlers/route_api_test.go index 6aeea75c..97038f15 100644 --- a/handlers/route_api_test.go +++ b/handlers/route_api_test.go @@ -280,6 +280,9 @@ func httpRequestAPI(t *testing.T, method, url string, body io.Reader) (*httptest if err != nil { return nil, err } + if body != nil { + req.Header.Set("Content-Type", "application/json") + } req.Header.Set("Authorization", core.CoreApp.ApiSecret) rr := httptest.NewRecorder() Router().ServeHTTP(rr, req)