Add outlook v2 model contract
This commit is contained in:
@@ -76,8 +76,7 @@ func buildConvectiveOutlook(bundle spcprovider.RawConvectiveOutlookBundle, fallb
|
||||
if err := validateProductMetadata(product); err != nil {
|
||||
return model.WeatherOutlookRun{}, time.Time{}, err
|
||||
}
|
||||
discussion, ok := discussions[product.Day]
|
||||
if !ok {
|
||||
if _, ok := discussions[product.Day]; !ok {
|
||||
return model.WeatherOutlookRun{}, time.Time{}, fmt.Errorf("product %s: discussion for day %d is required", product.Key, product.Day)
|
||||
}
|
||||
|
||||
@@ -98,7 +97,7 @@ func buildConvectiveOutlook(bundle spcprovider.RawConvectiveOutlookBundle, fallb
|
||||
continue
|
||||
}
|
||||
|
||||
outlook, err := mapFeature(product, feature, i, point, discussion)
|
||||
outlook, err := mapFeature(product, feature, i, point)
|
||||
if err != nil {
|
||||
return model.WeatherOutlookRun{}, time.Time{}, err
|
||||
}
|
||||
@@ -219,7 +218,7 @@ func validateProductMetadata(product spcprovider.RawOutlookProduct) error {
|
||||
}
|
||||
}
|
||||
|
||||
func mapFeature(product spcprovider.RawOutlookProduct, feature spcprovider.GeoJSONFeature, index int, point geo.Point, discussion parsedDiscussion) (model.WeatherOutlook, error) {
|
||||
func mapFeature(product spcprovider.RawOutlookProduct, feature spcprovider.GeoJSONFeature, index int, point geo.Point) (model.WeatherOutlook, error) {
|
||||
fieldPrefix := fmt.Sprintf("product %s feature %d", product.Key, index)
|
||||
props := feature.Properties
|
||||
|
||||
@@ -264,9 +263,6 @@ func mapFeature(product spcprovider.RawOutlookProduct, feature spcprovider.GeoJS
|
||||
IssuedAt: issuedAt,
|
||||
ExpiresAt: validTo,
|
||||
Forecaster: strings.TrimSpace(props.Forecaster),
|
||||
Headline: discussion.Headline,
|
||||
Summary: discussion.Summary,
|
||||
Discussion: discussion.Discussion,
|
||||
SourceURL: strings.TrimSpace(product.URL),
|
||||
ImageURL: "",
|
||||
ContainsLocation: containsLocation,
|
||||
|
||||
@@ -88,18 +88,6 @@ func TestConvectiveOutlookNormalizerProducesCanonicalSchemaAndMapsSample(t *test
|
||||
if !got.ContainsLocation {
|
||||
t.Fatalf("ContainsLocation = false, want true")
|
||||
}
|
||||
if got.Headline != "Day 1 Convective Outlook" {
|
||||
t.Fatalf("Headline = %q", got.Headline)
|
||||
}
|
||||
if !strings.Contains(got.Summary, "central Plains") {
|
||||
t.Fatalf("Summary = %q", got.Summary)
|
||||
}
|
||||
if !strings.Contains(got.Discussion, "...DISCUSSION...") {
|
||||
t.Fatalf("Discussion missing product text: %q", got.Discussion)
|
||||
}
|
||||
if !strings.HasPrefix(got.Discussion, "SPC AC 111234") {
|
||||
t.Fatalf("Discussion = %q, want SPC product code prefix", got.Discussion)
|
||||
}
|
||||
if got.ID != "spc-convective-day1-categorical-slgt-2026-06-11T12:34:56Z-2026-06-11T13:00:00Z-0" {
|
||||
t.Fatalf("ID = %q", got.ID)
|
||||
}
|
||||
@@ -212,7 +200,8 @@ func TestConvectiveOutlookNormalizerContainsLocationFalseOutsidePolygon(t *testi
|
||||
}
|
||||
|
||||
func TestConvectiveOutlookNormalizerPreservesCorrectionMarker(t *testing.T) {
|
||||
out, err := (ConvectiveOutlookNormalizer{}).Normalize(nil, spcRawEvent(t, spcBundle(t, 0, 0)))
|
||||
bundle := spcBundle(t, 0, 0)
|
||||
out, err := (ConvectiveOutlookNormalizer{}).Normalize(nil, spcRawEvent(t, bundle))
|
||||
if err != nil {
|
||||
t.Fatalf("Normalize() error = %v", err)
|
||||
}
|
||||
@@ -221,11 +210,15 @@ func TestConvectiveOutlookNormalizerPreservesCorrectionMarker(t *testing.T) {
|
||||
if got == nil {
|
||||
t.Fatalf("missing day 2 tornado outlook")
|
||||
}
|
||||
if !strings.Contains(got.Headline, "CORR 1") {
|
||||
t.Fatalf("Headline = %q, want correction marker", got.Headline)
|
||||
discussions, _, err := parseDiscussions(bundle.Discussions)
|
||||
if err != nil {
|
||||
t.Fatalf("parseDiscussions() error = %v", err)
|
||||
}
|
||||
if !strings.Contains(got.Discussion, "CORR 1") {
|
||||
t.Fatalf("Discussion = %q, want correction marker", got.Discussion)
|
||||
if !strings.Contains(discussions[2].Headline, "CORR 1") {
|
||||
t.Fatalf("day 2 headline = %q, want correction marker", discussions[2].Headline)
|
||||
}
|
||||
if !strings.Contains(discussions[2].Discussion, "CORR 1") {
|
||||
t.Fatalf("day 2 discussion = %q, want correction marker", discussions[2].Discussion)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -306,7 +299,7 @@ func TestConvectiveOutlookNormalizerOutputJSONShape(t *testing.T) {
|
||||
t.Fatalf("payload JSON missing %s: %s", want, got)
|
||||
}
|
||||
}
|
||||
for _, unwanted := range []string{`"products"`, `"discussions"`, `"fetchedAt"`, `"body"`} {
|
||||
for _, unwanted := range []string{`"products"`, `"fetchedAt"`, `"body"`} {
|
||||
if strings.Contains(got, unwanted) {
|
||||
t.Fatalf("payload JSON exposed raw key %s: %s", unwanted, got)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user