Files
pulse-api/internal/model/savings_test.go
Cosmo 8d9fe818f4
All checks were successful
CI / ci (push) Successful in 35s
Add unit tests for middleware, models, services, handlers, and repository helpers
2026-03-01 02:32:59 +00:00

62 lines
1.6 KiB
Go

package model
import (
"database/sql"
"testing"
"time"
)
func TestSavingsCategory_ProcessForJSON(t *testing.T) {
t.Run("with deposit dates", func(t *testing.T) {
c := &SavingsCategory{
DepositStartDate: sql.NullTime{Time: time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC), Valid: true},
DepositEndDate: sql.NullTime{Time: time.Date(2026, 1, 1, 0, 0, 0, 0, time.UTC), Valid: true},
CreditStartDate: sql.NullTime{Time: time.Date(2025, 6, 1, 0, 0, 0, 0, time.UTC), Valid: true},
}
c.ProcessForJSON()
if c.DepositStartStr == nil || *c.DepositStartStr != "2025-01-01" {
t.Errorf("expected 2025-01-01, got %v", c.DepositStartStr)
}
if c.DepositEndStr == nil || *c.DepositEndStr != "2026-01-01" {
t.Errorf("expected 2026-01-01, got %v", c.DepositEndStr)
}
if c.CreditStartStr == nil || *c.CreditStartStr != "2025-06-01" {
t.Errorf("expected 2025-06-01, got %v", c.CreditStartStr)
}
})
t.Run("without dates", func(t *testing.T) {
c := &SavingsCategory{}
c.ProcessForJSON()
if c.DepositStartStr != nil {
t.Error("expected nil deposit_start_date")
}
})
}
func TestSavingsRecurringPlan_ProcessForJSON(t *testing.T) {
t.Run("with user_id", func(t *testing.T) {
p := &SavingsRecurringPlan{
UserID: sql.NullInt64{Int64: 42, Valid: true},
}
p.ProcessForJSON()
if p.UserIDPtr == nil || *p.UserIDPtr != 42 {
t.Errorf("expected 42, got %v", p.UserIDPtr)
}
})
t.Run("without user_id", func(t *testing.T) {
p := &SavingsRecurringPlan{
UserID: sql.NullInt64{Valid: false},
}
p.ProcessForJSON()
if p.UserIDPtr != nil {
t.Error("expected nil user_id")
}
})
}