Skip to content

Commit

Permalink
Fix route id access path and create fallback pattern match to prevent… (
Browse files Browse the repository at this point in the history
#2144)

* fix route id access path and create fallback pattern match to prevent future crashes

* add some detail to logs

* better naming of vars and change test data structure
  • Loading branch information
anthonyshull authored Aug 15, 2024
1 parent ae26658 commit f3a8bbb
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
13 changes: 12 additions & 1 deletion lib/dotcom_web/controllers/trip_plan/feedback_csv.ex
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ defmodule DotcomWeb.TripPlan.FeedbackCSV do
Handle formatting feedback into a spreadsheet-friendly format.
"""

require Logger

alias TripPlan.PersonalDetail.Step

@headers [
Expand Down Expand Up @@ -132,7 +134,7 @@ defmodule DotcomWeb.TripPlan.FeedbackCSV do
"#{place_description(from)} to #{place_description(to)} via #{mode_description(mode)}"
end

defp mode_description(%{"route_id" => route_id, "trip_id" => trip_id}),
defp mode_description(%{"route" => %{"id" => route_id}, "trip_id" => trip_id}),
do: route_id <> " route on trip " <> trip_id

defp mode_description(%{"steps" => steps, "distance" => distance}) do
Expand All @@ -153,4 +155,13 @@ defmodule DotcomWeb.TripPlan.FeedbackCSV do

"walking #{distance} meters:\n\t#{step_description}"
end

defp mode_description(mode) do
trip_id = Map.get(mode, "trip_id")
type = Map.get(mode, "mode")

Logger.error("#{__MODULE__} error=unknown_mode trip_id=#{trip_id} type=#{type}")

"unknown"
end
end
20 changes: 15 additions & 5 deletions test/dotcom_web/controllers/trip_plan/feedback_csv_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,9 @@ defmodule DotcomWeb.TripPlan.FeedbackCSVTest do
},
"mode" => %{
"trip_id" => "60166270",
"route_id" => "4",
"route" => %{
"id" => "4"
},
"intermediate_stop_ids" => [
"233",
"234",
Expand Down Expand Up @@ -317,7 +319,9 @@ defmodule DotcomWeb.TripPlan.FeedbackCSVTest do
},
"mode" => %{
"trip_id" => "60564830",
"route_id" => "Green-D",
"route" => %{
"id" => "Green-D"
},
"intermediate_stop_ids" => [
"70204",
"70202"
Expand Down Expand Up @@ -376,7 +380,9 @@ defmodule DotcomWeb.TripPlan.FeedbackCSVTest do
},
"mode" => %{
"trip_id" => "60392520",
"route_id" => "Red",
"route" => %{
"id" => "Red"
},
"intermediate_stop_ids" => [
"70077"
]
Expand Down Expand Up @@ -405,7 +411,9 @@ defmodule DotcomWeb.TripPlan.FeedbackCSVTest do
},
"mode" => %{
"trip_id" => "60455437",
"route_id" => "Orange",
"route" => %{
"id" => "Orange"
},
"intermediate_stop_ids" => [
"70024",
"70022"
Expand Down Expand Up @@ -470,7 +478,9 @@ defmodule DotcomWeb.TripPlan.FeedbackCSVTest do
},
"mode" => %{
"trip_id" => "60392519",
"route_id" => "Red",
"route" => %{
"id" => "Red"
},
"intermediate_stop_ids" => []
},
"from" => %{
Expand Down

0 comments on commit f3a8bbb

Please sign in to comment.