Implemented NWS weather stories support
All checks were successful
ci/woodpecker/push/build-image Pipeline was successful
All checks were successful
ci/woodpecker/push/build-image Pipeline was successful
This commit is contained in:
@@ -193,6 +193,76 @@ func TestMapPostgresEventForecastDiscussionStructPayload(t *testing.T) {
|
||||
assertAllWritesIncludeAllColumns(t, writes)
|
||||
}
|
||||
|
||||
func TestMapPostgresEventWeatherStoryStructPayload(t *testing.T) {
|
||||
run := model.WeatherStoryRun{
|
||||
OfficeID: "LSX",
|
||||
AsOf: time.Date(2026, 5, 30, 9, 0, 34, 0, time.UTC),
|
||||
Stories: []model.WeatherStory{
|
||||
{
|
||||
OfficeID: "LSX",
|
||||
StartTime: time.Date(2026, 5, 30, 8, 46, 0, 0, time.UTC),
|
||||
EndTime: time.Date(2026, 5, 31, 11, 0, 0, 0, time.UTC),
|
||||
UpdatedAt: time.Date(2026, 5, 30, 9, 0, 34, 0, time.UTC),
|
||||
Title: "Several Chances for Rain Through Monday",
|
||||
Description: "Scattered showers and thunderstorms.",
|
||||
AltText: "This slide shows the forecast.",
|
||||
Priority: true,
|
||||
Order: 1,
|
||||
DownloadURL: "https://api.weather.gov/offices/LSX/weatherstories/download/story-1",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
writes, err := mapPostgresEvent(context.Background(), testEvent(standards.SchemaWeatherStoryV1, "weather_story", run))
|
||||
if err != nil {
|
||||
t.Fatalf("mapPostgresEvent() error = %v", err)
|
||||
}
|
||||
if len(writes) != 2 {
|
||||
t.Fatalf("mapPostgresEvent() writes len = %d, want 2", len(writes))
|
||||
}
|
||||
if writes[0].Table != tableWeatherStoryRuns {
|
||||
t.Fatalf("writes[0].Table = %q, want %q", writes[0].Table, tableWeatherStoryRuns)
|
||||
}
|
||||
if got := writes[0].Values["story_count"]; got != 1 {
|
||||
t.Fatalf("weather_story_runs story_count = %#v, want 1", got)
|
||||
}
|
||||
if writes[1].Table != tableWeatherStories {
|
||||
t.Fatalf("writes[1].Table = %q, want %q", writes[1].Table, tableWeatherStories)
|
||||
}
|
||||
if got := writes[1].Values["download_url"]; got != "https://api.weather.gov/offices/LSX/weatherstories/download/story-1" {
|
||||
t.Fatalf("weather_stories download_url = %#v", got)
|
||||
}
|
||||
if got := writes[1].Values["story_order"]; got != 1 {
|
||||
t.Fatalf("weather_stories story_order = %#v, want 1", got)
|
||||
}
|
||||
|
||||
assertAllWritesIncludeAllColumns(t, writes)
|
||||
}
|
||||
|
||||
func TestMapPostgresEventWeatherStoryRejectsMissingAsOf(t *testing.T) {
|
||||
_, err := mapPostgresEvent(context.Background(), testEvent(standards.SchemaWeatherStoryV1, "weather_story", model.WeatherStoryRun{}))
|
||||
if err == nil {
|
||||
t.Fatalf("mapPostgresEvent() error = nil, want missing asOf error")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "asOf is required") {
|
||||
t.Fatalf("error = %q, want asOf context", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMapPostgresEventWeatherStoryRejectsMissingStoryTimes(t *testing.T) {
|
||||
run := model.WeatherStoryRun{
|
||||
AsOf: time.Date(2026, 5, 30, 9, 0, 34, 0, time.UTC),
|
||||
Stories: []model.WeatherStory{{Title: "missing times"}},
|
||||
}
|
||||
_, err := mapPostgresEvent(context.Background(), testEvent(standards.SchemaWeatherStoryV1, "weather_story", run))
|
||||
if err == nil {
|
||||
t.Fatalf("mapPostgresEvent() error = nil, want missing story times error")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "stories[0] startTime/endTime/updatedAt are required") {
|
||||
t.Fatalf("error = %q, want story time context", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestMapPostgresEventMapPayload(t *testing.T) {
|
||||
run := model.WeatherForecastRun{
|
||||
IssuedAt: time.Date(2026, 3, 16, 18, 0, 0, 0, time.UTC),
|
||||
|
||||
Reference in New Issue
Block a user