Files
memby/server/internal/api/hero_schedule_test.go
T
2026-08-15 09:23:26 +12:00

40 lines
1.3 KiB
Go

package api
import (
"testing"
"time"
"github.com/ponzischeme89/memby/server/internal/store"
)
func TestRecurringHeroScheduleUsesLocalWeekdayAndTime(t *testing.T) {
zone := time.FixedZone("NZST", 12*60*60)
schedule := store.HeroSchedule{
Frequency: "weekly", StartTime: "18:00", EndTime: "22:00",
Weekdays: []int{1},
}
monday := time.Date(2026, 8, 17, 19, 0, 0, 0, zone)
if !heroScheduleActiveAt(schedule, monday, zone) {
t.Fatal("Monday evening schedule was not active")
}
if heroScheduleActiveAt(schedule, monday.Add(24*time.Hour), zone) {
t.Fatal("Monday schedule remained active on Tuesday")
}
}
func TestOvernightHeroScheduleBelongsToStartingDay(t *testing.T) {
zone := time.FixedZone("NZST", 12*60*60)
schedule := store.HeroSchedule{
Frequency: "weekly", StartTime: "22:00", EndTime: "02:00",
Weekdays: []int{5}, // Friday night through early Saturday.
}
fridayNight := time.Date(2026, 8, 21, 23, 0, 0, 0, zone)
saturdayEarly := time.Date(2026, 8, 22, 1, 0, 0, 0, zone)
if !heroScheduleActiveAt(schedule, fridayNight, zone) || !heroScheduleActiveAt(schedule, saturdayEarly, zone) {
t.Fatal("overnight Friday schedule did not span midnight")
}
if heroScheduleActiveAt(schedule, saturdayEarly.Add(24*time.Hour), zone) {
t.Fatal("overnight Friday schedule was active on Sunday morning")
}
}