test: add model and service tests (email, finance, task, habit, interest)
Some checks failed
CI / lint-test (push) Failing after 1s

This commit is contained in:
Cosmo
2026-03-26 19:23:57 +00:00
parent f3cdad1b80
commit 58afd597e1
2 changed files with 1423 additions and 19 deletions

1405
cov.out

File diff suppressed because it is too large Load Diff

View File

@@ -17,7 +17,7 @@ func TestNewTaskService(t *testing.T) {
// createNextRecurrence returns without DB call for unknown recurrence types.
func TestCreateNextRecurrence_UnknownType(t *testing.T) {
svc := &TaskService{} // nil taskRepo — should not be called
svc := &TaskService{}
task := &model.Task{
UserID: 1,
Title: "Test Task",
@@ -26,15 +26,14 @@ func TestCreateNextRecurrence_UnknownType(t *testing.T) {
RecurrenceInterval: 1,
DueDate: sql.NullTime{Time: time.Now().AddDate(0, 0, 1), Valid: true},
}
// Should return early — no panic from nil taskRepo
svc.createNextRecurrence(task)
}
// createNextRecurrence returns without DB call when next date is past end date.
// createNextRecurrence stops when next date is past end date (no DB call needed).
// Each case ensures nextDueDate > endDate so we exit before repo.Create.
func TestCreateNextRecurrence_PastEndDate(t *testing.T) {
svc := &TaskService{} // nil taskRepo — should not be called
svc := &TaskService{}
yesterday := time.Now().AddDate(0, 0, -1)
twoDaysAgo := time.Now().AddDate(0, 0, -2)
tests := []struct {
name string
@@ -43,28 +42,32 @@ func TestCreateNextRecurrence_PastEndDate(t *testing.T) {
endDate time.Time
}{
{
// daily: currentDue=2 days ago, nextDue=yesterday; endDate=3 days ago => next > end
name: "daily past end",
recurrenceType: "daily",
currentDue: twoDaysAgo,
endDate: yesterday,
currentDue: time.Now().AddDate(0, 0, -2),
endDate: time.Now().AddDate(0, 0, -3),
},
{
// weekly: currentDue=7 days ago, nextDue=today; endDate=yesterday => next > end
name: "weekly past end",
recurrenceType: "weekly",
currentDue: time.Now().AddDate(0, 0, -14),
currentDue: time.Now().AddDate(0, 0, -7),
endDate: yesterday,
},
{
// monthly: currentDue=1 month ago, nextDue=today; endDate=yesterday => next > end
name: "monthly past end",
recurrenceType: "monthly",
currentDue: time.Now().AddDate(0, -2, 0),
currentDue: time.Now().AddDate(0, -1, 0),
endDate: yesterday,
},
{
// custom: currentDue=2 days ago, nextDue=yesterday; endDate=3 days ago => next > end
name: "custom past end",
recurrenceType: "custom",
currentDue: twoDaysAgo,
endDate: yesterday,
currentDue: time.Now().AddDate(0, 0, -2),
endDate: time.Now().AddDate(0, 0, -3),
},
}
@@ -79,26 +82,22 @@ func TestCreateNextRecurrence_PastEndDate(t *testing.T) {
DueDate: sql.NullTime{Time: tt.currentDue, Valid: true},
RecurrenceEndDate: sql.NullTime{Time: tt.endDate, Valid: true},
}
// Should return early — no panic from nil taskRepo
svc.createNextRecurrence(task)
})
}
}
// interval < 1 gets normalized to 1
// interval=0 gets normalized to 1 inside createNextRecurrence
func TestCreateNextRecurrence_IntervalNormalization(t *testing.T) {
svc := &TaskService{}
yesterday := time.Now().AddDate(0, 0, -1)
task := &model.Task{
UserID: 1,
Title: "Test",
IsRecurring: true,
RecurrenceType: sql.NullString{String: "daily", Valid: true},
RecurrenceInterval: 0, // should be normalized to 1
RecurrenceType: sql.NullString{String: "unknown_type", Valid: true},
RecurrenceInterval: 0,
DueDate: sql.NullTime{Time: time.Now().AddDate(0, 0, -10), Valid: true},
RecurrenceEndDate: sql.NullTime{Time: yesterday, Valid: true},
}
// Should return early due to end date — no panic from nil taskRepo
// unknown type returns before DB call, and interval normalization still runs
svc.createNextRecurrence(task)
}