Skip to content
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
5 changes: 3 additions & 2 deletions lib/dotcom/schedule_finder/upcoming_departures.ex
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,10 @@ defmodule Dotcom.ScheduleFinder.UpcomingDepartures do
},
schedule: schedule
},
route_type: :commuter_rail
route_type: route_type
})
when schedule_relationship in [:cancelled, :skipped] do
when schedule_relationship in [:cancelled, :skipped] and
route_type in [:bus, :commuter_rail] do
{:cancelled, schedule.departure_time}
end

Expand Down
69 changes: 65 additions & 4 deletions test/dotcom/schedule_finder/upcoming_departures_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -1858,11 +1858,11 @@ defmodule Dotcom.ScheduleFinder.UpcomingDeparturesTest do
assert departure.arrival_substatus == {:status, display_status}
end

test "shows :cancelled for commuter rail if the schedule_relationship is :cancelled or :skipped" do
test "shows :cancelled for commuter rail or bus if the schedule_relationship is :cancelled or :skipped" do
# Setup
now = Dotcom.Utils.DateTime.now()

route = Factories.Routes.Route.build(:commuter_rail_route)
route = Factories.Routes.Route.build(Faker.Util.pick([:commuter_rail_route, :bus_route]))
route_id = route.id
stop_id = FactoryHelpers.build(:id)

Expand Down Expand Up @@ -1918,14 +1918,75 @@ defmodule Dotcom.ScheduleFinder.UpcomingDeparturesTest do
# Verify
assert [departure] = departures
assert departure.arrival_status == {:cancelled, scheduled_departure_time}
end

test "shows the schedule relationship as a substatus if it's :skipped or :cancelled for CR" do
# Setup
now = Dotcom.Utils.DateTime.now()

route = Factories.Routes.Route.build(:commuter_rail_route)
route_id = route.id
stop_id = FactoryHelpers.build(:id)

trip = Factories.Schedules.Trip.build(:trip)
direction_id = Faker.Util.pick([0, 1])

scheduled_departure_time =
Generators.DateTime.random_time_range_date_time(
{now, ServiceDateTime.end_of_service_day(now)}
)

schedule_relationship = Faker.Util.pick([:cancelled, :skipped])

expect(Predictions.Repo.Mock, :all, fn [
route: ^route_id,
direction_id: ^direction_id,
include_terminals: true
] ->
[
Factories.Predictions.Prediction.build(:prediction,
arrival_time: nil,
departure_time: nil,
stop: Factories.Stops.Stop.build(:stop, id: stop_id),
schedule_relationship: schedule_relationship,
trip: trip
)
]
end)

expect(Schedules.Repo.Mock, :by_route_ids, fn
[^route_id], direction_id: ^direction_id, date: date ->
assert date == ServiceDateTime.service_date(now)

[
Factories.Schedules.Schedule.build(:schedule,
departure_time: scheduled_departure_time,
time: scheduled_departure_time,
stop: Factories.Stops.Stop.build(:stop, id: stop_id),
trip: trip
)
]
end)

# Exercise
departures =
UpcomingDepartures.upcoming_departures(%{
direction_id: direction_id,
now: now,
route: route,
stop_id: stop_id
})

# Verify
assert [departure] = departures
assert departure.arrival_substatus == schedule_relationship
end

test "does not include skipped or cancelled bus or subway trips" do
test "does not include skipped or cancelled subway trips" do
# Setup
now = Dotcom.Utils.DateTime.now()

route = Factories.Routes.Route.build(Faker.Util.pick([:bus_route, :subway_route]))
route = Factories.Routes.Route.build(:subway_route)
route_id = route.id
stop_id = FactoryHelpers.build(:id)

Expand Down