Cleanup outlook endpoints and completed roadmap documentation
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:
@@ -1484,13 +1484,15 @@ func TestOutlookRoutesRegistered(t *testing.T) {
|
||||
for _, path := range []string{
|
||||
"/outlooks/convective",
|
||||
"/outlooks/convective/active",
|
||||
"/outlooks/convective/location",
|
||||
} {
|
||||
def := definitionForPath(t, defs, path)
|
||||
if len(def.Methods) != 1 || def.Methods[0] != http.MethodGet {
|
||||
t.Fatalf("%s: expected GET definition, got %+v", path, def.Methods)
|
||||
}
|
||||
}
|
||||
if endpointExists(defs, "/outlooks/convective/location") {
|
||||
t.Fatal("expected /outlooks/convective/location to be removed")
|
||||
}
|
||||
}
|
||||
|
||||
func TestOutlookRoutesJSONSuccess(t *testing.T) {
|
||||
@@ -1499,7 +1501,6 @@ func TestOutlookRoutesJSONSuccess(t *testing.T) {
|
||||
for _, path := range []string{
|
||||
"/outlooks/convective",
|
||||
"/outlooks/convective/active",
|
||||
"/outlooks/convective/location",
|
||||
} {
|
||||
t.Run(path, func(t *testing.T) {
|
||||
h := newHandler(t, &fakeService{outlookRun: testOutlookRun()}, path)
|
||||
@@ -1676,7 +1677,7 @@ func TestOutlookQueryParamsConstructFilter(t *testing.T) {
|
||||
h := newHandler(t, svc, "/outlooks/convective")
|
||||
|
||||
w := httptest.NewRecorder()
|
||||
req := httptest.NewRequest(http.MethodGet, "/outlooks/convective?day=2&outlookType=Tornado&containsLocation=true&tz=CDT&units=US", nil)
|
||||
req := httptest.NewRequest(http.MethodGet, "/outlooks/convective?day=2&outlookType=Tornado&tz=CDT&units=US", nil)
|
||||
h.ServeHTTP(w, req)
|
||||
|
||||
if w.Code != http.StatusOK {
|
||||
@@ -1692,15 +1693,12 @@ func TestOutlookQueryParamsConstructFilter(t *testing.T) {
|
||||
if filter.OutlookType != "tornado" {
|
||||
t.Fatalf("expected outlookType tornado, got %q", filter.OutlookType)
|
||||
}
|
||||
if filter.ContainsLocation == nil || !*filter.ContainsLocation {
|
||||
t.Fatalf("expected containsLocation true, got %+v", filter.ContainsLocation)
|
||||
}
|
||||
if filter.ActiveAt != nil {
|
||||
t.Fatalf("expected no active filter, got %v", filter.ActiveAt)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOutlookActiveAndLocationFiltersUseNow(t *testing.T) {
|
||||
func TestOutlookActiveFilterUsesNow(t *testing.T) {
|
||||
now := time.Date(2026, 6, 11, 15, 30, 0, 0, time.FixedZone("CDT", -5*3600))
|
||||
setOutlookNowForTest(t, now)
|
||||
|
||||
@@ -1716,28 +1714,6 @@ func TestOutlookActiveAndLocationFiltersUseNow(t *testing.T) {
|
||||
if activeFilter.ActiveAt == nil || !activeFilter.ActiveAt.Equal(now.UTC()) {
|
||||
t.Fatalf("expected activeAt %s, got %v", now.UTC(), activeFilter.ActiveAt)
|
||||
}
|
||||
if activeFilter.ContainsLocation != nil {
|
||||
t.Fatalf("expected active route not to force containsLocation, got %+v", activeFilter.ContainsLocation)
|
||||
}
|
||||
|
||||
locationSvc := &fakeService{outlookRun: testOutlookRun()}
|
||||
locationHandler := newHandler(t, locationSvc, "/outlooks/convective/location")
|
||||
w = httptest.NewRecorder()
|
||||
req = httptest.NewRequest(http.MethodGet, "/outlooks/convective/location?outlookType=hail", nil)
|
||||
locationHandler.ServeHTTP(w, req)
|
||||
if w.Code != http.StatusOK {
|
||||
t.Fatalf("expected location 200, got %d", w.Code)
|
||||
}
|
||||
locationFilter := locationSvc.outlookFilters[0]
|
||||
if locationFilter.ActiveAt == nil || !locationFilter.ActiveAt.Equal(now.UTC()) {
|
||||
t.Fatalf("expected location activeAt %s, got %v", now.UTC(), locationFilter.ActiveAt)
|
||||
}
|
||||
if locationFilter.ContainsLocation == nil || !*locationFilter.ContainsLocation {
|
||||
t.Fatalf("expected location route to force containsLocation true, got %+v", locationFilter.ContainsLocation)
|
||||
}
|
||||
if locationFilter.OutlookType != "hail" {
|
||||
t.Fatalf("expected outlookType hail, got %q", locationFilter.OutlookType)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOutlookInvalidQueryParamsReturnBadRequest(t *testing.T) {
|
||||
@@ -1748,10 +1724,10 @@ func TestOutlookInvalidQueryParamsReturnBadRequest(t *testing.T) {
|
||||
"/outlooks/convective?day=4",
|
||||
"/outlooks/convective?day=two",
|
||||
"/outlooks/convective?outlookType=snow",
|
||||
"/outlooks/convective?containsLocation=maybe",
|
||||
"/outlooks/convective?containsLocation=true",
|
||||
"/outlooks/convective/active?containsLocation=true",
|
||||
"/outlooks/convective?tz=not-a-timezone",
|
||||
"/outlooks/convective?tz=CDT&TZ=EST",
|
||||
"/outlooks/convective/location?containsLocation=true",
|
||||
} {
|
||||
t.Run(rawURL, func(t *testing.T) {
|
||||
h := newHandler(t, &fakeService{outlookRun: testOutlookRun()}, strings.Split(rawURL, "?")[0])
|
||||
@@ -2440,6 +2416,15 @@ func definitionForPath(t *testing.T, defs []endpoint.Definition, path string) en
|
||||
return endpoint.Definition{}
|
||||
}
|
||||
|
||||
func endpointExists(defs []endpoint.Definition, path string) bool {
|
||||
for _, def := range defs {
|
||||
if def.Path == path {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func testRenderers(t *testing.T) *render.Registry {
|
||||
t.Helper()
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ type outlookFilterMode int
|
||||
const (
|
||||
outlookFilterUser outlookFilterMode = iota
|
||||
outlookFilterActive
|
||||
outlookFilterLocation
|
||||
)
|
||||
|
||||
var outlookNow = time.Now
|
||||
@@ -27,7 +26,6 @@ func outlookDefinitions(svc Service) []endpoint.Definition {
|
||||
return []endpoint.Definition{
|
||||
outlookDefinition("/outlooks/convective", outlookFilterUser, bindOutlookQuery, svc),
|
||||
outlookDefinition("/outlooks/convective/active", outlookFilterActive, bindOutlookQuery, svc),
|
||||
outlookDefinition("/outlooks/convective/location", outlookFilterLocation, bindOutlookLocationQuery, svc),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,14 +40,10 @@ func outlookDefinition(
|
||||
binder,
|
||||
func(ctx context.Context, req outlookQueryRequest) (any, error) {
|
||||
filter := req.Filter
|
||||
if mode == outlookFilterActive || mode == outlookFilterLocation {
|
||||
if mode == outlookFilterActive {
|
||||
activeAt := outlookNow().UTC()
|
||||
filter.ActiveAt = &activeAt
|
||||
}
|
||||
if mode == outlookFilterLocation {
|
||||
containsLocation := true
|
||||
filter.ContainsLocation = &containsLocation
|
||||
}
|
||||
|
||||
run, err := svc.LatestConvectiveOutlook(ctx, filter)
|
||||
if err != nil {
|
||||
|
||||
@@ -145,29 +145,16 @@ func bindPrecisionQueryInternal(r *http.Request, allowTimezone bool) (precisionQ
|
||||
}
|
||||
|
||||
func bindOutlookQuery(r *http.Request) (outlookQueryRequest, error) {
|
||||
return bindOutlookQueryInternal(r, true)
|
||||
}
|
||||
|
||||
func bindOutlookLocationQuery(r *http.Request) (outlookQueryRequest, error) {
|
||||
return bindOutlookQueryInternal(r, false)
|
||||
}
|
||||
|
||||
func bindOutlookQueryInternal(r *http.Request, allowContainsLocation bool) (outlookQueryRequest, error) {
|
||||
normalizeCommonQueryValue(r, "units")
|
||||
normalizeCommonQueryValue(r, "format")
|
||||
normalizeCommonQueryValue(r, "outlookType")
|
||||
|
||||
allowedExtra := []string{"tz", "TZ", "day", "outlookType"}
|
||||
if allowContainsLocation {
|
||||
allowedExtra = append(allowedExtra, "containsLocation")
|
||||
}
|
||||
|
||||
common, err := bind.CommonQueryParams(r, bind.QueryPolicy{
|
||||
AllowUnits: true,
|
||||
AllowFormat: true,
|
||||
DefaultUnits: string(presenter.UnitsMetric),
|
||||
RejectUnknown: true,
|
||||
}, allowedExtra...)
|
||||
}, "tz", "TZ", "day", "outlookType")
|
||||
if err != nil {
|
||||
return outlookQueryRequest{}, err
|
||||
}
|
||||
@@ -182,7 +169,7 @@ func bindOutlookQueryInternal(r *http.Request, allowContainsLocation bool) (outl
|
||||
return outlookQueryRequest{}, err
|
||||
}
|
||||
|
||||
filter, err := bindOutlookFilter(r, allowContainsLocation)
|
||||
filter, err := bindOutlookFilter(r)
|
||||
if err != nil {
|
||||
return outlookQueryRequest{}, err
|
||||
}
|
||||
@@ -194,7 +181,7 @@ func bindOutlookQueryInternal(r *http.Request, allowContainsLocation bool) (outl
|
||||
}, nil
|
||||
}
|
||||
|
||||
func bindOutlookFilter(r *http.Request, allowContainsLocation bool) (app.OutlookFilter, error) {
|
||||
func bindOutlookFilter(r *http.Request) (app.OutlookFilter, error) {
|
||||
var filter app.OutlookFilter
|
||||
|
||||
if strings.TrimSpace(r.URL.Query().Get("day")) != "" {
|
||||
@@ -218,16 +205,5 @@ func bindOutlookFilter(r *http.Request, allowContainsLocation bool) (app.Outlook
|
||||
}
|
||||
}
|
||||
|
||||
if strings.TrimSpace(r.URL.Query().Get("containsLocation")) != "" {
|
||||
if !allowContainsLocation {
|
||||
return app.OutlookFilter{}, apierrors.InvalidParameter("containsLocation is not allowed on this endpoint")
|
||||
}
|
||||
containsLocation, err := bind.OptionalBool(r, "containsLocation", false)
|
||||
if err != nil {
|
||||
return app.OutlookFilter{}, err
|
||||
}
|
||||
filter.ContainsLocation = &containsLocation
|
||||
}
|
||||
|
||||
return filter, nil
|
||||
}
|
||||
|
||||
@@ -25,10 +25,9 @@ type Repository interface {
|
||||
|
||||
// OutlookFilter selects outlook entries from the latest convective outlook run.
|
||||
type OutlookFilter struct {
|
||||
Day *int
|
||||
OutlookType string
|
||||
ContainsLocation *bool
|
||||
ActiveAt *time.Time
|
||||
Day *int
|
||||
OutlookType string
|
||||
ActiveAt *time.Time
|
||||
}
|
||||
|
||||
// Service provides weather read use-cases.
|
||||
@@ -120,9 +119,6 @@ func matchesOutlookFilter(outlook model.WeatherOutlook, filter OutlookFilter) bo
|
||||
if filter.OutlookType != "" && outlook.OutlookType != normalizeOutlookType(filter.OutlookType) {
|
||||
return false
|
||||
}
|
||||
if filter.ContainsLocation != nil && outlook.ContainsLocation != *filter.ContainsLocation {
|
||||
return false
|
||||
}
|
||||
if filter.ActiveAt != nil && (filter.ActiveAt.Before(outlook.ValidFrom) || !filter.ActiveAt.Before(outlook.ValidTo)) {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -358,32 +358,6 @@ func TestServiceLatestConvectiveOutlookFiltersByOutlookType(t *testing.T) {
|
||||
assertDiscussionDays(t, run, []int{1})
|
||||
}
|
||||
|
||||
func TestServiceLatestConvectiveOutlookFiltersByContainsLocation(t *testing.T) {
|
||||
containsLocation := true
|
||||
repo := &fakeRepository{outlookRun: testOutlookRun()}
|
||||
svc := NewService(repo)
|
||||
|
||||
run, err := svc.LatestConvectiveOutlook(context.Background(), OutlookFilter{ContainsLocation: &containsLocation})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
assertOutlookIDs(t, run, []string{"cat-1", "tor-1", "day-2"})
|
||||
assertDiscussionDays(t, run, []int{1, 2})
|
||||
}
|
||||
|
||||
func TestServiceLatestConvectiveOutlookContainsLocationFalseReturnsEmptyRun(t *testing.T) {
|
||||
containsLocation := false
|
||||
repo := &fakeRepository{outlookRun: testOutlookRun()}
|
||||
svc := NewService(repo)
|
||||
|
||||
run, err := svc.LatestConvectiveOutlook(context.Background(), OutlookFilter{ContainsLocation: &containsLocation})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
assertOutlookIDs(t, run, nil)
|
||||
assertDiscussionDays(t, run, nil)
|
||||
}
|
||||
|
||||
func TestServiceLatestConvectiveOutlookFiltersByActiveAt(t *testing.T) {
|
||||
activeAt := time.Date(2026, 6, 11, 15, 0, 0, 0, time.UTC)
|
||||
repo := &fakeRepository{outlookRun: testOutlookRun()}
|
||||
@@ -399,16 +373,14 @@ func TestServiceLatestConvectiveOutlookFiltersByActiveAt(t *testing.T) {
|
||||
|
||||
func TestServiceLatestConvectiveOutlookCombinesFilters(t *testing.T) {
|
||||
day := 1
|
||||
containsLocation := true
|
||||
activeAt := time.Date(2026, 6, 11, 15, 0, 0, 0, time.UTC)
|
||||
repo := &fakeRepository{outlookRun: testOutlookRun()}
|
||||
svc := NewService(repo)
|
||||
|
||||
run, err := svc.LatestConvectiveOutlook(context.Background(), OutlookFilter{
|
||||
Day: &day,
|
||||
OutlookType: "categorical",
|
||||
ContainsLocation: &containsLocation,
|
||||
ActiveAt: &activeAt,
|
||||
Day: &day,
|
||||
OutlookType: "categorical",
|
||||
ActiveAt: &activeAt,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
|
||||
Reference in New Issue
Block a user