Updates to the nws forecast source and normalizer to separate code specific to hourly forecasts and prepare for upcoming feature addition of daily and narrative forecasts
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:
@@ -2,14 +2,18 @@ package nws
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gitea.maximumdirect.net/ejr/feedkit/event"
|
||||
"gitea.maximumdirect.net/ejr/weatherfeeder/standards"
|
||||
)
|
||||
|
||||
func TestBuildForecastUsesShortForecastAsTextDescription(t *testing.T) {
|
||||
parsed := nwsForecastResponse{}
|
||||
func TestBuildHourlyForecastUsesShortForecastAsTextDescription(t *testing.T) {
|
||||
parsed := nwsHourlyForecastResponse{}
|
||||
parsed.Properties.GeneratedAt = "2026-03-16T18:00:00Z"
|
||||
parsed.Properties.Periods = []nwsForecastPeriod{
|
||||
parsed.Properties.Periods = []nwsHourlyForecastPeriod{
|
||||
{
|
||||
StartTime: "2026-03-16T19:00:00Z",
|
||||
EndTime: "2026-03-16T20:00:00Z",
|
||||
@@ -19,9 +23,9 @@ func TestBuildForecastUsesShortForecastAsTextDescription(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
run, effectiveAt, err := buildForecast(parsed)
|
||||
run, effectiveAt, err := buildHourlyForecast(parsed)
|
||||
if err != nil {
|
||||
t.Fatalf("buildForecast() error = %v", err)
|
||||
t.Fatalf("buildHourlyForecast() error = %v", err)
|
||||
}
|
||||
if len(run.Periods) != 1 {
|
||||
t.Fatalf("periods len = %d, want 1", len(run.Periods))
|
||||
@@ -41,6 +45,31 @@ func TestBuildForecastUsesShortForecastAsTextDescription(t *testing.T) {
|
||||
assertNoLegacyForecastDescriptionKeys(t, run.Periods[0])
|
||||
}
|
||||
|
||||
func TestNormalizeForecastEventBySchemaRejectsUnsupportedSchema(t *testing.T) {
|
||||
_, err := normalizeForecastEventBySchema(event.Event{
|
||||
Schema: "raw.nws.daily.forecast.v1",
|
||||
})
|
||||
if err == nil {
|
||||
t.Fatalf("normalizeForecastEventBySchema() expected unsupported schema error")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "unsupported nws forecast schema") {
|
||||
t.Fatalf("error = %q, want unsupported schema context", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeForecastEventBySchemaRoutesHourly(t *testing.T) {
|
||||
_, err := normalizeForecastEventBySchema(event.Event{
|
||||
Schema: standards.SchemaRawNWSHourlyForecastV1,
|
||||
Payload: map[string]any{"properties": map[string]any{}},
|
||||
})
|
||||
if err == nil {
|
||||
t.Fatalf("normalizeForecastEventBySchema() expected build error for missing generatedAt")
|
||||
}
|
||||
if !strings.Contains(err.Error(), "missing properties.generatedAt") {
|
||||
t.Fatalf("error = %q, want missing properties.generatedAt", err)
|
||||
}
|
||||
}
|
||||
|
||||
func assertNoLegacyForecastDescriptionKeys(t *testing.T, period any) {
|
||||
t.Helper()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user