Preserve metric forecast units and overnight alerts

This commit is contained in:
2026-08-13 00:45:08 +00:00
parent 8fafacf921
commit 8e49ba88c7
5 changed files with 230 additions and 45 deletions

View File

@@ -100,6 +100,33 @@ func TestBuildDerivedDailySlicesDaypartsAndAlerts(t *testing.T) {
}
}
func TestBuildDerivedDailyIncludesNextDayOvernightAlerts(t *testing.T) {
location := testLocation()
bundle := testBundle(location)
bundle.Alerts = &weatherdata.AlertRun{Alerts: []json.RawMessage{
json.RawMessage(`{"event":"Overnight Advisory","onset":"2026-05-30T01:00:00-05:00","ends":"2026-05-30T05:00:00-05:00"}`),
}}
derived, err := BuildDerived(BuildDerivedRequest{
Resolved: resolveForTest(t, report.Daily, mustParse("2026-05-29T08:00:00-05:00"), location),
Timezone: location.String(),
Dayparts: []forecast.DaypartDefinition{
{Name: "night", Start: "22:00", End: "06:00"},
},
Collected: BuildCollected(bundle),
})
if err != nil {
t.Fatalf("BuildDerived() error = %v", err)
}
summary := derived.FirstDailySummary()
if summary == nil || len(summary.AlertOverlaps) != 0 {
t.Fatalf("DailySummary = %#v, want no next-day daily alerts", summary)
}
if len(derived.DaypartSummaries) != 1 || len(derived.DaypartSummaries[0].AlertOverlaps) != 1 || derived.DaypartSummaries[0].AlertOverlaps[0].Event != "Overnight Advisory" {
t.Fatalf("DaypartSummaries = %#v, want next-day overnight alert", derived.DaypartSummaries)
}
}
func TestBuildDerivedTomorrow(t *testing.T) {
location := testLocation()
for _, id := range []report.ID{report.Tomorrow} {