From 357dd15b96978cfb5ff17b9f25a34a906e2406f0 Mon Sep 17 00:00:00 2001 From: Cristen Jones Date: Tue, 17 Sep 2024 12:31:43 -0400 Subject: [PATCH] chore: consolidate trip planner modules (#2171) --- lib/dotcom/trip_plan/alerts.ex | 2 +- .../trip_plan}/fare_passes.ex | 4 +- .../trip_plan}/input_form.ex | 2 +- lib/{ => dotcom}/trip_plan/itinerary.ex | 8 +- lib/dotcom/trip_plan/itinerary_row.ex | 12 +- lib/dotcom/trip_plan/itinerary_row_list.ex | 3 +- lib/{ => dotcom}/trip_plan/leg.ex | 4 +- lib/dotcom/trip_plan/location.ex | 5 +- lib/dotcom/trip_plan/map.ex | 2 +- lib/{ => dotcom}/trip_plan/named_position.ex | 2 +- .../trip_plan}/open_trip_planner.ex | 6 +- .../trip_plan}/parser.ex | 5 +- lib/{ => dotcom}/trip_plan/personal_detail.ex | 4 +- lib/dotcom/trip_plan/query.ex | 3 +- lib/dotcom/trip_plan/related_link.ex | 2 +- lib/{ => dotcom}/trip_plan/transfer.ex | 4 +- lib/{ => dotcom}/trip_plan/transit_detail.ex | 2 +- lib/dotcom_web/{ => components}/components.ex | 0 lib/dotcom_web/components/trip_planner.ex | 8 +- .../controllers/trip_plan/feedback_csv.ex | 2 +- .../controllers/trip_plan_controller.ex | 17 +- .../index.ex => trip_planner.ex} | 2 +- .../trip_plan/_itinerary_tab.html.eex | 2 +- lib/dotcom_web/views/trip_plan_view.ex | 21 ++- livebooks/itinerary-groups.livemd | 18 +- test/dotcom/trip_plan/alerts_test.exs | 2 +- .../trip_plan}/input_form_test.exs | 4 +- .../trip_plan/itinerary_row_list_test.exs | 35 ++-- test/dotcom/trip_plan/itinerary_row_test.exs | 5 +- .../{ => dotcom}/trip_plan/itinerary_test.exs | 12 +- test/{ => dotcom}/trip_plan/leg_test.exs | 4 +- test/dotcom/trip_plan/location_test.exs | 3 +- .../trip_plan}/open_trip_planner_test.exs | 5 +- test/dotcom/trip_plan/query_test.exs | 7 +- test/dotcom/trip_plan/related_link_test.exs | 2 +- test/{ => dotcom}/trip_plan/transfer_test.exs | 6 +- .../components/trip_planner_test.exs | 10 +- .../controllers/trip_plan_controller_test.exs | 5 +- test/dotcom_web/views/trip_plan_view_test.exs | 164 ++++++++++-------- test/fares/fares_test.exs | 19 +- .../factories/trip_planner/trip_planner.ex | 3 +- 41 files changed, 219 insertions(+), 207 deletions(-) rename lib/{trip_planner => dotcom/trip_plan}/fare_passes.ex (98%) rename lib/{trip_planner => dotcom/trip_plan}/input_form.ex (98%) rename lib/{ => dotcom}/trip_plan/itinerary.ex (95%) rename lib/{ => dotcom}/trip_plan/leg.ex (97%) rename lib/{ => dotcom}/trip_plan/named_position.ex (95%) rename lib/{trip_planner => dotcom/trip_plan}/open_trip_planner.ex (91%) rename lib/{trip_planner => dotcom/trip_plan}/parser.ex (97%) rename lib/{ => dotcom}/trip_plan/personal_detail.ex (96%) rename lib/{ => dotcom}/trip_plan/transfer.ex (97%) rename lib/{ => dotcom}/trip_plan/transit_detail.ex (95%) rename lib/dotcom_web/{ => components}/components.ex (100%) rename lib/dotcom_web/live/{trip_planner/index.ex => trip_planner.ex} (98%) rename test/{trip_planner => dotcom/trip_plan}/input_form_test.exs (96%) rename test/{ => dotcom}/trip_plan/itinerary_test.exs (94%) rename test/{ => dotcom}/trip_plan/leg_test.exs (98%) rename test/{trip_planner => dotcom/trip_plan}/open_trip_planner_test.exs (92%) rename test/{ => dotcom}/trip_plan/transfer_test.exs (97%) diff --git a/lib/dotcom/trip_plan/alerts.ex b/lib/dotcom/trip_plan/alerts.ex index e3e9d9715f..6c0a033547 100644 --- a/lib/dotcom/trip_plan/alerts.ex +++ b/lib/dotcom/trip_plan/alerts.ex @@ -10,7 +10,7 @@ defmodule Dotcom.TripPlan.Alerts do alias Alerts.Alert alias Alerts.InformedEntity, as: IE - alias TripPlan.{Itinerary, Leg, TransitDetail} + alias Dotcom.TripPlan.{Itinerary, Leg, TransitDetail} @doc "Filters a list of Alerts to those relevant to the Itinerary" @spec filter_for_itinerary([Alert.t()], Itinerary.t()) :: [Alert.t()] diff --git a/lib/trip_planner/fare_passes.ex b/lib/dotcom/trip_plan/fare_passes.ex similarity index 98% rename from lib/trip_planner/fare_passes.ex rename to lib/dotcom/trip_plan/fare_passes.ex index 2e6ba75227..44cf421642 100644 --- a/lib/trip_planner/fare_passes.ex +++ b/lib/dotcom/trip_plan/fare_passes.ex @@ -1,9 +1,9 @@ -defmodule Dotcom.TripPlanner.FarePasses do +defmodule Dotcom.TripPlan.FarePasses do @moduledoc """ Computing fare passes and prices for trip plan itineraries. """ + alias Dotcom.TripPlan.{Itinerary, Leg, NamedPosition, PersonalDetail, TransitDetail} alias Fares.{Fare, Month, OneWay} - alias TripPlan.{Itinerary, Leg, NamedPosition, PersonalDetail, TransitDetail} @spec with_passes(Itinerary.t()) :: Itinerary.t() def with_passes(itinerary) do diff --git a/lib/trip_planner/input_form.ex b/lib/dotcom/trip_plan/input_form.ex similarity index 98% rename from lib/trip_planner/input_form.ex rename to lib/dotcom/trip_plan/input_form.ex index 8f3d60139d..abfa1e32dc 100644 --- a/lib/trip_planner/input_form.ex +++ b/lib/dotcom/trip_plan/input_form.ex @@ -1,4 +1,4 @@ -defmodule TripPlanner.InputForm do +defmodule Dotcom.TripPlan.InputForm do @moduledoc """ Describes the inputs users can fill to request trip plans. diff --git a/lib/trip_plan/itinerary.ex b/lib/dotcom/trip_plan/itinerary.ex similarity index 95% rename from lib/trip_plan/itinerary.ex rename to lib/dotcom/trip_plan/itinerary.ex index 7fada75152..390d8a8031 100644 --- a/lib/trip_plan/itinerary.ex +++ b/lib/dotcom/trip_plan/itinerary.ex @@ -1,4 +1,4 @@ -defmodule TripPlan.Itinerary do +defmodule Dotcom.TripPlan.Itinerary do @moduledoc """ A trip at a particular time. @@ -7,11 +7,11 @@ defmodule TripPlan.Itinerary do at different times of day. """ + alias Dotcom.TripPlan.{Leg, NamedPosition, TransitDetail} alias Fares.Fare alias Routes.Route alias Schedules.Trip alias Stops.Stop - alias TripPlan.{Leg, NamedPosition, TransitDetail} @derive {Jason.Encoder, except: [:passes]} @enforce_keys [:start, :stop] @@ -119,8 +119,8 @@ defmodule TripPlan.Itinerary do end end -defimpl Enumerable, for: TripPlan.Itinerary do - alias TripPlan.Leg +defimpl Enumerable, for: Dotcom.TripPlan.Itinerary do + alias Dotcom.TripPlan.Leg def count(_itinerary) do {:error, __MODULE__} diff --git a/lib/dotcom/trip_plan/itinerary_row.ex b/lib/dotcom/trip_plan/itinerary_row.ex index 6a49ccb50d..e2cb8a6d6d 100644 --- a/lib/dotcom/trip_plan/itinerary_row.ex +++ b/lib/dotcom/trip_plan/itinerary_row.ex @@ -1,10 +1,16 @@ defmodule Dotcom.TripPlan.ItineraryRow do @moduledoc false - alias Dotcom.TripPlan.IntermediateStop + alias Dotcom.TripPlan.{ + IntermediateStop, + Leg, + NamedPosition, + PersonalDetail, + PersonalDetail.Step, + TransitDetail + } + alias Routes.Route - alias TripPlan.{Leg, NamedPosition, PersonalDetail, TransitDetail} - alias TripPlan.PersonalDetail.Step defstruct stop: {nil, nil}, route: nil, diff --git a/lib/dotcom/trip_plan/itinerary_row_list.ex b/lib/dotcom/trip_plan/itinerary_row_list.ex index 6e0a003fbb..787389469c 100644 --- a/lib/dotcom/trip_plan/itinerary_row_list.ex +++ b/lib/dotcom/trip_plan/itinerary_row_list.ex @@ -5,9 +5,8 @@ defmodule Dotcom.TripPlan.ItineraryRowList do An optional to and from name can be passed in. """ - alias Dotcom.TripPlan.ItineraryRow + alias Dotcom.TripPlan.{Itinerary, ItineraryRow} alias Stops.Stop - alias TripPlan.Itinerary defstruct rows: [], destination: nil, diff --git a/lib/trip_plan/leg.ex b/lib/dotcom/trip_plan/leg.ex similarity index 97% rename from lib/trip_plan/leg.ex rename to lib/dotcom/trip_plan/leg.ex index 3beb841fe2..cc60d013e6 100644 --- a/lib/trip_plan/leg.ex +++ b/lib/dotcom/trip_plan/leg.ex @@ -1,4 +1,4 @@ -defmodule TripPlan.Leg do +defmodule Dotcom.TripPlan.Leg do @moduledoc """ A single-mode part of an Itinerary @@ -6,7 +6,7 @@ defmodule TripPlan.Leg do train, &c). Leg represents a single mode of travel during journey. """ - alias TripPlan.{NamedPosition, PersonalDetail, TransitDetail} + alias Dotcom.TripPlan.{NamedPosition, PersonalDetail, TransitDetail} @derive {Jason.Encoder, only: [:from, :to, :mode]} defstruct start: Timex.now(), diff --git a/lib/dotcom/trip_plan/location.ex b/lib/dotcom/trip_plan/location.ex index 88ad624ead..120d2b8f07 100644 --- a/lib/dotcom/trip_plan/location.ex +++ b/lib/dotcom/trip_plan/location.ex @@ -1,7 +1,6 @@ defmodule Dotcom.TripPlan.Location do - alias Dotcom.TripPlan.Query + alias Dotcom.TripPlan.{NamedPosition, Query} alias Phoenix.HTML - alias TripPlan.NamedPosition @location_service Application.compile_env!(:dotcom, :location_service) @stops_repo Application.compile_env!(:dotcom, :repo_modules)[:stops] @@ -124,7 +123,7 @@ defmodule Dotcom.TripPlan.Location do @spec do_validate_by_name(LocationService.Behaviour.result(), :to | :from, Query.t(), map) :: Query.t() defp do_validate_by_name({:ok, [%LocationService.Address{} = result | _]}, field, query, params) do - pos = TripPlan.NamedPosition.new(result) + pos = NamedPosition.new(result) query |> Map.put(field, pos) diff --git a/lib/dotcom/trip_plan/map.ex b/lib/dotcom/trip_plan/map.ex index 98608fcf0b..322ffef938 100644 --- a/lib/dotcom/trip_plan/map.ex +++ b/lib/dotcom/trip_plan/map.ex @@ -2,10 +2,10 @@ defmodule Dotcom.TripPlan.Map do @moduledoc """ Handles generating the maps displayed within the TripPlan Controller """ + alias Dotcom.TripPlan.{Leg, NamedPosition, TransitDetail} alias Leaflet.{MapData, MapData.Marker} alias Leaflet.MapData.Polyline, as: LeafletPolyline alias Routes.Route - alias TripPlan.{Leg, NamedPosition, TransitDetail} alias Util.Position @type t :: MapData.t() diff --git a/lib/trip_plan/named_position.ex b/lib/dotcom/trip_plan/named_position.ex similarity index 95% rename from lib/trip_plan/named_position.ex rename to lib/dotcom/trip_plan/named_position.ex index e23809dd20..0f77f3ee6e 100644 --- a/lib/trip_plan/named_position.ex +++ b/lib/dotcom/trip_plan/named_position.ex @@ -1,4 +1,4 @@ -defmodule TripPlan.NamedPosition do +defmodule Dotcom.TripPlan.NamedPosition do @moduledoc "Defines a position for a trip plan as a stop and/or lat/lon" @derive Jason.Encoder diff --git a/lib/trip_planner/open_trip_planner.ex b/lib/dotcom/trip_plan/open_trip_planner.ex similarity index 91% rename from lib/trip_planner/open_trip_planner.ex rename to lib/dotcom/trip_plan/open_trip_planner.ex index e55ea69383..fc4f2d837e 100644 --- a/lib/trip_planner/open_trip_planner.ex +++ b/lib/dotcom/trip_plan/open_trip_planner.ex @@ -1,10 +1,10 @@ -defmodule TripPlanner.OpenTripPlanner do +defmodule Dotcom.TripPlan.OpenTripPlanner do @moduledoc """ Makes requests to OpenTripPlanner via the OpenTripPlannerClient library, and parses the result. """ - alias Dotcom.TripPlanner.Parser + alias Dotcom.TripPlan.{NamedPosition, Parser} alias OpenTripPlannerClient.ItineraryTag.{ EarliestArrival, @@ -13,8 +13,6 @@ defmodule TripPlanner.OpenTripPlanner do ShortestTrip } - alias TripPlan.NamedPosition - @otp_module Application.compile_env!(:dotcom, :otp_module) @doc """ diff --git a/lib/trip_planner/parser.ex b/lib/dotcom/trip_plan/parser.ex similarity index 97% rename from lib/trip_planner/parser.ex rename to lib/dotcom/trip_plan/parser.ex index 795a157081..3100029828 100644 --- a/lib/trip_planner/parser.ex +++ b/lib/dotcom/trip_plan/parser.ex @@ -1,4 +1,4 @@ -defmodule Dotcom.TripPlanner.Parser do +defmodule Dotcom.TripPlan.Parser do @moduledoc """ Parse results from OpenTripPlanner: @@ -10,9 +10,8 @@ defmodule Dotcom.TripPlanner.Parser do MBTA system. """ - alias Dotcom.TripPlanner.FarePasses + alias Dotcom.TripPlan.{FarePasses, Itinerary, Leg, NamedPosition, PersonalDetail, TransitDetail} alias OpenTripPlannerClient.Schema - alias TripPlan.{Itinerary, Leg, NamedPosition, PersonalDetail, TransitDetail} @stops_repo Application.compile_env!(:dotcom, :repo_modules)[:stops] diff --git a/lib/trip_plan/personal_detail.ex b/lib/dotcom/trip_plan/personal_detail.ex similarity index 96% rename from lib/trip_plan/personal_detail.ex rename to lib/dotcom/trip_plan/personal_detail.ex index dea39466f4..05b66cff1a 100644 --- a/lib/trip_plan/personal_detail.ex +++ b/lib/dotcom/trip_plan/personal_detail.ex @@ -1,4 +1,4 @@ -defmodule TripPlan.PersonalDetail do +defmodule Dotcom.TripPlan.PersonalDetail do @moduledoc """ Additional information for legs which are taken on personal transportation """ @@ -12,7 +12,7 @@ defmodule TripPlan.PersonalDetail do } end -defmodule TripPlan.PersonalDetail.Step do +defmodule Dotcom.TripPlan.PersonalDetail.Step do @moduledoc """ A turn-by-turn direction """ diff --git a/lib/dotcom/trip_plan/query.ex b/lib/dotcom/trip_plan/query.ex index 47890b9d24..9ba7f451fc 100644 --- a/lib/dotcom/trip_plan/query.ex +++ b/lib/dotcom/trip_plan/query.ex @@ -1,8 +1,7 @@ defmodule Dotcom.TripPlan.Query do @moduledoc "Fetch trip plan via OTP and handle response" - alias TripPlan.{Itinerary, NamedPosition} - alias TripPlanner.OpenTripPlanner + alias Dotcom.TripPlan.{Itinerary, NamedPosition, OpenTripPlanner} defstruct [ :from, diff --git a/lib/dotcom/trip_plan/related_link.ex b/lib/dotcom/trip_plan/related_link.ex index ecf23e3a7b..e74a8a3c8f 100644 --- a/lib/dotcom/trip_plan/related_link.ex +++ b/lib/dotcom/trip_plan/related_link.ex @@ -8,9 +8,9 @@ defmodule Dotcom.TripPlan.RelatedLink do import DotcomWeb.Router.Helpers import PhoenixHTMLHelpers.Link, only: [link: 2] + alias Dotcom.TripPlan.{Itinerary, Leg, TransitDetail} alias DotcomWeb.PartialView.SvgIconWithCircle alias Routes.Route - alias TripPlan.{Itinerary, Leg, TransitDetail} @stops_repo Application.compile_env!(:dotcom, :repo_modules)[:stops] diff --git a/lib/trip_plan/transfer.ex b/lib/dotcom/trip_plan/transfer.ex similarity index 97% rename from lib/trip_plan/transfer.ex rename to lib/dotcom/trip_plan/transfer.ex index effa20e06b..059d5946fd 100644 --- a/lib/trip_plan/transfer.ex +++ b/lib/dotcom/trip_plan/transfer.ex @@ -1,4 +1,4 @@ -defmodule TripPlan.Transfer do +defmodule Dotcom.TripPlan.Transfer do @moduledoc """ Tools for handling logic around transfers between transit legs and modes. The MBTA allows transfers between services depending on the fare media used @@ -6,7 +6,7 @@ defmodule TripPlan.Transfer do This logic may be superseded by the upcoming fares work. """ - alias TripPlan.{Leg, NamedPosition, TransitDetail} + alias Dotcom.TripPlan.{Leg, NamedPosition, TransitDetail} @stops_repo Application.compile_env!(:dotcom, :repo_modules)[:stops] diff --git a/lib/trip_plan/transit_detail.ex b/lib/dotcom/trip_plan/transit_detail.ex similarity index 95% rename from lib/trip_plan/transit_detail.ex rename to lib/dotcom/trip_plan/transit_detail.ex index 2588d35107..536b2d7c9c 100644 --- a/lib/trip_plan/transit_detail.ex +++ b/lib/dotcom/trip_plan/transit_detail.ex @@ -1,4 +1,4 @@ -defmodule TripPlan.TransitDetail do +defmodule Dotcom.TripPlan.TransitDetail do @moduledoc """ Additional information for legs taken on public transportation """ diff --git a/lib/dotcom_web/components.ex b/lib/dotcom_web/components/components.ex similarity index 100% rename from lib/dotcom_web/components.ex rename to lib/dotcom_web/components/components.ex diff --git a/lib/dotcom_web/components/trip_planner.ex b/lib/dotcom_web/components/trip_planner.ex index d902f4ec81..41dbedfbcb 100644 --- a/lib/dotcom_web/components/trip_planner.ex +++ b/lib/dotcom_web/components/trip_planner.ex @@ -1,12 +1,10 @@ -defmodule DotcomWeb.Components.TripPlanner do +defmodule DotcomWeb.Components.TripPlannerForm do @moduledoc """ Reusable components mainly used for the Trip Planner """ - use Phoenix.Component + use DotcomWeb, :component - import DotcomWeb.Components, only: [algolia_autocomplete: 1] - - alias TripPlanner.InputForm + alias Dotcom.TripPlan.InputForm attr :id, :string attr :params, :map, default: %{} diff --git a/lib/dotcom_web/controllers/trip_plan/feedback_csv.ex b/lib/dotcom_web/controllers/trip_plan/feedback_csv.ex index 07b7b3bdd5..57d1256022 100644 --- a/lib/dotcom_web/controllers/trip_plan/feedback_csv.ex +++ b/lib/dotcom_web/controllers/trip_plan/feedback_csv.ex @@ -5,7 +5,7 @@ defmodule DotcomWeb.TripPlan.FeedbackCSV do require Logger - alias TripPlan.PersonalDetail.Step + alias Dotcom.TripPlan.PersonalDetail.Step @headers [ "generated_time", diff --git a/lib/dotcom_web/controllers/trip_plan_controller.ex b/lib/dotcom_web/controllers/trip_plan_controller.ex index 017ea3f45c..cc60b210af 100644 --- a/lib/dotcom_web/controllers/trip_plan_controller.ex +++ b/lib/dotcom_web/controllers/trip_plan_controller.ex @@ -7,10 +7,19 @@ defmodule DotcomWeb.TripPlanController do require Logger - alias Dotcom.TripPlan.{ItineraryRowList, Query, RelatedLink} + alias Dotcom.TripPlan.{ + Itinerary, + ItineraryRowList, + Leg, + NamedPosition, + PersonalDetail, + Query, + RelatedLink, + TransitDetail + } + alias Dotcom.TripPlan.Map, as: TripPlanMap alias Routes.Route - alias TripPlan.{Itinerary, Leg, NamedPosition, PersonalDetail, TransitDetail} @location_service Application.compile_env!(:dotcom, :location_service) @@ -44,7 +53,7 @@ defmodule DotcomWeb.TripPlanController do if String.match?(address, ~r/^(\-?\d+(\.\d+)?),(\-?\d+(\.\d+)?),.*$/) do [latitude, longitude, name] = String.split(address, ",", parts: 3) # Avoid extra geocode call, just use these coordinates - destination = %TripPlan.NamedPosition{ + destination = %NamedPosition{ latitude: String.to_float(latitude), longitude: String.to_float(longitude), name: name, @@ -108,7 +117,7 @@ defmodule DotcomWeb.TripPlanController do if String.match?(address, ~r/^(\-?\d+(\.\d+)?),(\-?\d+(\.\d+)?),.*$/) do [latitude, longitude, name] = String.split(address, ",", parts: 3) # Avoid extra geocode call, just use these coordinates - destination = %TripPlan.NamedPosition{ + destination = %NamedPosition{ latitude: String.to_float(latitude), longitude: String.to_float(longitude), name: name, diff --git a/lib/dotcom_web/live/trip_planner/index.ex b/lib/dotcom_web/live/trip_planner.ex similarity index 98% rename from lib/dotcom_web/live/trip_planner/index.ex rename to lib/dotcom_web/live/trip_planner.ex index 0b5a101716..01894cc657 100644 --- a/lib/dotcom_web/live/trip_planner/index.ex +++ b/lib/dotcom_web/live/trip_planner.ex @@ -7,7 +7,7 @@ defmodule DotcomWeb.Live.TripPlanner do use DotcomWeb, :live_view - import DotcomWeb.Components.TripPlanner + import DotcomWeb.Components.TripPlannerForm @form_id "trip-planner-form" diff --git a/lib/dotcom_web/templates/trip_plan/_itinerary_tab.html.eex b/lib/dotcom_web/templates/trip_plan/_itinerary_tab.html.eex index 95f0a05eea..52f70b75d7 100644 --- a/lib/dotcom_web/templates/trip_plan/_itinerary_tab.html.eex +++ b/lib/dotcom_web/templates/trip_plan/_itinerary_tab.html.eex @@ -15,6 +15,6 @@ <%= @routes |> Enum.map(&icon_for_route/1) |> Enum.intersperse(fa "angle-right") %> <%= svg "walk.svg" %> - <%= @itinerary |> TripPlan.Itinerary.walking_distance %> mi + <%= @itinerary |> Dotcom.TripPlan.Itinerary.walking_distance %> mi diff --git a/lib/dotcom_web/views/trip_plan_view.ex b/lib/dotcom_web/views/trip_plan_view.ex index 78a0e1d02d..088b790201 100644 --- a/lib/dotcom_web/views/trip_plan_view.ex +++ b/lib/dotcom_web/views/trip_plan_view.ex @@ -5,11 +5,10 @@ defmodule DotcomWeb.TripPlanView do require Routes.Route alias Fares.{Fare, Format} alias Routes.Route - alias Dotcom.TripPlan.{ItineraryRow, Query} alias DotcomWeb.PartialView.SvgIconWithCircle alias DotcomWeb.Plugs.Cookies - alias TripPlan.{Itinerary, Leg, Transfer} alias Dotcom.StopBubble + alias Dotcom.TripPlan.{Itinerary, ItineraryRow, Leg, NamedPosition, Query, Transfer} import Schedules.Repo, only: [end_of_rating: 0] @@ -79,10 +78,10 @@ defmodule DotcomWeb.TripPlanView do Fetches value to show in input field, preferring to use the geocoded Query value if one is available. """ - @spec get_input_value(Query.t() | nil, map, :to | :from) :: TripPlan.NamedPosition.t() + @spec get_input_value(Query.t() | nil, map, :to | :from) :: NamedPosition.t() def get_input_value(%Query{} = query, params, field) do case Map.get(query, field) do - pos = %TripPlan.NamedPosition{} -> + pos = %NamedPosition{} -> pos {:error, _} -> @@ -91,7 +90,7 @@ defmodule DotcomWeb.TripPlanView do end def get_input_value(nil, params, field) do - %TripPlan.NamedPosition{ + %NamedPosition{ name: Map.get(params, Atom.to_string(field)) } end @@ -322,13 +321,13 @@ defmodule DotcomWeb.TripPlanView do defp format_green_line_name("Green Line " <> branch), do: "Green Line (#{branch})" - @spec accessibility_icon(TripPlan.Itinerary.t()) :: Phoenix.HTML.Safe.t() - defp accessibility_icon(%TripPlan.Itinerary{accessible?: nil}) do + @spec accessibility_icon(Itinerary.t()) :: Phoenix.HTML.Safe.t() + defp accessibility_icon(%Itinerary{accessible?: nil}) do # Unknown accessibilityScore, so can't show a value {:safe, ""} end - defp accessibility_icon(%TripPlan.Itinerary{accessible?: accessible?}) do + defp accessibility_icon(%Itinerary{accessible?: accessible?}) do content_tag( :span, [ @@ -369,7 +368,7 @@ defmodule DotcomWeb.TripPlanView do svg_icon_with_circle(%SvgIconWithCircle{icon: route}) end - @spec datetime_from_query(nil | Dotcom.TripPlan.Query.t()) :: any() + @spec datetime_from_query(nil | Query.t()) :: any() def datetime_from_query(%Query{time: {:error, _}}), do: datetime_from_query(nil) def datetime_from_query(%Query{time: {_depart_or_arrive, dt}}), do: dt def datetime_from_query(nil), do: Util.now() |> Dotcom.TripPlan.DateTime.round_minute() @@ -581,7 +580,7 @@ defmodule DotcomWeb.TripPlanView do We have to check if there is a bus to subway transfer and manually add the transfer cost of $0.70. """ - @spec get_one_way_total_by_type(TripPlan.Itinerary.t(), Fares.fare_type()) :: non_neg_integer + @spec get_one_way_total_by_type(Itinerary.t(), Fares.fare_type()) :: non_neg_integer def get_one_way_total_by_type(itinerary, fare_type) do transit_legs = itinerary.legs @@ -635,7 +634,7 @@ defmodule DotcomWeb.TripPlanView do defp cr_prefix(%Fare{mode: :commuter_rail}), do: "Commuter Rail " defp cr_prefix(_), do: "" - @spec get_calculated_fares(TripPlan.Itinerary.t()) :: %{mode: fare_calculation} + @spec get_calculated_fares(Itinerary.t()) :: %{mode: fare_calculation} def get_calculated_fares(itinerary) do itinerary.legs |> Enum.filter(fn leg -> Leg.transit?(leg) end) diff --git a/livebooks/itinerary-groups.livemd b/livebooks/itinerary-groups.livemd index 6798a01e67..be43b5ac84 100644 --- a/livebooks/itinerary-groups.livemd +++ b/livebooks/itinerary-groups.livemd @@ -14,11 +14,11 @@ defmodule ItineraryGroups.Helpers do |> Kernel.then(&Map.put(trip, "groups", &1)) end - defp combined_leg_to_tuple(%TripPlan.Leg{mode: %TripPlan.PersonalDetail{}} = leg) do + defp combined_leg_to_tuple(%Leg{mode: %PersonalDetail{}} = leg) do unique_leg_to_tuple(leg) end - defp combined_leg_to_tuple(%TripPlan.Leg{mode: %{route: route}} = leg) do + defp combined_leg_to_tuple(%Leg{mode: %{route: route}} = leg) do {route.id, leg.from.name, leg.to.name} end @@ -65,15 +65,15 @@ defmodule ItineraryGroups.Helpers do |> :erlang.phash2() end - defp leg_to_string(%TripPlan.Leg{mode: %TripPlan.PersonalDetail{}} = leg) do + defp leg_to_string(%Leg{mode: %PersonalDetail{}} = leg) do "WALK #{leg.distance} MILES FROM #{leg.from.name} TO #{leg.to.name}" end - defp leg_to_string(%TripPlan.Leg{mode: %{mode: "BUS"} = mode} = leg) do + defp leg_to_string(%Leg{mode: %{mode: "BUS"} = mode} = leg) do "TAKE THE #{mode.route.id} BUS FROM #{leg.from.name} TO #{leg.to.name}" end - defp leg_to_string(%TripPlan.Leg{mode: %{mode: _} = mode} = leg) do + defp leg_to_string(%Leg{mode: %{mode: _} = mode} = leg) do "TAKE THE #{mode.route.long_name} #{mode.mode} FROM #{leg.from.name} TO #{leg.to.name}" end @@ -93,7 +93,7 @@ defmodule ItineraryGroups.Helpers do nil end - %TripPlan.NamedPosition{ + %NamedPosition{ stop: parent_stop || stop } end @@ -107,17 +107,17 @@ defmodule ItineraryGroups.Helpers do ) end - def short_walking_leg?(%TripPlan.Leg{mode: %TripPlan.PersonalDetail{}} = leg) do + def short_walking_leg?(%Leg{mode: %PersonalDetail{}} = leg) do leg.distance <= 0.2 end def short_walking_leg?(_), do: false - defp unique_leg_to_tuple(%TripPlan.Leg{mode: %TripPlan.PersonalDetail{}} = leg) do + defp unique_leg_to_tuple(%Leg{mode: %PersonalDetail{}} = leg) do {"WALK", leg.from.name, leg.to.name} end - defp unique_leg_to_tuple(%TripPlan.Leg{mode: %{route: route}} = leg) do + defp unique_leg_to_tuple(%Leg{mode: %{route: route}} = leg) do {Routes.Route.type_atom(route.type), leg.from.name, leg.to.name} end diff --git a/test/dotcom/trip_plan/alerts_test.exs b/test/dotcom/trip_plan/alerts_test.exs index 20f8ad5d33..216ef55b92 100644 --- a/test/dotcom/trip_plan/alerts_test.exs +++ b/test/dotcom/trip_plan/alerts_test.exs @@ -5,8 +5,8 @@ defmodule Dotcom.TripPlan.AlertsTest do import Mox alias Alerts.{Alert, InformedEntity} + alias Dotcom.TripPlan.Itinerary alias Test.Support.Factories.{MBTA.Api, Stops.Stop, TripPlanner.TripPlanner} - alias TripPlan.Itinerary setup :verify_on_exit! diff --git a/test/trip_planner/input_form_test.exs b/test/dotcom/trip_plan/input_form_test.exs similarity index 96% rename from test/trip_planner/input_form_test.exs rename to test/dotcom/trip_plan/input_form_test.exs index 8d8a17af7b..5e8eaba902 100644 --- a/test/trip_planner/input_form_test.exs +++ b/test/dotcom/trip_plan/input_form_test.exs @@ -1,7 +1,7 @@ -defmodule TripPlanner.InputFormTest do +defmodule Dotcom.TripPlan.InputFormTest do use ExUnit.Case, async: true - alias TripPlanner.InputForm + alias Dotcom.TripPlan.InputForm @from_params %{ "latitude" => "#{Faker.Address.latitude()}", diff --git a/test/dotcom/trip_plan/itinerary_row_list_test.exs b/test/dotcom/trip_plan/itinerary_row_list_test.exs index 60ff7535c8..42c7ae4bf7 100644 --- a/test/dotcom/trip_plan/itinerary_row_list_test.exs +++ b/test/dotcom/trip_plan/itinerary_row_list_test.exs @@ -5,6 +5,7 @@ defmodule Dotcom.TripPlan.ItineraryRowListTest do import Mox alias Test.Support.Factories.{Stops.Stop, TripPlanner.TripPlanner} + alias Dotcom.TripPlan.{Itinerary, Leg, NamedPosition, TransitDetail} @date_time ~N[2017-06-27T11:43:00] @@ -142,7 +143,7 @@ defmodule Dotcom.TripPlan.ItineraryRowListTest do stop_name = Faker.Address.city() to = TripPlanner.build(:stop_named_position, stop: %Stops.Stop{id: stop_id}) - itinerary = %TripPlan.Itinerary{ + itinerary = %Itinerary{ start: nil, stop: nil, legs: [TripPlanner.build(:transit_leg, to: to)] @@ -171,12 +172,12 @@ defmodule Dotcom.TripPlan.ItineraryRowListTest do @tag :external test "Returns additional routes for Green Line legs", %{itinerary: itinerary} do - green_leg = %TripPlan.Leg{ + green_leg = %Leg{ start: @date_time, stop: @date_time, - from: %TripPlan.NamedPosition{stop: %Stops.Stop{id: "place-kencl"}, name: "Kenmore"}, - to: %TripPlan.NamedPosition{stop: %Stops.Stop{id: "place-pktrm"}, name: "Park Street"}, - mode: %TripPlan.TransitDetail{ + from: %NamedPosition{stop: %Stops.Stop{id: "place-kencl"}, name: "Kenmore"}, + to: %NamedPosition{stop: %Stops.Stop{id: "place-pktrm"}, name: "Park Street"}, + mode: %TransitDetail{ route: %Routes.Route{id: "Green-C"}, trip_id: "Green-1", intermediate_stops: [] @@ -202,12 +203,12 @@ defmodule Dotcom.TripPlan.ItineraryRowListTest do @tag :external test "Alerts for intermediate steps parsed correctly", %{itinerary: itinerary} do - red_leg = %TripPlan.Leg{ + red_leg = %Leg{ start: @date_time, stop: @date_time, - from: %TripPlan.NamedPosition{stop: %Stops.Stop{id: "place-sstat"}, name: "South Station"}, - to: %TripPlan.NamedPosition{stop: %Stops.Stop{id: "place-pktrm"}, name: "Park Street"}, - mode: %TripPlan.TransitDetail{ + from: %NamedPosition{stop: %Stops.Stop{id: "place-sstat"}, name: "South Station"}, + to: %NamedPosition{stop: %Stops.Stop{id: "place-pktrm"}, name: "Park Street"}, + mode: %TransitDetail{ route: %Routes.Route{id: "Red"}, intermediate_stops: [%Stops.Stop{id: "place-dwnxg"}] } @@ -229,23 +230,23 @@ defmodule Dotcom.TripPlan.ItineraryRowListTest do test "Alerts for stations mid travel and destination parsed correctly", %{ itinerary: itinerary } do - red_leg = %TripPlan.Leg{ + red_leg = %Leg{ start: @date_time, stop: @date_time, - from: %TripPlan.NamedPosition{stop: %Stops.Stop{id: "place-sstat"}, name: "South Station"}, - to: %TripPlan.NamedPosition{stop: %Stops.Stop{id: "place-pktrm"}, name: "Park Street"}, - mode: %TripPlan.TransitDetail{ + from: %NamedPosition{stop: %Stops.Stop{id: "place-sstat"}, name: "South Station"}, + to: %NamedPosition{stop: %Stops.Stop{id: "place-pktrm"}, name: "Park Street"}, + mode: %TransitDetail{ route: %Routes.Route{id: "Red"}, intermediate_stops: [] } } - green_leg = %TripPlan.Leg{ + green_leg = %Leg{ start: @date_time, stop: @date_time, - from: %TripPlan.NamedPosition{stop: %Stops.Stop{id: "place-pktrm"}, name: "Park Street"}, - to: %TripPlan.NamedPosition{stop: %Stops.Stop{id: "place-kencl"}, name: "Kenmore"}, - mode: %TripPlan.TransitDetail{ + from: %NamedPosition{stop: %Stops.Stop{id: "place-pktrm"}, name: "Park Street"}, + to: %NamedPosition{stop: %Stops.Stop{id: "place-kencl"}, name: "Kenmore"}, + mode: %TransitDetail{ route: %Routes.Route{id: "Green-C"}, trip_id: "Green-1", intermediate_stops: [] diff --git a/test/dotcom/trip_plan/itinerary_row_test.exs b/test/dotcom/trip_plan/itinerary_row_test.exs index 550734a176..fe44a80ebd 100644 --- a/test/dotcom/trip_plan/itinerary_row_test.exs +++ b/test/dotcom/trip_plan/itinerary_row_test.exs @@ -1,14 +1,13 @@ -defmodule TripPlan.ItineraryRowTest do +defmodule Dotcom.TripPlan.ItineraryRowTest do use ExUnit.Case, async: true import Dotcom.TripPlan.ItineraryRow import Mox alias Alerts.{Alert, InformedEntity} - alias Dotcom.TripPlan.ItineraryRow + alias Dotcom.TripPlan.{ItineraryRow, Leg, NamedPosition, PersonalDetail} alias Routes.Route alias Test.Support.Factories.{MBTA.Api, Stops.Stop, TripPlanner.TripPlanner} - alias TripPlan.{Leg, NamedPosition, PersonalDetail} setup :verify_on_exit! diff --git a/test/trip_plan/itinerary_test.exs b/test/dotcom/trip_plan/itinerary_test.exs similarity index 94% rename from test/trip_plan/itinerary_test.exs rename to test/dotcom/trip_plan/itinerary_test.exs index c9605cc920..6d642ef9fe 100644 --- a/test/trip_plan/itinerary_test.exs +++ b/test/dotcom/trip_plan/itinerary_test.exs @@ -1,12 +1,12 @@ -defmodule TripPlan.ItineraryTest do +defmodule Dotcom.TripPlan.ItineraryTest do use ExUnit.Case, async: true import Mox - import TripPlan.Itinerary + import Dotcom.TripPlan.Itinerary + alias Dotcom.TripPlan.{Itinerary, Leg, PersonalDetail, TransitDetail} alias Test alias Test.Support.Factories.{Stops.Stop, TripPlanner.TripPlanner} - alias TripPlan.{Leg, PersonalDetail, TransitDetail} @from TripPlanner.build(:stop_named_position) @to TripPlanner.build(:stop_named_position) @@ -101,7 +101,7 @@ defmodule TripPlan.ItineraryTest do describe "walking_distance/1" do test "calculates walking distance of itinerary" do - itinerary = %TripPlan.Itinerary{ + itinerary = %Itinerary{ start: DateTime.from_unix(10), stop: DateTime.from_unix(13), legs: [ @@ -117,7 +117,7 @@ defmodule TripPlan.ItineraryTest do describe "intermediate_stop_ids" do test "returns intermediate stop ids if the leg is transit detail and has them" do - itinerary = %TripPlan.Itinerary{ + itinerary = %Itinerary{ start: DateTime.from_unix(10), stop: DateTime.from_unix(13), legs: [ @@ -135,7 +135,7 @@ defmodule TripPlan.ItineraryTest do end test "does not return duplicate ids" do - itinerary = %TripPlan.Itinerary{ + itinerary = %Itinerary{ start: DateTime.from_unix(10), stop: DateTime.from_unix(13), legs: [ diff --git a/test/trip_plan/leg_test.exs b/test/dotcom/trip_plan/leg_test.exs similarity index 98% rename from test/trip_plan/leg_test.exs rename to test/dotcom/trip_plan/leg_test.exs index e2613759eb..92ad19195f 100644 --- a/test/trip_plan/leg_test.exs +++ b/test/dotcom/trip_plan/leg_test.exs @@ -1,8 +1,8 @@ -defmodule TripPlan.LegTest do +defmodule Dotcom.TripPlan.LegTest do use ExUnit.Case, async: true import Mox - import TripPlan.Leg + import Dotcom.TripPlan.Leg alias Test.Support.Factories.{Routes.Route, Stops.Stop, TripPlanner.TripPlanner} diff --git a/test/dotcom/trip_plan/location_test.exs b/test/dotcom/trip_plan/location_test.exs index 67e64d605f..840cdb1f02 100644 --- a/test/dotcom/trip_plan/location_test.exs +++ b/test/dotcom/trip_plan/location_test.exs @@ -1,7 +1,6 @@ defmodule Dotcom.TripPlan.LocationTest do use ExUnit.Case, async: true - alias Dotcom.TripPlan.{Location, Query} - alias TripPlan.NamedPosition + alias Dotcom.TripPlan.{Location, NamedPosition, Query} import Mox import Test.Support.Factories.LocationService.LocationService diff --git a/test/trip_planner/open_trip_planner_test.exs b/test/dotcom/trip_plan/open_trip_planner_test.exs similarity index 92% rename from test/trip_planner/open_trip_planner_test.exs rename to test/dotcom/trip_plan/open_trip_planner_test.exs index eb7b40694e..1150a7d237 100644 --- a/test/trip_planner/open_trip_planner_test.exs +++ b/test/dotcom/trip_plan/open_trip_planner_test.exs @@ -1,8 +1,7 @@ -defmodule TripPlanner.OpenTripPlannerTest do +defmodule Dotcom.TripPlan.OpenTripPlannerTest do use ExUnit.Case, async: true - alias TripPlan.NamedPosition - alias TripPlanner.OpenTripPlanner + alias Dotcom.TripPlan.{NamedPosition, OpenTripPlanner} import Mox import Test.Support.Factories.TripPlanner.TripPlanner diff --git a/test/dotcom/trip_plan/query_test.exs b/test/dotcom/trip_plan/query_test.exs index 24fa5c9220..89c3fbbdc0 100644 --- a/test/dotcom/trip_plan/query_test.exs +++ b/test/dotcom/trip_plan/query_test.exs @@ -4,8 +4,7 @@ defmodule Dotcom.TripPlan.QueryTest do import Dotcom.TripPlan.Query import Mox import Test.Support.Factories.LocationService.LocationService - alias Dotcom.TripPlan.Query - alias TripPlan.NamedPosition + alias Dotcom.TripPlan.{Itinerary, NamedPosition, Query} @date_time Timex.to_datetime(~N[2017-05-30T19:30:00], "America/New_York") @date_time_params %{ @@ -275,11 +274,11 @@ defmodule Dotcom.TripPlan.QueryTest do describe "get_itineraries/1" do test "returns itineraries if present" do itineraries = [ - %TripPlan.Itinerary{ + %Itinerary{ start: Util.now(), stop: Util.now() }, - %TripPlan.Itinerary{ + %Itinerary{ start: Util.now(), stop: Util.now() } diff --git a/test/dotcom/trip_plan/related_link_test.exs b/test/dotcom/trip_plan/related_link_test.exs index 66caa18336..21f89a5a97 100644 --- a/test/dotcom/trip_plan/related_link_test.exs +++ b/test/dotcom/trip_plan/related_link_test.exs @@ -7,7 +7,7 @@ defmodule Dotcom.TripPlan.RelatedLinkTest do import Test.Support.Factories.TripPlanner.TripPlanner alias Test.Support.Factories.Stops.Stop - alias TripPlan.Itinerary + alias Dotcom.TripPlan.Itinerary setup :verify_on_exit! diff --git a/test/trip_plan/transfer_test.exs b/test/dotcom/trip_plan/transfer_test.exs similarity index 97% rename from test/trip_plan/transfer_test.exs rename to test/dotcom/trip_plan/transfer_test.exs index 7da55e5230..510ea5ce84 100644 --- a/test/trip_plan/transfer_test.exs +++ b/test/dotcom/trip_plan/transfer_test.exs @@ -1,11 +1,11 @@ -defmodule TransferTest do +defmodule Dotcom.TripPlan.TransferTest do use ExUnit.Case, async: true import Mox - import TripPlan.Transfer + import Dotcom.TripPlan.Transfer + alias Dotcom.TripPlan.{Leg, NamedPosition, PersonalDetail, TransitDetail} alias Test.Support.Factories.{Stops.Stop, TripPlanner.TripPlanner} - alias TripPlan.{Leg, NamedPosition, PersonalDetail, TransitDetail} setup :verify_on_exit! diff --git a/test/dotcom_web/components/trip_planner_test.exs b/test/dotcom_web/components/trip_planner_test.exs index 92e13d937c..40c09e922d 100644 --- a/test/dotcom_web/components/trip_planner_test.exs +++ b/test/dotcom_web/components/trip_planner_test.exs @@ -1,8 +1,8 @@ -defmodule DotcomWeb.Components.TripPlannerTest do +defmodule DotcomWeb.Components.TripPlannerFormTest do @moduledoc false use ExUnit.Case import Phoenix.LiveViewTest - import DotcomWeb.Components.TripPlanner + import DotcomWeb.Components.TripPlannerForm describe "input_form" do test "renders the needed inputs" do @@ -75,12 +75,12 @@ defmodule DotcomWeb.Components.TripPlannerTest do assert_receive {:updated_form, data} - assert %TripPlanner.InputForm{ - from: %TripPlanner.InputForm.Location{ + assert %Dotcom.TripPlan.InputForm{ + from: %Dotcom.TripPlan.InputForm.Location{ latitude: ^from_lat, longitude: ^from_lon }, - to: %TripPlanner.InputForm.Location{ + to: %Dotcom.TripPlan.InputForm.Location{ latitude: ^to_lat, longitude: ^to_lon } diff --git a/test/dotcom_web/controllers/trip_plan_controller_test.exs b/test/dotcom_web/controllers/trip_plan_controller_test.exs index c946284f7f..5c63b0aa22 100644 --- a/test/dotcom_web/controllers/trip_plan_controller_test.exs +++ b/test/dotcom_web/controllers/trip_plan_controller_test.exs @@ -1,9 +1,8 @@ defmodule DotcomWeb.TripPlanControllerTest do use DotcomWeb.ConnCase, async: true + alias Dotcom.TripPlan.{Itinerary, PersonalDetail, Query, TransitDetail} alias Fares.Fare - alias Dotcom.TripPlan.Query - alias TripPlan.{Itinerary, PersonalDetail, TransitDetail} import Test.Support.Factories.LocationService.LocationService @@ -310,7 +309,7 @@ defmodule DotcomWeb.TripPlanControllerTest do for itinerary <- conn.assigns.itineraries do for leg <- itinerary.legs do - if TripPlan.Leg.transit?(leg) do + if Dotcom.TripPlan.Leg.transit?(leg) do assert leg.mode.fares == %{ highest_one_way_fare: nil, lowest_one_way_fare: nil, diff --git a/test/dotcom_web/views/trip_plan_view_test.exs b/test/dotcom_web/views/trip_plan_view_test.exs index e503ec89ff..89d30aab22 100644 --- a/test/dotcom_web/views/trip_plan_view_test.exs +++ b/test/dotcom_web/views/trip_plan_view_test.exs @@ -6,10 +6,20 @@ defmodule DotcomWeb.TripPlanViewTest do import Phoenix.HTML, only: [safe_to_string: 1] import Schedules.Repo, only: [end_of_rating: 0] + alias Dotcom.TripPlan.{ + IntermediateStop, + Itinerary, + ItineraryRow, + Leg, + NamedPosition, + PersonalDetail, + PersonalDetail.Step, + Query, + TransitDetail + } + alias Fares.Fare - alias Dotcom.TripPlan.{IntermediateStop, ItineraryRow, Query} alias Test.Support.Factories.{Stops.Stop, TripPlanner.TripPlanner} - alias TripPlan.{Itinerary, Leg, NamedPosition, TransitDetail} @highest_one_way_fare %Fares.Fare{ additional_valid_modes: [:bus], @@ -803,7 +813,7 @@ closest arrival to 12:00 AM, Thursday, January 1st." assert %DateTime{} = time end - test "returns with encdoded %TripPlan.Query{}", %{conn: conn} do + test "returns with encdoded %Query{}", %{conn: conn} do conn = assign(conn, :query, %Query{ from: TripPlanner.build(:named_position), @@ -874,21 +884,21 @@ closest arrival to 12:00 AM, Thursday, January 1st." round_trip_total: "$5.80" } - @itinerary %TripPlan.Itinerary{ + @itinerary %Itinerary{ start: nil, stop: nil, legs: [ - %TripPlan.Leg{ - from: %TripPlan.NamedPosition{ + %Leg{ + from: %NamedPosition{ latitude: 42.365486, longitude: -71.103802, name: "Central", stop: nil }, - mode: %TripPlan.PersonalDetail{ + mode: %PersonalDetail{ distance: 24.274, steps: [ - %TripPlan.PersonalDetail.Step{ + %Step{ absolute_direction: :southeast, distance: 24.274, relative_direction: :depart, @@ -897,27 +907,27 @@ closest arrival to 12:00 AM, Thursday, January 1st." ] }, polyline: "eoqaGzm~pLTe@BE@A", - to: %TripPlan.NamedPosition{ + to: %NamedPosition{ latitude: 42.365304, longitude: -71.103621, name: "Central", stop: %Stops.Stop{id: "70069"} } }, - %TripPlan.Leg{ - from: %TripPlan.NamedPosition{ + %Leg{ + from: %NamedPosition{ latitude: 42.365304, longitude: -71.103621, name: "Central", stop: %Stops.Stop{id: "70069"} }, - mode: %TripPlan.TransitDetail{ + mode: %TransitDetail{ fares: @fares, intermediate_stops: [%Stops.Stop{id: "70071"}, %Stops.Stop{id: "70073"}], route: %Routes.Route{id: "Red"}, trip_id: "43870769C0" }, - to: %TripPlan.NamedPosition{ + to: %NamedPosition{ latitude: 42.356395, longitude: -71.062424, name: "Park Street", @@ -1022,21 +1032,21 @@ closest arrival to 12:00 AM, Thursday, January 1st." } } - itinerary = %TripPlan.Itinerary{ + itinerary = %Itinerary{ start: nil, stop: nil, legs: [ - %TripPlan.Leg{ - from: %TripPlan.NamedPosition{ + %Leg{ + from: %NamedPosition{ latitude: 42.365486, longitude: -71.103802, name: "Central", stop: nil }, - mode: %TripPlan.PersonalDetail{ + mode: %PersonalDetail{ distance: 24.274, steps: [ - %TripPlan.PersonalDetail.Step{ + %Step{ absolute_direction: :southeast, distance: 24.274, relative_direction: :depart, @@ -1045,41 +1055,41 @@ closest arrival to 12:00 AM, Thursday, January 1st." ] }, polyline: "eoqaGzm~pLTe@BE@A", - to: %TripPlan.NamedPosition{ + to: %NamedPosition{ latitude: 42.365304, longitude: -71.103621, name: "Central", stop: %Stops.Stop{id: "70069"} } }, - %TripPlan.Leg{ - from: %TripPlan.NamedPosition{ + %Leg{ + from: %NamedPosition{ latitude: 42.365304, longitude: -71.103621, name: "Central", stop: %Stops.Stop{id: "70069"} }, - mode: %TripPlan.TransitDetail{ + mode: %TransitDetail{ fares: @fares, intermediate_stops: [%Stops.Stop{id: "70071"}, %Stops.Stop{id: "70073"}], route: %Routes.Route{id: "Red"}, trip_id: "43870769C0" }, - to: %TripPlan.NamedPosition{ + to: %NamedPosition{ latitude: 42.356395, longitude: -71.062424, name: "Park Street", stop: %Stops.Stop{id: "70075"} } }, - %TripPlan.Leg{ - from: %TripPlan.NamedPosition{ + %Leg{ + from: %NamedPosition{ latitude: 42.362804, longitude: -71.099509, name: "Massachusetts Ave @ Sidney St", stop: %Stops.Stop{id: "73"} }, - mode: %TripPlan.TransitDetail{ + mode: %TransitDetail{ fares: bus_fares, intermediate_stops: [ %Stops.Stop{id: "74"}, @@ -1091,27 +1101,27 @@ closest arrival to 12:00 AM, Thursday, January 1st." route: %Routes.Route{id: "1"}, trip_id: "44170977" }, - to: %TripPlan.NamedPosition{ + to: %NamedPosition{ latitude: 42.342478, longitude: -71.084701, name: "Massachusetts Ave @ Huntington Ave", stop: %Stops.Stop{id: "82"} } }, - %TripPlan.Leg{ - from: %TripPlan.NamedPosition{ + %Leg{ + from: %NamedPosition{ latitude: 42.365304, longitude: -71.103621, name: "Central", stop: %Stops.Stop{id: "70069"} }, - mode: %TripPlan.TransitDetail{ + mode: %TransitDetail{ fares: @fares, intermediate_stops: [%Stops.Stop{id: "70071"}, %Stops.Stop{id: "70073"}], route: %Routes.Route{id: "Red"}, trip_id: "43870769C0" }, - to: %TripPlan.NamedPosition{ + to: %NamedPosition{ latitude: 42.356395, longitude: -71.062424, name: "Park Street", @@ -1147,7 +1157,7 @@ closest arrival to 12:00 AM, Thursday, January 1st." shuttle_leg = TripPlanner.build(:shuttle_leg) bus_leg = TripPlanner.build(:subway_leg) - itinerary = %TripPlan.Itinerary{ + itinerary = %Itinerary{ start: nil, stop: nil, legs: [shuttle_leg, bus_leg] @@ -1187,7 +1197,7 @@ closest arrival to 12:00 AM, Thursday, January 1st." TripPlanner.build(:subway_leg) itinerary = - %TripPlan.Itinerary{start: nil, stop: nil, legs: [free_leg, paid_leg]} + %Itinerary{start: nil, stop: nil, legs: [free_leg, paid_leg]} assert get_one_way_total_by_type(itinerary, :highest_one_way_fare) == 240 end @@ -1279,7 +1289,7 @@ closest arrival to 12:00 AM, Thursday, January 1st." } } - itinerary = %TripPlan.Itinerary{ + itinerary = %Itinerary{ start: nil, stop: nil, legs: [red_leg, orange_leg] @@ -1289,21 +1299,21 @@ closest arrival to 12:00 AM, Thursday, January 1st." end test "returns 0 when there is no highest one-way fare" do - itinerary = %TripPlan.Itinerary{ + itinerary = %Itinerary{ start: nil, stop: nil, legs: [ - %TripPlan.Leg{ - from: %TripPlan.NamedPosition{ + %Leg{ + from: %NamedPosition{ latitude: 42.365486, longitude: -71.103802, name: "Central", stop: nil }, - mode: %TripPlan.PersonalDetail{ + mode: %PersonalDetail{ distance: 24.274, steps: [ - %TripPlan.PersonalDetail.Step{ + %Step{ absolute_direction: :southeast, distance: 24.274, relative_direction: :depart, @@ -1312,21 +1322,21 @@ closest arrival to 12:00 AM, Thursday, January 1st." ] }, polyline: "eoqaGzm~pLTe@BE@A", - to: %TripPlan.NamedPosition{ + to: %NamedPosition{ latitude: 42.365304, longitude: -71.103621, name: "Central", stop: %Stops.Stop{id: "70069"} } }, - %TripPlan.Leg{ - from: %TripPlan.NamedPosition{ + %Leg{ + from: %NamedPosition{ latitude: 42.365304, longitude: -71.103621, name: "Central", stop: %Stops.Stop{id: "70069"} }, - mode: %TripPlan.TransitDetail{ + mode: %TransitDetail{ fares: %{ highest_one_way_fare: nil, lowest_one_way_fare: nil @@ -1335,7 +1345,7 @@ closest arrival to 12:00 AM, Thursday, January 1st." route: %Routes.Route{id: "Red"}, trip_id: "43870769C0" }, - to: %TripPlan.NamedPosition{ + to: %NamedPosition{ latitude: 42.356395, longitude: -71.062424, name: "Park Street", @@ -1355,19 +1365,19 @@ closest arrival to 12:00 AM, Thursday, January 1st." | legs: [ %Leg{ mode: %TransitDetail{route: %Routes.Route{id: "77"}}, - from: %TripPlan.NamedPosition{ + from: %NamedPosition{ stop: nil }, - to: %TripPlan.NamedPosition{ + to: %NamedPosition{ stop: nil } }, %Leg{ mode: %TransitDetail{route: %Routes.Route{id: "1"}}, - from: %TripPlan.NamedPosition{ + from: %NamedPosition{ stop: nil }, - to: %TripPlan.NamedPosition{ + to: %NamedPosition{ stop: nil } } @@ -1418,14 +1428,14 @@ closest arrival to 12:00 AM, Thursday, January 1st." test "renders the Fare Calculator", %{conn: conn} do leg_for_route = &%Leg{ - from: %TripPlan.NamedPosition{ + from: %NamedPosition{ stop: nil }, mode: %TransitDetail{ route: %Routes.Route{id: &1}, fares: @fares }, - to: %TripPlan.NamedPosition{ + to: %NamedPosition{ stop: nil } } @@ -1479,14 +1489,14 @@ closest arrival to 12:00 AM, Thursday, January 1st." test "includes Logan in the trip", %{conn: conn} do legs = [ - %TripPlan.Leg{ - from: %TripPlan.NamedPosition{ + %Leg{ + from: %NamedPosition{ latitude: 42.366494, longitude: -71.017289, name: "Terminal C - Arrivals Level", stop: %Stops.Stop{id: "17094"} }, - mode: %TripPlan.TransitDetail{ + mode: %TransitDetail{ fares: %{ highest_one_way_fare: %Fares.Fare{ additional_valid_modes: [], @@ -1520,7 +1530,7 @@ closest arrival to 12:00 AM, Thursday, January 1st." route: %Routes.Route{id: "741"}, trip_id: "44812009" }, - to: %TripPlan.NamedPosition{ + to: %NamedPosition{ latitude: 42.352271, longitude: -71.055242, name: "South Station", @@ -1611,7 +1621,7 @@ closest arrival to 12:00 AM, Thursday, January 1st." sl_from_logan_itinerary = %Itinerary{ legs: [ %Leg{ - mode: %TripPlan.PersonalDetail{ + mode: %PersonalDetail{ distance: 510.2 } }, @@ -1637,40 +1647,40 @@ closest arrival to 12:00 AM, Thursday, January 1st." end test "returns true for all other itineraries" do - login_sl_plus_subway_itinerary = %TripPlan.Itinerary{ + login_sl_plus_subway_itinerary = %Itinerary{ legs: [ - %TripPlan.Leg{ - mode: %TripPlan.PersonalDetail{ + %Leg{ + mode: %PersonalDetail{ distance: 385.75800000000004 } }, - %TripPlan.Leg{ - from: %TripPlan.NamedPosition{ + %Leg{ + from: %NamedPosition{ name: "Terminal A", stop: %Stops.Stop{id: "17091"} }, - mode: %TripPlan.TransitDetail{ + mode: %TransitDetail{ route: %Routes.Route{id: "741"} }, - to: %TripPlan.NamedPosition{ + to: %NamedPosition{ name: "South Station", stop: %Stops.Stop{id: "74617"} } }, - %TripPlan.Leg{ - mode: %TripPlan.PersonalDetail{ + %Leg{ + mode: %PersonalDetail{ distance: 0.0 } }, - %TripPlan.Leg{ - from: %TripPlan.NamedPosition{ + %Leg{ + from: %NamedPosition{ name: "South Station", stop: %Stops.Stop{id: "70080"} }, - mode: %TripPlan.TransitDetail{ + mode: %TransitDetail{ route: %Routes.Route{id: "Red"} }, - to: %TripPlan.NamedPosition{ + to: %NamedPosition{ name: "Downtown Crossing", stop: %Stops.Stop{id: "70078"} } @@ -1684,15 +1694,15 @@ closest arrival to 12:00 AM, Thursday, January 1st." end test "returns true for an itinerary without any transit legs" do - no_transit_legs_itinerary = %TripPlan.Itinerary{ + no_transit_legs_itinerary = %Itinerary{ legs: [ - %TripPlan.Leg{ - mode: %TripPlan.PersonalDetail{ + %Leg{ + mode: %PersonalDetail{ distance: 385.75800000000004 } }, - %TripPlan.Leg{ - mode: %TripPlan.PersonalDetail{ + %Leg{ + mode: %PersonalDetail{ distance: 0.0 } } @@ -1719,7 +1729,7 @@ closest arrival to 12:00 AM, Thursday, January 1st." conn: %{query_params: %{}, request_path: ""}, itinerary_row: %{ duration: 2, - trip: %{headsign: nil, direction_id: 0, name: Faker.Name.name()} + trip: %{headsign: nil, direction_id: 0, name: Faker.App.name()} } } @@ -1744,7 +1754,7 @@ closest arrival to 12:00 AM, Thursday, January 1st." conn: %{query_params: %{}, request_path: ""}, itinerary_row: %{ duration: 2, - trip: %{headsign: nil, direction_id: 0, name: Faker.Name.name()} + trip: %{headsign: nil, direction_id: 0, name: Faker.App.name()} } } @@ -1769,7 +1779,7 @@ closest arrival to 12:00 AM, Thursday, January 1st." conn: %{query_params: %{}, request_path: ""}, itinerary_row: %{ duration: 2, - trip: %{headsign: nil, direction_id: 0, name: Faker.Name.name()} + trip: %{headsign: nil, direction_id: 0, name: Faker.App.name()} } } @@ -1794,7 +1804,7 @@ closest arrival to 12:00 AM, Thursday, January 1st." conn: %{query_params: %{}, request_path: ""}, itinerary_row: %{ duration: 2, - trip: %{headsign: nil, direction_id: 0, name: Faker.Name.name()} + trip: %{headsign: nil, direction_id: 0, name: Faker.App.name()} } } diff --git a/test/fares/fares_test.exs b/test/fares/fares_test.exs index bbc3663be6..f698be2d43 100644 --- a/test/fares/fares_test.exs +++ b/test/fares/fares_test.exs @@ -4,6 +4,7 @@ defmodule FaresTest do import Mox + alias Dotcom.TripPlan.{NamedPosition, Leg, PersonalDetail, PersonalDetail.Step, TransitDetail} alias Test.Support.Factories.{Routes.Route, Stops.Stop} setup :verify_on_exit! @@ -186,17 +187,17 @@ defmodule FaresTest do describe "get_fare_by_type/2" do test "gets fare by type" do - non_transit_leg = %TripPlan.Leg{ - from: %TripPlan.NamedPosition{ + non_transit_leg = %Leg{ + from: %NamedPosition{ latitude: 42.365486, longitude: -71.103802, name: "Central", stop: nil }, - mode: %TripPlan.PersonalDetail{ + mode: %PersonalDetail{ distance: 24.274, steps: [ - %TripPlan.PersonalDetail.Step{ + %Step{ absolute_direction: :southeast, distance: 24.274, relative_direction: :depart, @@ -205,7 +206,7 @@ defmodule FaresTest do ] }, polyline: "eoqaGzm~pLTe@BE@A", - to: %TripPlan.NamedPosition{ + to: %NamedPosition{ latitude: 42.365304, longitude: -71.103621, name: "Central", @@ -229,14 +230,14 @@ defmodule FaresTest do cents: 110 } - transit_leg = %TripPlan.Leg{ - from: %TripPlan.NamedPosition{ + transit_leg = %Leg{ + from: %NamedPosition{ latitude: 42.365304, longitude: -71.103621, name: "Central", stop: %Stops.Stop{id: "70069"} }, - mode: %TripPlan.TransitDetail{ + mode: %TransitDetail{ fares: %{ highest_one_way_fare: highest_one_way_fare, lowest_one_way_fare: lowest_one_way_fare, @@ -246,7 +247,7 @@ defmodule FaresTest do route: %Routes.Route{id: "Red"}, trip_id: "43870769C0" }, - to: %TripPlan.NamedPosition{ + to: %NamedPosition{ latitude: 42.356395, longitude: -71.062424, name: "Park Street", diff --git a/test/support/factories/trip_planner/trip_planner.ex b/test/support/factories/trip_planner/trip_planner.ex index 47de618ab4..bcf7ce3402 100644 --- a/test/support/factories/trip_planner/trip_planner.ex +++ b/test/support/factories/trip_planner/trip_planner.ex @@ -4,9 +4,8 @@ defmodule Test.Support.Factories.TripPlanner.TripPlanner do """ use ExMachina - alias Dotcom.TripPlanner.Parser + alias Dotcom.TripPlan.{NamedPosition, Parser} alias OpenTripPlannerClient.Test.Support.Factory - alias TripPlan.NamedPosition def itinerary_factory do Factory.build(:itinerary)