test: expand handler tests to 53.4% coverage
Some checks failed
CI / lint-test (push) Failing after 1s

This commit is contained in:
Cosmo
2026-03-26 19:21:30 +00:00
parent 3c8dd575c3
commit f3cdad1b80
12 changed files with 2031 additions and 0 deletions

View File

@@ -84,6 +84,240 @@ func TestSavingsHandler_UpdateCategory_InvalidBody(t *testing.T) {
}
}
func TestSavingsHandler_UpdateCategory_InvalidID(t *testing.T) {
req := httptest.NewRequest("PUT", "/savings/categories/abc", bytes.NewBufferString("{}"))
req = withChiParam(req, "id", "abc")
rr := httptest.NewRecorder()
h := &SavingsHandler{repo: nil}
h.UpdateCategory(rr, req)
if rr.Code != http.StatusBadRequest {
t.Errorf("expected 400, got %d", rr.Code)
}
}
func TestSavingsHandler_UpdateCategory_InvalidBodyAfterValidID(t *testing.T) {
req := httptest.NewRequest("PUT", "/savings/categories/1", bytes.NewBufferString("bad json"))
req = withChiParam(req, "id", "1")
rr := httptest.NewRecorder()
h := &SavingsHandler{repo: nil}
h.UpdateCategory(rr, req)
if rr.Code != http.StatusBadRequest {
t.Errorf("expected 400, got %d", rr.Code)
}
}
func TestSavingsHandler_GetCategory_NoChiParam(t *testing.T) {
req := httptest.NewRequest("GET", "/savings/categories/1", nil)
rr := httptest.NewRecorder()
h := &SavingsHandler{repo: nil}
h.GetCategory(rr, req)
if rr.Code != http.StatusBadRequest {
t.Errorf("expected 400, got %d", rr.Code)
}
}
func TestSavingsHandler_GetCategory_InvalidID(t *testing.T) {
req := httptest.NewRequest("GET", "/savings/categories/abc", nil)
req = withChiParam(req, "id", "abc")
rr := httptest.NewRecorder()
h := &SavingsHandler{repo: nil}
h.GetCategory(rr, req)
if rr.Code != http.StatusBadRequest {
t.Errorf("expected 400, got %d", rr.Code)
}
}
func TestSavingsHandler_DeleteCategory_NoChiParam(t *testing.T) {
req := httptest.NewRequest("DELETE", "/savings/categories/1", nil)
rr := httptest.NewRecorder()
h := &SavingsHandler{repo: nil}
h.DeleteCategory(rr, req)
if rr.Code != http.StatusBadRequest {
t.Errorf("expected 400, got %d", rr.Code)
}
}
func TestSavingsHandler_DeleteCategory_InvalidID(t *testing.T) {
req := httptest.NewRequest("DELETE", "/savings/categories/abc", nil)
req = withChiParam(req, "id", "abc")
rr := httptest.NewRecorder()
h := &SavingsHandler{repo: nil}
h.DeleteCategory(rr, req)
if rr.Code != http.StatusBadRequest {
t.Errorf("expected 400, got %d", rr.Code)
}
}
func TestSavingsHandler_GetTransaction_NoChiParam(t *testing.T) {
req := httptest.NewRequest("GET", "/savings/transactions/1", nil)
rr := httptest.NewRecorder()
h := &SavingsHandler{repo: nil}
h.GetTransaction(rr, req)
if rr.Code != http.StatusBadRequest {
t.Errorf("expected 400, got %d", rr.Code)
}
}
func TestSavingsHandler_GetTransaction_InvalidID(t *testing.T) {
req := httptest.NewRequest("GET", "/savings/transactions/abc", nil)
req = withChiParam(req, "id", "abc")
rr := httptest.NewRecorder()
h := &SavingsHandler{repo: nil}
h.GetTransaction(rr, req)
if rr.Code != http.StatusBadRequest {
t.Errorf("expected 400, got %d", rr.Code)
}
}
func TestSavingsHandler_UpdateTransaction_NoChiParam(t *testing.T) {
req := httptest.NewRequest("PUT", "/savings/transactions/1", bytes.NewBufferString("{}"))
rr := httptest.NewRecorder()
h := &SavingsHandler{repo: nil}
h.UpdateTransaction(rr, req)
if rr.Code != http.StatusBadRequest {
t.Errorf("expected 400, got %d", rr.Code)
}
}
func TestSavingsHandler_UpdateTransaction_InvalidID(t *testing.T) {
req := httptest.NewRequest("PUT", "/savings/transactions/abc", bytes.NewBufferString("{}"))
req = withChiParam(req, "id", "abc")
rr := httptest.NewRecorder()
h := &SavingsHandler{repo: nil}
h.UpdateTransaction(rr, req)
if rr.Code != http.StatusBadRequest {
t.Errorf("expected 400, got %d", rr.Code)
}
}
func TestSavingsHandler_UpdateTransaction_InvalidBody(t *testing.T) {
req := httptest.NewRequest("PUT", "/savings/transactions/1", bytes.NewBufferString("bad json"))
req = withChiParam(req, "id", "1")
rr := httptest.NewRecorder()
h := &SavingsHandler{repo: nil}
h.UpdateTransaction(rr, req)
if rr.Code != http.StatusBadRequest {
t.Errorf("expected 400, got %d", rr.Code)
}
}
func TestSavingsHandler_DeleteTransaction_NoChiParam(t *testing.T) {
req := httptest.NewRequest("DELETE", "/savings/transactions/1", nil)
rr := httptest.NewRecorder()
h := &SavingsHandler{repo: nil}
h.DeleteTransaction(rr, req)
if rr.Code != http.StatusBadRequest {
t.Errorf("expected 400, got %d", rr.Code)
}
}
func TestSavingsHandler_DeleteTransaction_InvalidID(t *testing.T) {
req := httptest.NewRequest("DELETE", "/savings/transactions/abc", nil)
req = withChiParam(req, "id", "abc")
rr := httptest.NewRecorder()
h := &SavingsHandler{repo: nil}
h.DeleteTransaction(rr, req)
if rr.Code != http.StatusBadRequest {
t.Errorf("expected 400, got %d", rr.Code)
}
}
func TestSavingsHandler_ListMembers_NoChiParam(t *testing.T) {
req := httptest.NewRequest("GET", "/savings/categories/1/members", nil)
rr := httptest.NewRecorder()
h := &SavingsHandler{repo: nil}
h.ListMembers(rr, req)
if rr.Code != http.StatusBadRequest {
t.Errorf("expected 400, got %d", rr.Code)
}
}
func TestSavingsHandler_ListMembers_InvalidID(t *testing.T) {
req := httptest.NewRequest("GET", "/savings/categories/abc/members", nil)
req = withChiParam(req, "id", "abc")
rr := httptest.NewRecorder()
h := &SavingsHandler{repo: nil}
h.ListMembers(rr, req)
if rr.Code != http.StatusBadRequest {
t.Errorf("expected 400, got %d", rr.Code)
}
}
func TestSavingsHandler_AddMember_NoChiParam(t *testing.T) {
req := httptest.NewRequest("POST", "/savings/categories/1/members", bytes.NewBufferString("{}"))
rr := httptest.NewRecorder()
h := &SavingsHandler{repo: nil}
h.AddMember(rr, req)
if rr.Code != http.StatusBadRequest {
t.Errorf("expected 400, got %d", rr.Code)
}
}
func TestSavingsHandler_AddMember_InvalidID(t *testing.T) {
req := httptest.NewRequest("POST", "/savings/categories/abc/members", bytes.NewBufferString("{}"))
req = withChiParam(req, "id", "abc")
rr := httptest.NewRecorder()
h := &SavingsHandler{repo: nil}
h.AddMember(rr, req)
if rr.Code != http.StatusBadRequest {
t.Errorf("expected 400, got %d", rr.Code)
}
}
func TestSavingsHandler_RemoveMember_NoChiParam(t *testing.T) {
req := httptest.NewRequest("DELETE", "/savings/categories/1/members/2", nil)
rr := httptest.NewRecorder()
h := &SavingsHandler{repo: nil}
h.RemoveMember(rr, req)
if rr.Code != http.StatusBadRequest {
t.Errorf("expected 400, got %d", rr.Code)
}
}
func TestSavingsHandler_RemoveMember_InvalidCategoryID(t *testing.T) {
req := httptest.NewRequest("DELETE", "/savings/categories/abc/members/2", nil)
req = withChiParam(req, "id", "abc")
rr := httptest.NewRecorder()
h := &SavingsHandler{repo: nil}
h.RemoveMember(rr, req)
if rr.Code != http.StatusBadRequest {
t.Errorf("expected 400, got %d", rr.Code)
}
}
func TestSavingsHandler_RemoveMember_InvalidUserID(t *testing.T) {
req := httptest.NewRequest("DELETE", "/savings/categories/1/members/abc", nil)
req = withChiParam(req, "id", "1")
req = withChiParam(req, "userId", "abc")
rr := httptest.NewRecorder()
h := &SavingsHandler{repo: nil}
h.RemoveMember(rr, req)
if rr.Code != http.StatusBadRequest {
t.Errorf("expected 400, got %d", rr.Code)
}
}
func TestSavingsHandler_ListRecurringPlans_NoChiParam(t *testing.T) {
req := httptest.NewRequest("GET", "/savings/categories/1/plans", nil)
rr := httptest.NewRecorder()
h := &SavingsHandler{repo: nil}
h.ListRecurringPlans(rr, req)
if rr.Code != http.StatusBadRequest {
t.Errorf("expected 400, got %d", rr.Code)
}
}
func TestSavingsHandler_ListRecurringPlans_InvalidID(t *testing.T) {
req := httptest.NewRequest("GET", "/savings/categories/abc/plans", nil)
req = withChiParam(req, "id", "abc")
rr := httptest.NewRecorder()
h := &SavingsHandler{repo: nil}
h.ListRecurringPlans(rr, req)
if rr.Code != http.StatusBadRequest {
t.Errorf("expected 400, got %d", rr.Code)
}
}
func TestSavingsHandler_CreateRecurringPlan_InvalidBody(t *testing.T) {
req := httptest.NewRequest("POST", "/savings/categories/1/plans", bytes.NewBufferString("bad"))
rr := httptest.NewRecorder()
@@ -95,3 +329,77 @@ func TestSavingsHandler_CreateRecurringPlan_InvalidBody(t *testing.T) {
t.Errorf("expected 400, got %d", rr.Code)
}
}
func TestSavingsHandler_CreateRecurringPlan_NoChiParam(t *testing.T) {
req := httptest.NewRequest("POST", "/savings/categories/1/plans", bytes.NewBufferString("{}"))
rr := httptest.NewRecorder()
h := &SavingsHandler{repo: nil}
h.CreateRecurringPlan(rr, req)
if rr.Code != http.StatusBadRequest {
t.Errorf("expected 400, got %d", rr.Code)
}
}
func TestSavingsHandler_CreateRecurringPlan_InvalidID(t *testing.T) {
req := httptest.NewRequest("POST", "/savings/categories/abc/plans", bytes.NewBufferString("{}"))
req = withChiParam(req, "id", "abc")
rr := httptest.NewRecorder()
h := &SavingsHandler{repo: nil}
h.CreateRecurringPlan(rr, req)
if rr.Code != http.StatusBadRequest {
t.Errorf("expected 400, got %d", rr.Code)
}
}
func TestSavingsHandler_DeleteRecurringPlan_NoChiParam(t *testing.T) {
req := httptest.NewRequest("DELETE", "/savings/categories/1/plans/1", nil)
rr := httptest.NewRecorder()
h := &SavingsHandler{repo: nil}
h.DeleteRecurringPlan(rr, req)
if rr.Code != http.StatusBadRequest {
t.Errorf("expected 400, got %d", rr.Code)
}
}
func TestSavingsHandler_DeleteRecurringPlan_InvalidID(t *testing.T) {
req := httptest.NewRequest("DELETE", "/savings/categories/1/plans/abc", nil)
req = withChiParam(req, "planId", "abc")
rr := httptest.NewRecorder()
h := &SavingsHandler{repo: nil}
h.DeleteRecurringPlan(rr, req)
if rr.Code != http.StatusBadRequest {
t.Errorf("expected 400, got %d", rr.Code)
}
}
func TestSavingsHandler_UpdateRecurringPlan_NoChiParam(t *testing.T) {
req := httptest.NewRequest("PUT", "/savings/categories/1/plans/1", bytes.NewBufferString("{}"))
rr := httptest.NewRecorder()
h := &SavingsHandler{repo: nil}
h.UpdateRecurringPlan(rr, req)
if rr.Code != http.StatusBadRequest {
t.Errorf("expected 400, got %d", rr.Code)
}
}
func TestSavingsHandler_UpdateRecurringPlan_InvalidID(t *testing.T) {
req := httptest.NewRequest("PUT", "/savings/categories/1/plans/abc", bytes.NewBufferString("{}"))
req = withChiParam(req, "planId", "abc")
rr := httptest.NewRecorder()
h := &SavingsHandler{repo: nil}
h.UpdateRecurringPlan(rr, req)
if rr.Code != http.StatusBadRequest {
t.Errorf("expected 400, got %d", rr.Code)
}
}
func TestSavingsHandler_UpdateRecurringPlan_InvalidBody(t *testing.T) {
req := httptest.NewRequest("PUT", "/savings/categories/1/plans/1", bytes.NewBufferString("bad json"))
req = withChiParam(req, "planId", "1")
rr := httptest.NewRecorder()
h := &SavingsHandler{repo: nil}
h.UpdateRecurringPlan(rr, req)
if rr.Code != http.StatusBadRequest {
t.Errorf("expected 400, got %d", rr.Code)
}
}