Skip to content

Commit c021e3c

Browse files
authored
Merge pull request #1069 from ARCoder181105/fix/1012-stop-endpoint-situations
fix: Enforce empty situations array in stop endpoint
2 parents 9e73f2a + 704d64a commit c021e3c

2 files changed

Lines changed: 1 addition & 37 deletions

File tree

internal/restapi/stop_handler.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,6 @@ func (api *RestAPI) stopHandler(w http.ResponseWriter, r *http.Request) {
136136
})
137137
}
138138
}
139-
140-
// Populate situation references for alerts affecting this stop and its serving routes
141-
rawRouteIDs := make([]string, len(routes))
142-
for i, route := range routes {
143-
rawRouteIDs[i] = route.ID
144-
}
145-
alerts := api.collectAlertsForStopsAndRoutes([]string{stopID}, rawRouteIDs)
146-
situations := api.BuildSituationReferences(alerts)
147-
references.Situations = append(references.Situations, situations...)
148139
}
149140

150141
response := models.NewEntryResponse(stopData, *references, api.Clock)

internal/restapi/stop_handler_test.go

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"net/http"
77
"testing"
88

9-
"github.com/OneBusAway/go-gtfs"
109
"github.com/stretchr/testify/assert"
1110
"github.com/stretchr/testify/require"
1211
"maglev.onebusaway.org/gtfsdb"
@@ -51,6 +50,7 @@ func TestStopHandlerEndToEnd(t *testing.T) {
5150
require.Len(t, model.Data.References.Routes, len(testdata.Stop4062.RouteIDs),
5251
"references.routes count should match entry.routeIds count")
5352
assert.Equal(t, []models.AgencyReference{testdata.Raba}, model.Data.References.Agencies)
53+
assert.Empty(t, model.Data.References.Situations, "situations should always be empty for this endpoint")
5454
}
5555

5656
func TestStopHandler_NotFoundAndMalformed(t *testing.T) {
@@ -178,33 +178,6 @@ func TestStopHandlerMultiAgencyScenario(t *testing.T) {
178178
assert.True(t, agencyIDs[agencyB], "AgencyB should be in references")
179179
}
180180

181-
// TestStopHandlerWithSituations verifies that an alert informing the same
182-
// situation against multiple entities (stop + route) deduplicates to one
183-
// situation in references.
184-
func TestStopHandlerWithSituations(t *testing.T) {
185-
api := createTestApi(t)
186-
defer api.Shutdown()
187-
188-
// Real-time alerts use raw (un-prefixed) ids from the GTFS-RT feed.
189-
rawStopID := "4062" // Stop4062 = "25_4062"
190-
rawRouteID := "154" // Stop4062 is on route 25_154
191-
const alertID = "test-cross-entity-alert-789"
192-
api.GtfsManager.AddAlertForTest(gtfs.Alert{
193-
ID: alertID,
194-
InformedEntities: []gtfs.AlertInformedEntity{
195-
{StopID: &rawStopID},
196-
{RouteID: &rawRouteID},
197-
},
198-
})
199-
200-
resp, model := callAPIHandler[StopEntryResponse](t, api, stopURL(testdata.Stop4062.ID))
201-
202-
assert.Equal(t, http.StatusOK, resp.StatusCode)
203-
require.Len(t, model.Data.References.Situations, 1,
204-
"expected exactly one deduplicated situation despite matching multiple entities")
205-
assert.Equal(t, alertID, model.Data.References.Situations[0].ID)
206-
}
207-
208181
// TestStopHandler_StopCodeFallback verifies that when a stop has no stop_code
209182
// in the database (Code is a null NullString), the response falls back to
210183
// returning the raw entity portion of the combined ID as the code field.

0 commit comments

Comments
 (0)