62 lines
1.6 KiB
Go
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")
|
|
}
|
|
})
|
|
}
|