Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Have Realtime.TripModification take shape_id as an argument #2689

Merged
merged 1 commit into from
Jul 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 15 additions & 11 deletions lib/realtime/trip_modification.ex
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,25 @@ defmodule Realtime.TripModification do
missed_stops: [Stop.t()],
shape_with_stops: ShapeWithStops.t(),
service_date: Date.t(),
last_modified_time: DateTime.t()
last_modified_time: DateTime.t(),
shape_id: String.t()
}

@enforce_keys [
:route_pattern,
:missed_stops,
:shape_with_stops,
:service_date,
:last_modified_time
:last_modified_time,
:shape_id
]
defstruct [
:route_pattern,
:missed_stops,
:shape_with_stops,
:service_date,
:last_modified_time
:last_modified_time,
:shape_id
]
end

Expand Down Expand Up @@ -112,19 +115,19 @@ defmodule Realtime.TripModification do
...> build(:gtfs_stop, id: "ABC129")
...> ],
...> shape_with_stops: build(:shape_with_stops,
...> id: "010128",
...> stops: build_list(5, :gtfs_stop)
...> ),
...> service_date: ~D[2024-06-20],
...> last_modified_time: ~U[2024-06-18 12:00:00Z]
...> last_modified_time: ~U[2024-06-18 12:00:00Z],
...> shape_id: "diverted-shape-id"
...> }
...> )
{:ok,
%Realtime.TripModification{
selected_trips: [
%Realtime.TripModification.SelectedTrip{
trip_ids: ["01-00"],
shape_id: "010128"
shape_id: "diverted-shape-id"
}
],
service_dates: ["20240620"],
Expand Down Expand Up @@ -165,18 +168,19 @@ defmodule Realtime.TripModification do
...> ]
...> ),
...> service_date: ~D[2024-06-20],
...> last_modified_time: ~U[2024-06-18 12:00:00Z]
...> last_modified_time: ~U[2024-06-18 12:00:00Z],
...> shape_id: "diverted-shape-id"
...> }
...> )
{:error, :duplicate_stops_in_shape}
"""
def new(%Input{
route_pattern: %RoutePattern{representative_trip_id: trip_id},
missed_stops: missed_stops,
shape_with_stops:
shape_with_stops = %Schedule.ShapeWithStops{stops: original_shape_stops},
shape_with_stops: %Schedule.ShapeWithStops{stops: original_shape_stops},
service_date: service_date,
last_modified_time: last_modified_time
last_modified_time: last_modified_time,
shape_id: shape_id
}) do
has_duplicate_stops =
original_shape_stops
Expand All @@ -191,7 +195,7 @@ defmodule Realtime.TripModification do
{:ok,
%__MODULE__{
selected_trips: [
%SelectedTrip{trip_ids: [trip_id], shape_id: shape_with_stops.id}
%SelectedTrip{trip_ids: [trip_id], shape_id: shape_id}
],
service_dates: [Date.to_iso8601(service_date, :basic)],
modifications: [
Expand Down
9 changes: 5 additions & 4 deletions test/realtime/trip_modification_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ defmodule Realtime.TripModificationTest do

shape_with_stops =
build(:shape_with_stops,
id: "id-of-the-shape",
stops: build_list(5, :gtfs_stop)
)

Expand All @@ -29,14 +28,15 @@ defmodule Realtime.TripModificationTest do
missed_stops: missed_stops,
shape_with_stops: shape_with_stops,
service_date: service_date,
last_modified_time: last_modified_time
last_modified_time: last_modified_time,
shape_id: "id-of-the-diverted-shape"
}) ==
{:ok,
%TripModification{
selected_trips: [
%TripModification.SelectedTrip{
trip_ids: ["39-0-0-1"],
shape_id: "id-of-the-shape"
shape_id: "id-of-the-diverted-shape"
}
],
service_dates: [Date.to_iso8601(service_date, :basic)],
Expand Down Expand Up @@ -66,7 +66,8 @@ defmodule Realtime.TripModificationTest do
missed_stops: build_list(3, :gtfs_stop),
shape_with_stops: shape_with_stops,
service_date: Date.utc_today(),
last_modified_time: DateTime.utc_now()
last_modified_time: DateTime.utc_now(),
shape_id: "id-of-the-diverted-shape"
}) == {:error, :duplicate_stops_in_shape}
end
end
Loading