test: expand handler tests to 53.4% coverage
Some checks failed
CI / lint-test (push) Failing after 1s
Some checks failed
CI / lint-test (push) Failing after 1s
This commit is contained in:
@@ -31,3 +31,150 @@ func TestHabitHandler_Create_EmptyName(t *testing.T) {
|
||||
t.Errorf("expected 400, got %d", rr.Code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHabitHandler_Get_NoChiParam(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", "/habits/1", nil)
|
||||
rr := httptest.NewRecorder()
|
||||
h := &HabitHandler{habitService: nil}
|
||||
h.Get(rr, req)
|
||||
if rr.Code != http.StatusBadRequest {
|
||||
t.Errorf("expected 400, got %d", rr.Code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHabitHandler_Get_InvalidID(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", "/habits/abc", nil)
|
||||
req = withChiParam(req, "id", "abc")
|
||||
rr := httptest.NewRecorder()
|
||||
h := &HabitHandler{habitService: nil}
|
||||
h.Get(rr, req)
|
||||
if rr.Code != http.StatusBadRequest {
|
||||
t.Errorf("expected 400, got %d", rr.Code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHabitHandler_Update_NoChiParam(t *testing.T) {
|
||||
req := httptest.NewRequest("PUT", "/habits/1", bytes.NewBufferString("{}"))
|
||||
rr := httptest.NewRecorder()
|
||||
h := &HabitHandler{habitService: nil}
|
||||
h.Update(rr, req)
|
||||
if rr.Code != http.StatusBadRequest {
|
||||
t.Errorf("expected 400, got %d", rr.Code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHabitHandler_Update_InvalidBody(t *testing.T) {
|
||||
req := httptest.NewRequest("PUT", "/habits/1", bytes.NewBufferString("bad json"))
|
||||
req = withChiParam(req, "id", "1")
|
||||
rr := httptest.NewRecorder()
|
||||
h := &HabitHandler{habitService: nil}
|
||||
h.Update(rr, req)
|
||||
if rr.Code != http.StatusBadRequest {
|
||||
t.Errorf("expected 400, got %d", rr.Code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHabitHandler_Delete_NoChiParam(t *testing.T) {
|
||||
req := httptest.NewRequest("DELETE", "/habits/1", nil)
|
||||
rr := httptest.NewRecorder()
|
||||
h := &HabitHandler{habitService: nil}
|
||||
h.Delete(rr, req)
|
||||
if rr.Code != http.StatusBadRequest {
|
||||
t.Errorf("expected 400, got %d", rr.Code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHabitHandler_Delete_InvalidID(t *testing.T) {
|
||||
req := httptest.NewRequest("DELETE", "/habits/abc", nil)
|
||||
req = withChiParam(req, "id", "abc")
|
||||
rr := httptest.NewRecorder()
|
||||
h := &HabitHandler{habitService: nil}
|
||||
h.Delete(rr, req)
|
||||
if rr.Code != http.StatusBadRequest {
|
||||
t.Errorf("expected 400, got %d", rr.Code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHabitHandler_Log_NoChiParam(t *testing.T) {
|
||||
req := httptest.NewRequest("POST", "/habits/1/log", bytes.NewBufferString("{}"))
|
||||
rr := httptest.NewRecorder()
|
||||
h := &HabitHandler{habitService: nil}
|
||||
h.Log(rr, req)
|
||||
if rr.Code != http.StatusBadRequest {
|
||||
t.Errorf("expected 400, got %d", rr.Code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHabitHandler_Log_InvalidID(t *testing.T) {
|
||||
req := httptest.NewRequest("POST", "/habits/abc/log", bytes.NewBufferString("{}"))
|
||||
req = withChiParam(req, "id", "abc")
|
||||
rr := httptest.NewRecorder()
|
||||
h := &HabitHandler{habitService: nil}
|
||||
h.Log(rr, req)
|
||||
if rr.Code != http.StatusBadRequest {
|
||||
t.Errorf("expected 400, got %d", rr.Code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHabitHandler_GetLogs_NoChiParam(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", "/habits/1/logs", nil)
|
||||
rr := httptest.NewRecorder()
|
||||
h := &HabitHandler{habitService: nil}
|
||||
h.GetLogs(rr, req)
|
||||
if rr.Code != http.StatusBadRequest {
|
||||
t.Errorf("expected 400, got %d", rr.Code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHabitHandler_GetLogs_InvalidID(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", "/habits/abc/logs", nil)
|
||||
req = withChiParam(req, "id", "abc")
|
||||
rr := httptest.NewRecorder()
|
||||
h := &HabitHandler{habitService: nil}
|
||||
h.GetLogs(rr, req)
|
||||
if rr.Code != http.StatusBadRequest {
|
||||
t.Errorf("expected 400, got %d", rr.Code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHabitHandler_DeleteLog_NoChiParam(t *testing.T) {
|
||||
req := httptest.NewRequest("DELETE", "/habits/logs/1", nil)
|
||||
rr := httptest.NewRecorder()
|
||||
h := &HabitHandler{habitService: nil}
|
||||
h.DeleteLog(rr, req)
|
||||
if rr.Code != http.StatusBadRequest {
|
||||
t.Errorf("expected 400, got %d", rr.Code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHabitHandler_DeleteLog_InvalidID(t *testing.T) {
|
||||
req := httptest.NewRequest("DELETE", "/habits/logs/abc", nil)
|
||||
req = withChiParam(req, "logId", "abc")
|
||||
rr := httptest.NewRecorder()
|
||||
h := &HabitHandler{habitService: nil}
|
||||
h.DeleteLog(rr, req)
|
||||
if rr.Code != http.StatusBadRequest {
|
||||
t.Errorf("expected 400, got %d", rr.Code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHabitHandler_HabitStats_NoChiParam(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", "/habits/1/stats", nil)
|
||||
rr := httptest.NewRecorder()
|
||||
h := &HabitHandler{habitService: nil}
|
||||
h.HabitStats(rr, req)
|
||||
if rr.Code != http.StatusBadRequest {
|
||||
t.Errorf("expected 400, got %d", rr.Code)
|
||||
}
|
||||
}
|
||||
|
||||
func TestHabitHandler_HabitStats_InvalidID(t *testing.T) {
|
||||
req := httptest.NewRequest("GET", "/habits/abc/stats", nil)
|
||||
req = withChiParam(req, "id", "abc")
|
||||
rr := httptest.NewRecorder()
|
||||
h := &HabitHandler{habitService: nil}
|
||||
h.HabitStats(rr, req)
|
||||
if rr.Code != http.StatusBadRequest {
|
||||
t.Errorf("expected 400, got %d", rr.Code)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user