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

@@ -0,0 +1,58 @@
package model
import (
"database/sql"
"testing"
)
func TestFinanceCategory_ProcessForJSON(t *testing.T) {
tests := []struct {
name string
budget sql.NullFloat64
wantNil bool
wantValue float64
}{
{
name: "with valid budget",
budget: sql.NullFloat64{Float64: 5000.0, Valid: true},
wantNil: false,
wantValue: 5000.0,
},
{
name: "with null budget",
budget: sql.NullFloat64{Valid: false},
wantNil: true,
},
{
name: "with zero valid budget",
budget: sql.NullFloat64{Float64: 0, Valid: true},
wantNil: false,
wantValue: 0,
},
{
name: "with negative budget",
budget: sql.NullFloat64{Float64: -100.5, Valid: true},
wantNil: false,
wantValue: -100.5,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := &FinanceCategory{Budget: tt.budget}
c.ProcessForJSON()
if tt.wantNil {
if c.BudgetVal != nil {
t.Errorf("expected nil BudgetVal, got %v", *c.BudgetVal)
}
} else {
if c.BudgetVal == nil {
t.Fatal("expected non-nil BudgetVal")
}
if *c.BudgetVal != tt.wantValue {
t.Errorf("expected %.2f, got %.2f", tt.wantValue, *c.BudgetVal)
}
}
})
}
}