Skip to content

Commit

Permalink
Tighten up CR Fare Finder and Foxboro Special Event fare (#247)
Browse files Browse the repository at this point in the history
  • Loading branch information
amaisano authored Oct 10, 2019
1 parent 2043f93 commit 264e6ef
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 7 deletions.
1 change: 1 addition & 0 deletions apps/fares/lib/fare.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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__{
Expand Down
2 changes: 1 addition & 1 deletion apps/fares/lib/fare_info.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
3 changes: 2 additions & 1 deletion apps/fares/lib/format.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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"
Expand Down
3 changes: 2 additions & 1 deletion apps/site/lib/site/content_rewriters/liquid_objects/fare.ex
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ defmodule Site.ContentRewriters.LiquidObjects.Fare do
"charlie_ticket",
"commuter_ticket",
"mticket",
"paper_ferry"
"paper_ferry",
"special_event"
]

@fare_reduced [
Expand Down
11 changes: 9 additions & 2 deletions apps/site/lib/site_web/controllers/fare/commuter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
7 changes: 6 additions & 1 deletion apps/site/lib/site_web/views/fare/description.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
18 changes: 17 additions & 1 deletion apps/site/test/site_web/controllers/fare/commuter_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit 264e6ef

Please sign in to comment.