Skip to content

Commit

Permalink
feat: inlcuded non-revenue trips in enchanced feeds
Browse files Browse the repository at this point in the history
  • Loading branch information
Whoops committed Dec 7, 2023
1 parent df0eaab commit a70463d
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 8 deletions.
2 changes: 0 additions & 2 deletions lib/concentrate/encoder/trip_updates_enhanced.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ defmodule Concentrate.Encoder.TripUpdatesEnhanced do

@impl Concentrate.Encoder
def encode_groups(groups, opts \\ []) when is_list(groups) do
groups = Enum.reject(groups, &non_revenue?/1)

message = %{
header: feed_header(opts),
entity: trip_update_feed_entity(groups, &build_stop_time_update/1, &enhanced_data/1)
Expand Down
2 changes: 0 additions & 2 deletions lib/concentrate/encoder/vehicle_positions_enhanced.ex
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ defmodule Concentrate.Encoder.VehiclePositionsEnhanced do

@impl Concentrate.Encoder
def encode_groups(groups, opts \\ []) when is_list(groups) do
groups = Enum.reject(groups, &non_revenue?/1)

message = %{
"header" => feed_header(opts),
"entity" => Enum.flat_map(groups, &build_entity/1)
Expand Down
16 changes: 14 additions & 2 deletions test/concentrate/encoder/trip_updates_enhanced_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ defmodule Concentrate.Encoder.TripUpdatesEnhancedTest do
} = encoded
end

test "Non-revenue trips are dropped" do
test "Non-revenue trips are included" do
parsed = [
TripDescriptor.new(
trip_id: "NONREV-trip",
Expand All @@ -145,7 +145,19 @@ defmodule Concentrate.Encoder.TripUpdatesEnhancedTest do
encoded = Jason.decode!(encode_groups(group(parsed)))

assert %{
"entity" => []
"entity" => [
%{
"id" => "NONREV-trip",
"trip_update" => %{
"trip" => %{
"direction_id" => 0,
"revenue" => false,
"route_id" => "route",
"trip_id" => "NONREV-trip"
}
}
}
]
} = encoded
end
end
Expand Down
18 changes: 16 additions & 2 deletions test/concentrate/encoder/vehicle_positions_enhanced_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ defmodule Concentrate.Encoder.VehiclePositionsEnhancedTest do
assert [] == FeedUpdate.updates(round_trip(data))
end

test "filters non-revenue trips" do
test "includes non-revenue trips" do
data = [
TripDescriptor.new(trip_id: "one", vehicle_id: "y1", revenue: false),
VehiclePosition.new(
Expand All @@ -78,7 +78,21 @@ defmodule Concentrate.Encoder.VehiclePositionsEnhancedTest do
)
]

assert [] == FeedUpdate.updates(round_trip(data))
assert [
%Concentrate.TripDescriptor{
trip_id: "one",
vehicle_id: "y1",
revenue: false,
schedule_relationship: :SCHEDULED
},
%Concentrate.VehiclePosition{
id: "y1",
trip_id: "one",
latitude: 1,
longitude: 1,
status: :IN_TRANSIT_TO
}
] == FeedUpdate.updates(round_trip(data))
end
end

Expand Down

0 comments on commit a70463d

Please sign in to comment.