Skip to content

Commit

Permalink
fixup! cleanup: Add more alert factories for use in SystemStatus.Subw…
Browse files Browse the repository at this point in the history
…ayTests
  • Loading branch information
joshlarson committed Feb 8, 2025
1 parent e163637 commit 9798a8e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 18 deletions.
3 changes: 1 addition & 2 deletions test/dotcom/system_status/subway_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,8 @@ defmodule Dotcom.SystemStatus.SubwayTest do
effect = Faker.Util.pick(Alerts.service_effects())

alerts = [
Alert.build(:alert, effect: effect)
Alert.build(:alert_for_route, route_id: affected_route_id, effect: effect)
|> Alert.active_during(time)
|> Alert.for_route(affected_route_id)
]

# Exercise
Expand Down
27 changes: 11 additions & 16 deletions test/support/factories/alerts/alert.ex
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ defmodule Test.Support.Factories.Alerts.Alert do
use ExMachina

alias Alerts.{Alert, Priority}
alias Test.Support.Factories.Alerts.InformedEntity
alias Test.Support.Factories.Alerts.InformedEntitySet

def alert_factory do
Expand All @@ -30,21 +29,17 @@ defmodule Test.Support.Factories.Alerts.Alert do
}
end

def for_route(alert, route_id) do
%{
alert
| informed_entity:
InformedEntitySet.build(:informed_entity_set,
route: route_id,
entities: [
InformedEntity.build(:informed_entity, route: route_id)
]
)
}
end

def with_high_priority_effect(alert) do
%{alert | effect: Faker.Util.pick(Dotcom.SystemStatus.Alerts.service_effects())}
def alert_for_route_factory(attrs) do
{route_id, attrs} = Map.pop(attrs, :route_id)

build(
:alert,
attrs
|> Map.put(
:informed_entity,
InformedEntitySet.build(:informed_entity_set_for_route, route_id: route_id)
)
)
end

def active_during(alert, time) do
Expand Down
8 changes: 8 additions & 0 deletions test/support/factories/alerts/informed_entity_set.ex
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,12 @@ defmodule Test.Support.Factories.Alerts.InformedEntitySet do

InformedEntitySet.new([informed_entity])
end

def informed_entity_set_for_route_factory(attrs) do
{route_id, attrs} = attrs |> Map.pop(:route_id)

informed_entity = InformedEntity.build(:informed_entity, attrs |> Map.put(:route, route_id))

InformedEntitySet.new([informed_entity])
end
end

0 comments on commit 9798a8e

Please sign in to comment.