fix: anchor growth forecasts to real Tehran date

This commit is contained in:
2026-08-21 18:27:40 +08:00
parent 7140213857
commit 8507b5d017
9 changed files with 306 additions and 6 deletions

View File

@@ -0,0 +1,51 @@
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)
}
})
}
}