chore: initial commit of HouseholdBudgetBook (backend, frontend, desktop)
This commit is contained in:
commit
4a5db3f1f9
167 files changed
+21732
No files matched your search
@@ -0,0 +1,83 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
_ "modernc.org/sqlite"
|
||||
)
|
||||
|
||||
func TestUpcomingPoliciesUsesInclusiveLocalDateWindow(t *testing.T) {
|
||||
db := setupPolicyTestDB(t)
|
||||
svc := NewPolicyService(db)
|
||||
svc.now = func() time.Time {
|
||||
return time.Date(2026, 4, 28, 23, 30, 0, 0, time.Local)
|
||||
}
|
||||
|
||||
insertPolicy(t, db, "expired", "2026-04-27")
|
||||
insertPolicy(t, db, "today", "2026-04-28")
|
||||
insertPolicy(t, db, "in 30 days", "2026-05-28")
|
||||
insertPolicy(t, db, "in 31 days", "2026-05-29")
|
||||
insertPolicy(t, db, "no end date", "")
|
||||
|
||||
items, err := svc.Upcoming(context.Background(), 30)
|
||||
if err != nil {
|
||||
t.Fatalf("Upcoming returned error: %v", err)
|
||||
}
|
||||
|
||||
got := make([]string, 0, len(items))
|
||||
for _, item := range items {
|
||||
got = append(got, item.Name)
|
||||
}
|
||||
want := []string{"today", "in 30 days"}
|
||||
if len(got) != len(want) {
|
||||
t.Fatalf("expected %v, got %v", want, got)
|
||||
}
|
||||
for i := range want {
|
||||
if got[i] != want[i] {
|
||||
t.Fatalf("expected %v, got %v", want, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func setupPolicyTestDB(t *testing.T) *sql.DB {
|
||||
t.Helper()
|
||||
db, err := sql.Open("sqlite", ":memory:")
|
||||
if err != nil {
|
||||
t.Fatalf("open sqlite: %v", err)
|
||||
}
|
||||
t.Cleanup(func() { _ = db.Close() })
|
||||
|
||||
_, err = db.Exec(`CREATE TABLE policies (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL,
|
||||
type TEXT NOT NULL DEFAULT 'other',
|
||||
insured_person TEXT NOT NULL DEFAULT '',
|
||||
premium INTEGER NOT NULL DEFAULT 0,
|
||||
coverage_amount INTEGER NOT NULL DEFAULT 0,
|
||||
start_date TEXT NOT NULL DEFAULT '',
|
||||
end_date TEXT NOT NULL DEFAULT '',
|
||||
payment_frequency TEXT NOT NULL DEFAULT 'annual',
|
||||
next_payment_date TEXT NOT NULL DEFAULT '',
|
||||
payment_term_end TEXT NOT NULL DEFAULT '',
|
||||
beneficiary TEXT NOT NULL DEFAULT '',
|
||||
status TEXT NOT NULL DEFAULT 'active',
|
||||
note TEXT NOT NULL DEFAULT '',
|
||||
created_at TEXT NOT NULL DEFAULT (datetime('now')),
|
||||
updated_at TEXT NOT NULL DEFAULT (datetime('now'))
|
||||
)`)
|
||||
if err != nil {
|
||||
t.Fatalf("create policies table: %v", err)
|
||||
}
|
||||
return db
|
||||
}
|
||||
|
||||
func insertPolicy(t *testing.T, db *sql.DB, name string, endDate string) {
|
||||
t.Helper()
|
||||
_, err := db.Exec(`INSERT INTO policies (name, end_date, next_payment_date) VALUES (?, ?, ?)`, name, endDate, endDate)
|
||||
if err != nil {
|
||||
t.Fatalf("insert policy %q: %v", name, err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user