Files
pulse-api/internal/handler/habits_test.go
2026-03-26 19:03:22 +00:00

34 lines
732 B
Go

package handler
import (
"bytes"
"net/http"
"net/http/httptest"
"testing"
)
func TestHabitHandler_Create_InvalidBody(t *testing.T) {
req := httptest.NewRequest("POST", "/habits", bytes.NewBufferString("not json"))
rr := httptest.NewRecorder()
h := &HabitHandler{habitService: nil}
h.Create(rr, req)
if rr.Code != http.StatusBadRequest {
t.Errorf("expected 400, got %d", rr.Code)
}
}
func TestHabitHandler_Create_EmptyName(t *testing.T) {
body := `{"name":""}`
req := httptest.NewRequest("POST", "/habits", bytes.NewBufferString(body))
rr := httptest.NewRecorder()
h := &HabitHandler{habitService: nil}
h.Create(rr, req)
if rr.Code != http.StatusBadRequest {
t.Errorf("expected 400, got %d", rr.Code)
}
}