100 lines
3.3 KiB
Go
100 lines
3.3 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 TestWeekendBriefingBuildsPlanningInputs(t *testing.T) {
|
|
location := mustLocation(t)
|
|
resolved, err := report.Resolve(report.Weekend, report.ResolveRequest{
|
|
Now: mustParse("2026-05-29T08:00:00-05:00"),
|
|
Location: location,
|
|
})
|
|
if err != nil {
|
|
t.Fatalf("resolve weekend: %v", err)
|
|
}
|
|
precip := 70.0
|
|
gust := 32.0
|
|
summaries := []forecast.DailySummary{
|
|
{
|
|
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: "Showers and thunderstorms",
|
|
Period: timeutil.Period{
|
|
Start: mustParse("2026-05-30T12:00:00-05:00"),
|
|
End: mustParse("2026-05-30T18:00:00-05:00"),
|
|
},
|
|
MaxPrecipitationProbability: &forecast.TimedValue{
|
|
Value: precip,
|
|
Time: mustParse("2026-05-30T15:00:00-05:00"),
|
|
},
|
|
PeakWindGust: &forecast.TimedValue{
|
|
Value: gust,
|
|
Time: mustParse("2026-05-30T16:00:00-05:00"),
|
|
},
|
|
Indicators: forecast.Indicators{Wind: true},
|
|
HourlyPeriods: []forecast.ForecastPeriod{
|
|
{
|
|
StartTime: mustParse("2026-05-30T15:00:00-05:00"),
|
|
EndTime: mustParse("2026-05-30T16:00:00-05:00"),
|
|
TextDescription: "Showers and thunderstorms",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
AlertOverlaps: []forecast.AlertOverlap{{Event: "Flood Watch"}},
|
|
Discussion: &forecast.Discussion{
|
|
Product: "discussion",
|
|
KeyMessages: []string{"Timing may shift."},
|
|
ShortTerm: &forecast.DiscussionSection{Text: "Short-term showers exit before the weekend."},
|
|
LongTerm: &forecast.DiscussionSection{Text: "Long-term weekend rain timing remains uncertain."},
|
|
},
|
|
},
|
|
}
|
|
|
|
pkg, err := BuildWeekend(BuildContext{
|
|
Resolved: resolved,
|
|
Units: "us",
|
|
Timezone: "America/Chicago",
|
|
}, summaries)
|
|
if err != nil {
|
|
t.Fatalf("BuildWeekend() error = %v", err)
|
|
}
|
|
|
|
if pkg.Metadata.ReportID != report.Weekend {
|
|
t.Fatalf("ReportID = %q, want weekend", pkg.Metadata.ReportID)
|
|
}
|
|
if pkg.Weekend == nil {
|
|
t.Fatal("Weekend = nil")
|
|
}
|
|
if len(pkg.Weekend.Days) != 1 {
|
|
t.Fatalf("Days length = %d, want 1", len(pkg.Weekend.Days))
|
|
}
|
|
if len(pkg.Weekend.Planning.WorstWeatherWindows) == 0 {
|
|
t.Fatalf("WorstWeatherWindows = %#v, want weather window", pkg.Weekend.Planning.WorstWeatherWindows)
|
|
}
|
|
if !strings.Contains(strings.Join(pkg.Weekend.Planning.RainStormTiming, " "), "precipitation") {
|
|
t.Fatalf("RainStormTiming = %#v, want precipitation timing", pkg.Weekend.Planning.RainStormTiming)
|
|
}
|
|
if len(pkg.Weekend.Planning.UncertaintyInputs) == 0 {
|
|
t.Fatal("UncertaintyInputs length = 0, want discussion context")
|
|
}
|
|
if pkg.Weekend.Discussion.ShortTerm != "Short-term showers exit before the weekend." {
|
|
t.Fatalf("Discussion.ShortTerm = %q, want short-term AFD narrative", pkg.Weekend.Discussion.ShortTerm)
|
|
}
|
|
if pkg.Weekend.Discussion.LongTerm != "Long-term weekend rain timing remains uncertain." {
|
|
t.Fatalf("Discussion.LongTerm = %q, want long-term AFD narrative", pkg.Weekend.Discussion.LongTerm)
|
|
}
|
|
}
|