95 lines
3.0 KiB
Go
95 lines
3.0 KiB
Go
package briefing
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
|
|
"gitea.maximumdirect.net/eric/weatherreporter/internal/forecast"
|
|
"gitea.maximumdirect.net/eric/weatherreporter/internal/report"
|
|
"gitea.maximumdirect.net/eric/weatherreporter/internal/timeutil"
|
|
)
|
|
|
|
func TestThreeDayBriefingBuildsOutlookDays(t *testing.T) {
|
|
location := mustLocation(t)
|
|
resolved, err := report.Resolve(report.ThreeDay, report.ResolveRequest{
|
|
Now: mustParse("2026-05-29T06:00:00-05:00"),
|
|
Location: location,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("resolve 3-day: %v", err)
|
|
}
|
|
precip := 70.0
|
|
gust := 35.0
|
|
summaries := []forecast.DailySummary{
|
|
{
|
|
Date: "2026-05-29",
|
|
Period: timeutil.Period{
|
|
Start: mustParse("2026-05-29T06:00:00-05:00"),
|
|
End: mustParse("2026-05-30T00:00:00-05:00"),
|
|
},
|
|
Dayparts: []forecast.DaypartSummary{
|
|
{
|
|
Name: "morning",
|
|
DominantCondition: "Showers and thunderstorms",
|
|
MaxPrecipitationProbability: &forecast.TimedValue{
|
|
Value: precip,
|
|
Time: mustParse("2026-05-29T09:00:00-05:00"),
|
|
},
|
|
PeakWindGust: &forecast.TimedValue{
|
|
Value: gust,
|
|
Time: mustParse("2026-05-29T10:00:00-05:00"),
|
|
},
|
|
Indicators: forecast.Indicators{Wind: true},
|
|
},
|
|
},
|
|
AlertOverlaps: []forecast.AlertOverlap{{Event: "Flood Watch"}},
|
|
Discussion: &forecast.Discussion{
|
|
Product: "discussion",
|
|
KeyMessages: []string{"Unsettled stretch."},
|
|
ShortTerm: &forecast.DiscussionSection{Text: "Short-term rain chances remain focused today."},
|
|
LongTerm: &forecast.DiscussionSection{Text: "Long-term warmth builds into the weekend."},
|
|
},
|
|
},
|
|
{
|
|
Date: "2026-05-30",
|
|
Period: timeutil.Period{
|
|
Start: mustParse("2026-05-30T00:00:00-05:00"),
|
|
End: mustParse("2026-05-31T00:00:00-05:00"),
|
|
},
|
|
Dayparts: []forecast.DaypartSummary{{Name: "afternoon", DominantCondition: "Clear"}},
|
|
},
|
|
}
|
|
|
|
pkg, err := BuildThreeDay(BuildContext{
|
|
Resolved: resolved,
|
|
Units: "us",
|
|
Timezone: "America/Chicago",
|
|
}, summaries)
|
|
if err != nil {
|
|
t.Fatalf("BuildThreeDay() error = %v", err)
|
|
}
|
|
|
|
if pkg.Metadata.ReportID != report.ThreeDay {
|
|
t.Fatalf("ReportID = %q, want three_day", pkg.Metadata.ReportID)
|
|
}
|
|
if pkg.ThreeDay == nil {
|
|
t.Fatal("ThreeDay = nil")
|
|
}
|
|
if len(pkg.ThreeDay.Days) != 2 {
|
|
t.Fatalf("Days length = %d, want 2", len(pkg.ThreeDay.Days))
|
|
}
|
|
first := pkg.ThreeDay.Days[0]
|
|
if !strings.Contains(first.OverallCharacter, "Showers") || !strings.Contains(strings.Join(first.Risks, ","), "wind") {
|
|
t.Fatalf("first day = %#v, want conditions and risks", first)
|
|
}
|
|
if len(pkg.ThreeDay.RelevantAlerts) != 1 {
|
|
t.Fatalf("RelevantAlerts length = %d, want 1", len(pkg.ThreeDay.RelevantAlerts))
|
|
}
|
|
if pkg.ThreeDay.Discussion.ShortTerm != "Short-term rain chances remain focused today." {
|
|
t.Fatalf("Discussion.ShortTerm = %q, want short-term AFD narrative", pkg.ThreeDay.Discussion.ShortTerm)
|
|
}
|
|
if pkg.ThreeDay.Discussion.LongTerm != "Long-term warmth builds into the weekend." {
|
|
t.Fatalf("Discussion.LongTerm = %q, want long-term AFD narrative", pkg.ThreeDay.Discussion.LongTerm)
|
|
}
|
|
}
|