test: add model and service tests (email, finance, task, habit, interest)
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:
@@ -17,7 +17,7 @@ func TestNewTaskService(t *testing.T) {
|
|||||||
|
|
||||||
// createNextRecurrence returns without DB call for unknown recurrence types.
|
// createNextRecurrence returns without DB call for unknown recurrence types.
|
||||||
func TestCreateNextRecurrence_UnknownType(t *testing.T) {
|
func TestCreateNextRecurrence_UnknownType(t *testing.T) {
|
||||||
svc := &TaskService{} // nil taskRepo — should not be called
|
svc := &TaskService{}
|
||||||
task := &model.Task{
|
task := &model.Task{
|
||||||
UserID: 1,
|
UserID: 1,
|
||||||
Title: "Test Task",
|
Title: "Test Task",
|
||||||
@@ -26,15 +26,14 @@ func TestCreateNextRecurrence_UnknownType(t *testing.T) {
|
|||||||
RecurrenceInterval: 1,
|
RecurrenceInterval: 1,
|
||||||
DueDate: sql.NullTime{Time: time.Now().AddDate(0, 0, 1), Valid: true},
|
DueDate: sql.NullTime{Time: time.Now().AddDate(0, 0, 1), Valid: true},
|
||||||
}
|
}
|
||||||
// Should return early — no panic from nil taskRepo
|
|
||||||
svc.createNextRecurrence(task)
|
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) {
|
func TestCreateNextRecurrence_PastEndDate(t *testing.T) {
|
||||||
svc := &TaskService{} // nil taskRepo — should not be called
|
svc := &TaskService{}
|
||||||
yesterday := time.Now().AddDate(0, 0, -1)
|
yesterday := time.Now().AddDate(0, 0, -1)
|
||||||
twoDaysAgo := time.Now().AddDate(0, 0, -2)
|
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
name string
|
name string
|
||||||
@@ -43,28 +42,32 @@ func TestCreateNextRecurrence_PastEndDate(t *testing.T) {
|
|||||||
endDate time.Time
|
endDate time.Time
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
|
// daily: currentDue=2 days ago, nextDue=yesterday; endDate=3 days ago => next > end
|
||||||
name: "daily past end",
|
name: "daily past end",
|
||||||
recurrenceType: "daily",
|
recurrenceType: "daily",
|
||||||
currentDue: twoDaysAgo,
|
currentDue: time.Now().AddDate(0, 0, -2),
|
||||||
endDate: yesterday,
|
endDate: time.Now().AddDate(0, 0, -3),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
// weekly: currentDue=7 days ago, nextDue=today; endDate=yesterday => next > end
|
||||||
name: "weekly past end",
|
name: "weekly past end",
|
||||||
recurrenceType: "weekly",
|
recurrenceType: "weekly",
|
||||||
currentDue: time.Now().AddDate(0, 0, -14),
|
currentDue: time.Now().AddDate(0, 0, -7),
|
||||||
endDate: yesterday,
|
endDate: yesterday,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
// monthly: currentDue=1 month ago, nextDue=today; endDate=yesterday => next > end
|
||||||
name: "monthly past end",
|
name: "monthly past end",
|
||||||
recurrenceType: "monthly",
|
recurrenceType: "monthly",
|
||||||
currentDue: time.Now().AddDate(0, -2, 0),
|
currentDue: time.Now().AddDate(0, -1, 0),
|
||||||
endDate: yesterday,
|
endDate: yesterday,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
// custom: currentDue=2 days ago, nextDue=yesterday; endDate=3 days ago => next > end
|
||||||
name: "custom past end",
|
name: "custom past end",
|
||||||
recurrenceType: "custom",
|
recurrenceType: "custom",
|
||||||
currentDue: twoDaysAgo,
|
currentDue: time.Now().AddDate(0, 0, -2),
|
||||||
endDate: yesterday,
|
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},
|
DueDate: sql.NullTime{Time: tt.currentDue, Valid: true},
|
||||||
RecurrenceEndDate: sql.NullTime{Time: tt.endDate, Valid: true},
|
RecurrenceEndDate: sql.NullTime{Time: tt.endDate, Valid: true},
|
||||||
}
|
}
|
||||||
// Should return early — no panic from nil taskRepo
|
|
||||||
svc.createNextRecurrence(task)
|
svc.createNextRecurrence(task)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// interval < 1 gets normalized to 1
|
// interval=0 gets normalized to 1 inside createNextRecurrence
|
||||||
func TestCreateNextRecurrence_IntervalNormalization(t *testing.T) {
|
func TestCreateNextRecurrence_IntervalNormalization(t *testing.T) {
|
||||||
svc := &TaskService{}
|
svc := &TaskService{}
|
||||||
yesterday := time.Now().AddDate(0, 0, -1)
|
|
||||||
|
|
||||||
task := &model.Task{
|
task := &model.Task{
|
||||||
UserID: 1,
|
UserID: 1,
|
||||||
Title: "Test",
|
Title: "Test",
|
||||||
IsRecurring: true,
|
IsRecurring: true,
|
||||||
RecurrenceType: sql.NullString{String: "daily", Valid: true},
|
RecurrenceType: sql.NullString{String: "unknown_type", Valid: true},
|
||||||
RecurrenceInterval: 0, // should be normalized to 1
|
RecurrenceInterval: 0,
|
||||||
DueDate: sql.NullTime{Time: time.Now().AddDate(0, 0, -10), Valid: true},
|
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)
|
svc.createNextRecurrence(task)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user