From 264e6ef62b1174371d210f14f284569c8756e531 Mon Sep 17 00:00:00 2001 From: Adamo Maisano Date: Thu, 10 Oct 2019 17:22:59 -0400 Subject: [PATCH] Tighten up CR Fare Finder and Foxboro Special Event fare (#247) --- apps/fares/lib/fare.ex | 1 + apps/fares/lib/fare_info.ex | 2 +- apps/fares/lib/format.ex | 3 ++- .../content_rewriters/liquid_objects/fare.ex | 3 ++- .../lib/site_web/controllers/fare/commuter.ex | 11 +++++++++-- .../lib/site_web/views/fare/description.ex | 7 ++++++- .../controllers/fare/commuter_test.exs | 18 +++++++++++++++++- 7 files changed, 38 insertions(+), 7 deletions(-) diff --git a/apps/fares/lib/fare.ex b/apps/fares/lib/fare.ex index 93a1ea4d1d..5dcd2e18e0 100644 --- a/apps/fares/lib/fare.ex +++ b/apps/fares/lib/fare.ex @@ -14,6 +14,7 @@ defmodule Fares.Fare do | :student_card | :senior_card | :paper_ferry + | :special_event @type reduced :: nil | :student | :senior_disabled | :any @type duration :: :single_trip | :round_trip | :day | :week | :weekend | :month | :invalid @type t :: %__MODULE__{ diff --git a/apps/fares/lib/fare_info.ex b/apps/fares/lib/fare_info.ex index cd51632420..2a265394e3 100644 --- a/apps/fares/lib/fare_info.ex +++ b/apps/fares/lib/fare_info.ex @@ -398,7 +398,7 @@ defmodule Fares.FareInfo do mode: :commuter_rail, name: :foxboro, duration: :round_trip, - media: [:commuter_ticket, :cash], + media: [:mticket, :special_event, :cash], reduced: nil, cents: dollars_to_cents(round_trip) } diff --git a/apps/fares/lib/format.ex b/apps/fares/lib/format.ex index cd385edefd..ccf5cf4399 100644 --- a/apps/fares/lib/format.ex +++ b/apps/fares/lib/format.ex @@ -29,6 +29,7 @@ defmodule Fares.Format do def media(:senior_card), do: "Senior CharlieCard or TAP ID" def media(:student_card), do: "Student CharlieCard" def media(:paper_ferry), do: "Paper Ferry Ticket" + def media(:special_event), do: "Special Event Ticket" @doc "Formats the customers that are served by the given fare based on reduced type" @spec customers(Fare.t() | Fare.reduced()) :: String.t() @@ -89,7 +90,7 @@ defmodule Fares.Format do def name(:commuter_ferry_logan), do: "Commuter Ferry to Logan Airport" def name({:zone, zone}), do: "Zone #{zone}" def name({:interzone, zone}), do: "Interzone #{zone}" - def name(:foxboro), do: "Foxboro" + def name(:foxboro), do: "Foxboro Special Event" def name(:free_fare), do: "Free Fare for SL1 Trips from Airport Stops" def name(:ada_ride), do: "ADA Ride" def name(:premium_ride), do: "Premium Ride" diff --git a/apps/site/lib/site/content_rewriters/liquid_objects/fare.ex b/apps/site/lib/site/content_rewriters/liquid_objects/fare.ex index af375f18cc..f3dc870f62 100644 --- a/apps/site/lib/site/content_rewriters/liquid_objects/fare.ex +++ b/apps/site/lib/site/content_rewriters/liquid_objects/fare.ex @@ -80,7 +80,8 @@ defmodule Site.ContentRewriters.LiquidObjects.Fare do "charlie_ticket", "commuter_ticket", "mticket", - "paper_ferry" + "paper_ferry", + "special_event" ] @fare_reduced [ diff --git a/apps/site/lib/site_web/controllers/fare/commuter.ex b/apps/site/lib/site_web/controllers/fare/commuter.ex index 0383e5e92f..97ff0340eb 100644 --- a/apps/site/lib/site_web/controllers/fare/commuter.ex +++ b/apps/site/lib/site_web/controllers/fare/commuter.ex @@ -10,15 +10,19 @@ defmodule SiteWeb.FareController.Commuter do @impl true @foxboro "place-FS-0049" + @pilot_launch_date ~D[2019-10-21] - def fares(%{assigns: %{origin: origin, destination: destination}}) + def fares(%{assigns: %{origin: origin, destination: destination, date: date}}) when not is_nil(origin) and not is_nil(destination) do case Fares.fare_for_stops(:commuter_rail, origin.id, destination.id) do {:ok, fare_name} -> standard_fares = get_fares(fare_name) + foxboro_event_fare = get_fares(:foxboro) if foxboro?(origin.id, destination.id) do - standard_fares ++ get_fares(:foxboro) + if foxboro_pilot?(date), + do: foxboro_event_fare ++ standard_fares, + else: foxboro_event_fare else standard_fares end @@ -45,4 +49,7 @@ defmodule SiteWeb.FareController.Commuter do @spec foxboro?(String.t(), String.t()) :: boolean() defp foxboro?(a, b) when @foxboro in [a, b], do: true defp foxboro?(_, _), do: false + + @spec foxboro_pilot?(Date.t()) :: boolean + defp foxboro_pilot?(current_date), do: Date.compare(current_date, @pilot_launch_date) != :lt end diff --git a/apps/site/lib/site_web/views/fare/description.ex b/apps/site/lib/site_web/views/fare/description.ex index 7ba3ab0042..3e108c66c0 100644 --- a/apps/site/lib/site_web/views/fare/description.ex +++ b/apps/site/lib/site_web/views/fare/description.ex @@ -3,6 +3,7 @@ defmodule SiteWeb.FareView.Description do import Phoenix.HTML.Link import Phoenix.HTML.Tag, only: [content_tag: 2] + import Phoenix.HTML.Link, only: [link: 2] import SiteWeb.ViewHelpers, only: [cms_static_page_path: 2] import Util.AndOr @@ -374,7 +375,11 @@ defmodule SiteWeb.FareView.Description do end defp valid_commuter_zones(:foxboro) do - "to Gillette Stadium for special events" + [ + "to ", + link("Gillette Stadium", to: "/gillette"), + " for special events" + ] end def transfers(fare) do diff --git a/apps/site/test/site_web/controllers/fare/commuter_test.exs b/apps/site/test/site_web/controllers/fare/commuter_test.exs index 8d76a58d8f..4c98884f2c 100644 --- a/apps/site/test/site_web/controllers/fare/commuter_test.exs +++ b/apps/site/test/site_web/controllers/fare/commuter_test.exs @@ -9,6 +9,7 @@ defmodule SiteWeb.FareController.CommuterTest do valid_fares = conn + |> assign(:date, ~D[2019-10-21]) |> assign(:origin, origin) |> assign(:destination, destination) |> Commuter.fares() @@ -17,12 +18,27 @@ defmodule SiteWeb.FareController.CommuterTest do refute Enum.any?(valid_fares, fn fare -> match?(%Fares.Fare{name: :foxboro}, fare) end) end - test "includes Foxboro special event fare if selection includes Foxboro", %{conn: conn} do + test "show only Foxboro special event fare if selection includes Foxboro", %{conn: conn} do origin = Stops.Repo.get("place-sstat") destination = Stops.Repo.get("place-FS-0049") valid_fares = conn + |> assign(:date, ~D[2019-10-20]) + |> assign(:origin, origin) + |> assign(:destination, destination) + |> Commuter.fares() + + assert valid_fares == Fares.Repo.all(name: :foxboro) + end + + test "includes Zone 4 fares for Foxboro if pilot has launched", %{conn: conn} do + origin = Stops.Repo.get("place-sstat") + destination = Stops.Repo.get("place-FS-0049") + + valid_fares = + conn + |> assign(:date, ~D[2019-10-21]) |> assign(:origin, origin) |> assign(:destination, destination) |> Commuter.fares()