package service import ( "testing" "time" "vidarchive/internal/models" ) func TestComputeNextRun(t *testing.T) { svc := &SubscriptionService{} // A fixed reference time: 2026-06-21 12:30 local. from := time.Date(2026, 6, 21, 12, 30, 0, 0, time.Local) cases := []struct { kind string custom string wantErr bool check func(t *testing.T, next time.Time) }{ {kind: "hourly", check: func(t *testing.T, next time.Time) { if !next.After(from) || next.Minute() != 0 { t.Errorf("hourly: got %v", next) } }}, {kind: "daily", check: func(t *testing.T, next time.Time) { if next.Hour() != 3 || next.Minute() != 0 || !next.After(from) { t.Errorf("daily: got %v", next) } }}, {kind: "weekly", check: func(t *testing.T, next time.Time) { if next.Weekday() != time.Sunday || !next.After(from) { t.Errorf("weekly: got %v", next) } }}, {kind: "monthly", check: func(t *testing.T, next time.Time) { if next.Day() != 1 || !next.After(from) { t.Errorf("monthly: got %v", next) } }}, {kind: "cron", custom: "*/15 * * * *", check: func(t *testing.T, next time.Time) { if next.Minute() != 45 || !next.After(from) { t.Errorf("custom cron */15: got %v", next) } }}, {kind: "cron", custom: "not a cron", wantErr: true}, {kind: "cron", custom: "", wantErr: true}, {kind: "bogus", wantErr: true}, } for _, c := range cases { sub := &models.Subscription{ScheduleKind: c.kind, CronExpr: c.custom} next, err := svc.ComputeNextRun(sub, from) if c.wantErr { if err == nil { t.Errorf("kind=%q custom=%q: expected error, got %v", c.kind, c.custom, next) } continue } if err != nil { t.Errorf("kind=%q custom=%q: unexpected error: %v", c.kind, c.custom, err) continue } c.check(t, next) } }