diff --git a/apps/api_web/lib/api_web/views/prediction_view.ex b/apps/api_web/lib/api_web/views/prediction_view.ex index 6f4505cb..63bf7252 100644 --- a/apps/api_web/lib/api_web/views/prediction_view.ex +++ b/apps/api_web/lib/api_web/views/prediction_view.ex @@ -153,8 +153,8 @@ defmodule ApiWeb.PredictionView do optional_relationship("stop", stop_id, &State.Stop.by_id/1, conn) end - def id(%{trip_id: trip_id, stop_id: stop_id, stop_sequence: seq}, _conn) do - "prediction-#{trip_id}-#{stop_id}-#{seq}" + def id(%{trip_id: trip_id, stop_id: stop_id, stop_sequence: seq, route_id: route_id}, _conn) do + "prediction-#{trip_id}-#{stop_id}-#{seq}-#{route_id}" end def schedule(%{schedule: schedule}, _conn), do: schedule diff --git a/apps/api_web/test/api_web/controllers/trip_controller_test.exs b/apps/api_web/test/api_web/controllers/trip_controller_test.exs index b7f42771..599839c7 100644 --- a/apps/api_web/test/api_web/controllers/trip_controller_test.exs +++ b/apps/api_web/test/api_web/controllers/trip_controller_test.exs @@ -296,7 +296,7 @@ defmodule ApiWeb.TripControllerTest do "id" => "trip", "relationships" => %{ "predictions" => %{ - "data" => [%{"id" => "prediction-trip-stop-", "type" => "prediction"}] + "data" => [%{"id" => "prediction-trip-stop--", "type" => "prediction"}] } } } = json_response(conn, 200)["data"] diff --git a/apps/api_web/test/api_web/views/prediction_view_test.exs b/apps/api_web/test/api_web/views/prediction_view_test.exs index 96258e3e..64d2ebf6 100644 --- a/apps/api_web/test/api_web/views/prediction_view_test.exs +++ b/apps/api_web/test/api_web/views/prediction_view_test.exs @@ -92,6 +92,12 @@ defmodule ApiWeb.PredictionViewTest do } end + test "includes a unique record identifier by trip, stop, stop seq, and route", %{conn: conn} do + rendered = render(ApiWeb.PredictionView, "index.json-api", data: @prediction, conn: conn) + + assert rendered["data"]["id"] == "prediction-trip-North Station-02-5-CR-Lowell" + end + test "includes trip/stop/route/vehicle relationships by default", %{conn: conn} do rendered = render(ApiWeb.PredictionView, "index.json-api", data: @prediction, conn: conn) diff --git a/apps/api_web/test/api_web/views/schedule_view_test.exs b/apps/api_web/test/api_web/views/schedule_view_test.exs index 7f413ce1..1930da8e 100644 --- a/apps/api_web/test/api_web/views/schedule_view_test.exs +++ b/apps/api_web/test/api_web/views/schedule_view_test.exs @@ -93,7 +93,7 @@ defmodule ApiWeb.ScheduleViewTest do |> render("index.json-api", data: @schedule, conn: conn, opts: %{include: "prediction"}) |> get_in(["data", "relationships", "prediction", "data", "id"]) - assert prediction_id == "prediction-trip-stop-1" + assert prediction_id == "prediction-trip-stop-1-route" end test "does not return a prediction if not explicitly requested", %{conn: conn} do