52 lines
1.4 KiB
Go
52 lines
1.4 KiB
Go
package insight
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestTimeContextUsesRealTehranTodayAndReportsDatasetLag(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
now := time.Date(2026, time.August, 21, 8, 30, 0, 0, time.UTC)
|
|
dataThrough := time.Date(2026, time.June, 30, 0, 0, 0, 0, time.UTC)
|
|
|
|
got := BuildTimeContext(now, dataThrough)
|
|
|
|
if got.AsOfDate != "2026-08-21" {
|
|
t.Fatalf("AsOfDate = %q, want real Tehran date", got.AsOfDate)
|
|
}
|
|
if got.DataThroughDate != "2026-06-30" {
|
|
t.Fatalf("DataThroughDate = %q", got.DataThroughDate)
|
|
}
|
|
if got.ForecastStartDate != got.AsOfDate {
|
|
t.Fatalf("ForecastStartDate = %q, want %q", got.ForecastStartDate, got.AsOfDate)
|
|
}
|
|
if got.Freshness != FreshnessStale || got.DataLagDays != 52 {
|
|
t.Fatalf("freshness = %s, lag = %d", got.Freshness, got.DataLagDays)
|
|
}
|
|
}
|
|
|
|
func TestClassifyFreshnessUsesProductionBoundaries(t *testing.T) {
|
|
t.Parallel()
|
|
|
|
tests := []struct {
|
|
name string
|
|
lag int
|
|
want Freshness
|
|
}{
|
|
{name: "same day", lag: 0, want: FreshnessFresh},
|
|
{name: "yesterday", lag: 1, want: FreshnessFresh},
|
|
{name: "two days", lag: 2, want: FreshnessLagging},
|
|
{name: "seven days", lag: 7, want: FreshnessLagging},
|
|
{name: "eight days", lag: 8, want: FreshnessStale},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
if got := ClassifyFreshness(tt.lag); got != tt.want {
|
|
t.Fatalf("ClassifyFreshness(%d) = %s, want %s", tt.lag, got, tt.want)
|
|
}
|
|
})
|
|
}
|
|
}
|