Skip to content

Commit

Permalink
refactor: Clean up whitespace and formatting in disruption controller…
Browse files Browse the repository at this point in the history
… test
  • Loading branch information
Whoops committed Feb 27, 2025
1 parent 218146f commit d1c8491
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions test/arrow_web/controllers/disruption_v2_controller_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ defmodule ArrowWeb.DisruptionV2ControllerTest do

@tag :authenticated
test "lists disruptions that match a search query on title", %{conn: conn} do
route = insert(:gtfs_route) # Use insert to get a route with a unique ID
route = insert(:gtfs_route)

insert(:limit,
disruption: build(:disruption_v2, title: "Test disruption Alpha"),
route: route
)

insert(:limit,
disruption: build(:disruption_v2, title: "Test disruption Beta"),
route: route
Expand All @@ -86,18 +86,19 @@ defmodule ArrowWeb.DisruptionV2ControllerTest do

@tag :authenticated
test "lists disruptions that match a search query on stop names", %{conn: conn} do
route = insert(:gtfs_route) # Use insert to get a route with a unique ID
# Use insert to get a route with a unique ID
route = insert(:gtfs_route)
start_stop = insert(:gtfs_stop, name: "UniqueStopName Station")
end_stop = insert(:gtfs_stop, name: "Regular Station")

# Disruption that should match the search
insert(:limit,
disruption: build(:disruption_v2, title: "First Disruption"),
route: route,
start_stop: start_stop,
end_stop: end_stop
)

# Disruption that shouldn't match the search
insert(:limit,
disruption: build(:disruption_v2, title: "Second Disruption"),
Expand All @@ -114,29 +115,32 @@ defmodule ArrowWeb.DisruptionV2ControllerTest do
test "lists disruptions that match a search query on shuttle names", %{conn: conn} do
# Create a route to be used by both the shuttle and the limits
route = insert(:gtfs_route)

disruption_with_shuttle = insert(:disruption_v2, title: "Shuttle Disruption")
disruption_without_shuttle = insert(:disruption_v2, title: "Regular Disruption")

# Create a shuttle with proper association to the route, and include stops AND times to next stop
shuttle = Arrow.ShuttlesFixtures.shuttle_fixture(
%{
shuttle_name: "SpecialShuttleName Bus",
disrupted_route_id: route.id,
status: :active
},
true, # include stops parameter
true # include times to next stop parameter - this was missing
)

shuttle =
Arrow.ShuttlesFixtures.shuttle_fixture(
%{
shuttle_name: "SpecialShuttleName Bus",
disrupted_route_id: route.id,
status: :active
},
# include stops parameter
true,
# include times to next stop parameter - this was missing
true
)

# Use the fixture to create the replacement service instead of raw insert
Arrow.DisruptionsFixtures.replacement_service_fixture(%{
disruption_id: disruption_with_shuttle.id,
shuttle_id: shuttle.id,
start_date: ~D[2023-01-01],
end_date: ~D[2023-12-31]
})

# Add limits to both disruptions using the same route
insert(:limit, disruption: disruption_with_shuttle, route: route)
insert(:limit, disruption: disruption_without_shuttle, route: route)
Expand All @@ -161,13 +165,14 @@ defmodule ArrowWeb.DisruptionV2ControllerTest do

@tag :authenticated
test "empty search string returns all disruptions", %{conn: conn} do
route = insert(:gtfs_route) # Use insert to get a route with a unique ID

# Use insert to get a route with a unique ID
route = insert(:gtfs_route)

insert(:limit,
disruption: build(:disruption_v2, title: "First Disruption"),
route: route
)

insert(:limit,
disruption: build(:disruption_v2, title: "Second Disruption"),
route: route
Expand Down

0 comments on commit d1c8491

Please sign in to comment.