Skip to content

Commit

Permalink
Give all models their own trip_id.
Browse files Browse the repository at this point in the history
  • Loading branch information
cmaddox5 committed Dec 16, 2024
1 parent ec44bb5 commit 180c1e4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion apps/api_web/test/api_web/views/api_view_helpers_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ defmodule ApiWeb.ApiViewHelpersTest do
import ApiViewHelpers

@service_id "service"
@trip_id "trip"
@trip_id "api_view_helpers_trip"
@trip %Model.Trip{
block_id: "block_id",
id: @trip_id,
Expand Down
14 changes: 8 additions & 6 deletions apps/api_web/test/api_web/views/prediction_view_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@ defmodule ApiWeb.PredictionViewTest do

alias Model.Prediction

@trip_id "prediction_view_trip"
# GMT
@datetime Timex.to_datetime(~N[2016-06-07T00:00:00], "America/New_York")
@prediction %Prediction{
trip_id: "trip",
trip_id: @trip_id,
stop_id: "North Station-02",
route_id: "CR-Lowell",
vehicle_id: "vehicle",
Expand All @@ -34,7 +35,7 @@ defmodule ApiWeb.PredictionViewTest do
]
@trips [
%Model.Trip{
id: "trip",
id: @trip_id,
route_id: "CR-Lowell",
direction_id: 1,
service_id: "service"
Expand All @@ -47,7 +48,7 @@ defmodule ApiWeb.PredictionViewTest do
}
]
@associated_schedule %Model.Schedule{
trip_id: "trip",
trip_id: @trip_id,
route_id: "CR-Lowell",
stop_id: "North Station",
direction_id: 0,
Expand Down Expand Up @@ -95,15 +96,16 @@ defmodule ApiWeb.PredictionViewTest do
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"
assert rendered["data"]["id"] ==
"prediction-prediction_view_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)

assert rendered["data"]["relationships"] ==
%{
"trip" => %{"data" => %{"type" => "trip", "id" => "trip"}},
"trip" => %{"data" => %{"type" => "trip", "id" => @trip_id}},
"stop" => %{"data" => %{"type" => "stop", "id" => "North Station-02"}},
"route" => %{"data" => %{"type" => "route", "id" => "CR-Lowell"}},
"vehicle" => %{"data" => %{"type" => "vehicle", "id" => "vehicle"}}
Expand Down Expand Up @@ -151,7 +153,7 @@ defmodule ApiWeb.PredictionViewTest do
|> render("index.json-api", data: prediction, conn: conn)
|> get_in(["data", "relationships", "schedule", "data", "id"])

assert schedule_id == "schedule-trip-North Station-5"
assert schedule_id == "schedule-prediction_view_trip-North Station-5"
end

test "does not return a schedule if not explicitly requested", %{conn: conn} do
Expand Down
12 changes: 7 additions & 5 deletions apps/api_web/test/api_web/views/schedule_view_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ defmodule ApiWeb.ScheduleViewTest do

alias Model.Schedule

@trip_id "schedule_view_trip"

@schedule %Schedule{
trip_id: "trip",
trip_id: @trip_id,
route_id: "route",
stop_id: "stop",
direction_id: 1,
Expand Down Expand Up @@ -67,7 +69,7 @@ defmodule ApiWeb.ScheduleViewTest do

associated_prediction = %Model.Prediction{
route_id: "route",
trip_id: "trip",
trip_id: @trip_id,
stop_id: "stop",
stop_sequence: 1,
direction_id: 1,
Expand All @@ -93,15 +95,15 @@ 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-route"
assert prediction_id == "prediction-#{@trip_id}-stop-1-route"
end

test "does not return a prediction if not explicitly requested", %{conn: conn} do
today = Timex.to_datetime(~D[2016-06-07], "America/New_York")

associated_prediction = %Model.Prediction{
route_id: "route",
trip_id: "trip",
trip_id: @trip_id,
stop_id: "stop",
stop_sequence: 1,
direction_id: 1,
Expand Down Expand Up @@ -135,7 +137,7 @@ defmodule ApiWeb.ScheduleViewTest do

associated_prediction = %Model.Prediction{
route_id: "route",
trip_id: "trip",
trip_id: @trip_id,
stop_id: "stop",
stop_sequence: 1,
direction_id: 1,
Expand Down

0 comments on commit 180c1e4

Please sign in to comment.