diff --git a/views/addViews_test.go b/views/addViews_test.go index 54ef4d6..abac205 100644 --- a/views/addViews_test.go +++ b/views/addViews_test.go @@ -51,3 +51,35 @@ func TestAddEmptyCategory(t *testing.T) { t.Error("Body should be empty. Instead contained data: ", body) } } + +func TestEditTaskWithWrongMethod(t *testing.T) { + ts := httptest.NewServer(http.HandlerFunc(EditTaskFunc)) + defer ts.Close() + req, err := http.NewRequest("OPTIONS", ts.URL, nil) + if err != nil { + t.Errorf("Error occured while constracting request:%s", err) + } + w := httptest.NewRecorder() + EditTaskFunc(w, req) + + if w.Code != http.StatusFound && message != "Method not allowed" { + t.Errorf("Message was: %s Return code was: %d. Should have been message: %s return code: %d", message, w.Code, "Method not allowed", http.StatusFound) + } +} + +func TestEditTaskWrongTaskName(t *testing.T) { + ts := httptest.NewServer(http.HandlerFunc(EditTaskFunc)) + defer ts.Close() + ts.URL = ts.URL + "/edit/invalidID" + req, err := http.NewRequest("GET", ts.URL, nil) + if err != nil { + t.Errorf("Error occured while constracting request:%s", err) + } + w := httptest.NewRecorder() + EditTaskFunc(w, req) + //TODO: Error should be returned as part of the string so that the message can tell + //why there was a problem. + if w.Code != http.StatusBadRequest { + t.Errorf("Actual status: (%d); Expected status:(%d)", w.Code, http.StatusBadRequest) + } +}