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:
58
internal/model/finance_test.go
Normal file
58
internal/model/finance_test.go
Normal 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)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user