package main import ( "context" "errors" "fuj-management/go/internal/scheduler" "fuj-management/go/internal/services/banksync" "io" "strings" "testing" "time" ) func TestSyncInfo(t *testing.T) { now := time.Date(2026, 10, 8, 12, 0, 0, 0, time.UTC) four := []scheduler.TimeOfDay{{Hour: 4}} ok := banksync.NewRunner(func(context.Context, io.Writer) error { return nil }) if got := syncInfo(ok, four, time.UTC, now); got != "no sync since start | next 2026-10-09 04:00" { t.Errorf("before any run: %q", got) } if err := ok.Run(context.Background(), "scheduled", io.Discard); err != nil { t.Fatal(err) } got := syncInfo(ok, nil, time.UTC, now) if !strings.HasPrefix(got, "last sync ") || !strings.HasSuffix(got, "(scheduled) ok | scheduled sync off") { t.Errorf("after ok run, schedule off: %q", got) } bad := banksync.NewRunner(func(context.Context, io.Writer) error { return errors.New("boom") }) _ = bad.Run(context.Background(), "manual", io.Discard) if got := syncInfo(bad, four, time.UTC, now); !strings.Contains(got, "(manual) FAILED | next 2026-10-09 04:00") { t.Errorf("after failed run: %q", got) } }