Alerts
Imports and Aliases
import Dotcom.Utils.DateTime, only: [now: 0]
alias Test.Support.Factories.Alerts.{Alert, InformedEntity}
Stop the fetcher so it doesn’t update alerts
Supervisor.which_children(Dotcom.Supervisor)
|> Enum.find(fn {_, _, _, list} -> list == [Alerts.CacheSupervisor] end)
|> elem(1)
|> Supervisor.terminate_child(Alerts.Cache.Fetcher)
Orange Line Suspension
# Create an informed entity for a route (Orange) and stop (Downtown Crossing)
informed_entity =
InformedEntity.build(:informed_entity,
activities: MapSet.new([:exit, :ride, :board]),
route: "Orange",
route_type: 1,
stop: "place-dwnxg"
)
informed_entity_set = Alerts.InformedEntitySet.new([informed_entity])
# Create a currently active suspension alert
alert =
Alert.build(:alert,
active_period: [
{
now() |> Timex.shift(hours: -4),
now() |> Timex.shift(hours: 8)
}
],
effect: :suspension,
informed_entity: informed_entity_set
)
alerts = [alert]
# Remove all other alerts and only use the one's you created
Alerts.Cache.Store.update(alerts, nil)
now() |> Alerts.Repo.all()
Red Line Single-Tracking with Endpoints
informed_entities =
[
nil,
"place-jfk",
"place-nqncy",
"place-wlsta",
"place-qnctr"
]
|> Enum.map(
&InformedEntity.build(:informed_entity,
activities: MapSet.new([:exit, :ride, :board]),
route: "Red",
route_type: 1,
stop: &1
)
)
# Create a currently active suspension alert
alerts =
[
Alert.build(:alert,
active_period: [
{
now() |> Timex.shift(hours: -4),
now() |> Timex.shift(hours: 8)
}
],
effect: :single_tracking,
cause: :single_tracking,
severity: 1,
informed_entity: Alerts.InformedEntitySet.new(informed_entities)
)
]
# Remove all other alerts and only use the ones you created
Alerts.Cache.Store.update(alerts, nil)
now() |> Alerts.Repo.all()