Normalize briefing module options and weather stories
This commit is contained in:
@@ -4,6 +4,7 @@ package weatherdata
|
||||
import (
|
||||
"encoding/json"
|
||||
"math"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -180,6 +181,15 @@ type WeatherStory struct {
|
||||
DownloadURL string `json:"downloadUrl,omitempty"`
|
||||
}
|
||||
|
||||
// HasUsableContent reports whether the weather story contains displayable content or a valid period.
|
||||
func (s WeatherStory) HasUsableContent() bool {
|
||||
return strings.TrimSpace(s.Title) != "" ||
|
||||
strings.TrimSpace(s.Description) != "" ||
|
||||
strings.TrimSpace(s.AltText) != "" ||
|
||||
strings.TrimSpace(s.DownloadURL) != "" ||
|
||||
(!s.StartTime.IsZero() && !s.EndTime.IsZero() && s.EndTime.After(s.StartTime))
|
||||
}
|
||||
|
||||
type ConvectiveOutlookRun struct {
|
||||
LocationID string `json:"locationId,omitempty"`
|
||||
LocationName string `json:"locationName,omitempty"`
|
||||
|
||||
@@ -117,6 +117,31 @@ func TestForecastPeriodHasValidPrecipitationProbability(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestWeatherStoryHasUsableContent(t *testing.T) {
|
||||
start := mustParseBundleTime("2026-05-29T13:00:00Z")
|
||||
end := mustParseBundleTime("2026-05-29T14:00:00Z")
|
||||
for _, tt := range []struct {
|
||||
name string
|
||||
story WeatherStory
|
||||
want bool
|
||||
}{
|
||||
{name: "empty"},
|
||||
{name: "whitespace title", story: WeatherStory{Title: " \t "}},
|
||||
{name: "title", story: WeatherStory{Title: "Rain Chances"}, want: true},
|
||||
{name: "description", story: WeatherStory{Description: "Showers expected."}, want: true},
|
||||
{name: "alternate text", story: WeatherStory{AltText: "Rain chances graphic"}, want: true},
|
||||
{name: "download URL", story: WeatherStory{DownloadURL: "https://example.invalid/story.png"}, want: true},
|
||||
{name: "valid period", story: WeatherStory{StartTime: start, EndTime: end}, want: true},
|
||||
{name: "reversed period", story: WeatherStory{StartTime: end, EndTime: start}},
|
||||
} {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := tt.story.HasUsableContent(); got != tt.want {
|
||||
t.Fatalf("HasUsableContent() = %t, want %t", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func mustParseBundleTime(value string) time.Time {
|
||||
parsed, err := time.Parse(time.RFC3339, value)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user