// schedule_nextrun_test.go — pin the cron parser → next-run shape we
// rely on for the dashboard host row + schedules tab (P2R-14).
package http

import (
	"testing"
	"time"
)

func TestCronParserNext(t *testing.T) {
	cases := []struct {
		name string
		expr string
		from time.Time
		want time.Time
	}{
		{
			name: "daily at 03:00",
			expr: "0 3 * * *",
			from: time.Date(2026, 5, 4, 1, 0, 0, 0, time.UTC),
			want: time.Date(2026, 5, 4, 3, 0, 0, 0, time.UTC),
		},
		{
			name: "daily at 03:00 (after time of day → next day)",
			expr: "0 3 * * *",
			from: time.Date(2026, 5, 4, 5, 0, 0, 0, time.UTC),
			want: time.Date(2026, 5, 5, 3, 0, 0, 0, time.UTC),
		},
		{
			name: "every 15 minutes",
			expr: "*/15 * * * *",
			from: time.Date(2026, 5, 4, 1, 7, 0, 0, time.UTC),
			want: time.Date(2026, 5, 4, 1, 15, 0, 0, time.UTC),
		},
	}
	for _, c := range cases {
		t.Run(c.name, func(t *testing.T) {
			parsed, err := cronParser.Parse(c.expr)
			if err != nil {
				t.Fatalf("parse %q: %v", c.expr, err)
			}
			got := parsed.Next(c.from)
			if !got.Equal(c.want) {
				t.Fatalf("Next(%v) = %v, want %v", c.from, got, c.want)
			}
		})
	}
}
