Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion lib/dotcom_web/plugs/rewrite_urls.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@ defmodule DotcomWeb.Plugs.RewriteUrls do
end
end

# Send SF1.0 URLS to the new SF2.0
defp rewrite_url(
%{
path_info: ["schedules", _, "line"],
params: %{
"route" => route_id,
"schedule_finder" => %{"direction_id" => direction_id, "origin" => stop_id}
}
} = conn
) do
"/departures/?route_id=#{route_id}&direction_id=#{direction_id}&stop_id=#{stop_id}"
end

defp rewrite_url(%{path_info: ["schedules", "Boat-F3" | _]} = conn) do
String.replace(conn.request_path, "Boat-F3", "Boat-F1")
end
Expand All @@ -38,6 +51,10 @@ defmodule DotcomWeb.Plugs.RewriteUrls do
end

defp merge_url(base_url, query_string) do
"#{base_url}?#{query_string}"
if base_url |> String.contains?("?") do
"#{base_url}&#{query_string}"
else
"#{base_url}?#{query_string}"
end
end
end
22 changes: 22 additions & 0 deletions test/dotcom_web/plugs/rewrite_urls_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,28 @@ defmodule DotcomWeb.Plugs.RewriteUrlsTest do
assert conn.halted
end

test "redirects if we're going to the old schedule finder", %{conn: conn} do
route_id = Faker.Pokemon.name()
direction_id = Faker.Util.pick(["0", "1"])
stop_id = Faker.Pokemon.name()

conn = %{
conn
| params: %{
"route" => route_id,
"schedule_finder" => %{"direction_id" => direction_id, "origin" => stop_id}
},
path_info: ["schedules", "red", "line"]
}

conn = call(conn, [])

assert redirected_to(conn, 302) ==
"/departures/?route_id=#{route_id}&direction_id=#{direction_id}&stop_id=#{stop_id}"

assert conn.halted
end

test "includes a query string if present", %{conn: conn} do
conn = %{
conn
Expand Down
Loading