Skip to content

Commit

Permalink
PR updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ErinLMoore committed Sep 14, 2023
1 parent f38d2a8 commit e79c9ef
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 5 deletions.
7 changes: 5 additions & 2 deletions apps/parse/lib/parse/alerts.ex
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,11 @@ defmodule Parse.Alerts do
copy(url)
end

defp do_localized_image(%{"localized_image" => [%{"language" => "en", "url" => url} | _]}, _) do
copy(url)
defp do_localized_image(%{"localized_image" => [_ | _] = translations}, %{default: default}) do
case Enum.find(translations, &(&1["language"] == "en")) do
%{"language" => "en", "url" => url} -> url
_ -> default
end
end

defp active_period(%{"start" => start, "end" => stop}) do
Expand Down
51 changes: 48 additions & 3 deletions apps/parse/test/parse/alerts_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,7 @@ defmodule Parse.AlertsTest do
assert [%Alert{description: "Good morning"}] = parse_json(map)
end

test "returns english image url if available" do
test "returns english image url over unspecified language" do
url =
"https://dev-mbta.pantheonsite.io/sites/default/files/styles/max_2600x2600/public/media/2023-09/QuincyCenter-Braintree-EA.png"

Expand All @@ -456,15 +456,60 @@ defmodule Parse.AlertsTest do
"id" => "113791",
"image" => %{
"localized_image" => [
%{
"url" => "some_other_url",
"media_type" => "image/png",
"language" => "fr"
},
%{
"url" => url,
"media_type" => "image/png",
"language" => "en"
},
}
]
},
"informed_entity" => [%{}],
"last_modified_timestamp" => 1_494_947_991,
"last_push_notification_timestamp" => 1_494_947_991,
"service_effect_text" => [],
"severity" => 3,
"short_header_text" => [],
"timeframe_text" => []
}
]
}

assert [%Alert{image: ^url}] = parse_json(map)
end

test "returns english image url over other language" do
url =
"https://dev-mbta.pantheonsite.io/sites/default/files/styles/max_2600x2600/public/media/2023-09/QuincyCenter-Braintree-EA.png"

map = %{
"timestamp" => "1496832813",
"alerts" => [
%{
"active_period" => [],
"alert_lifecycle" => "NEW",
"cause" => "UNKNOWN_CAUSE",
"created_timestamp" => 1_494_947_991,
"description_text" => [],
"duration_certainty" => "KNOWN",
"effect" => "NO_SERVICE",
"effect_detail" => "STATION_CLOSURE",
"header_text" => [],
"id" => "113791",
"image" => %{
"localized_image" => [
%{
"url" => "some_other_url",
"media_type" => "image/png"
},
%{
"url" => url,
"media_type" => "image/png",
"language" => "fr"
"language" => "en"
}
]
},
Expand Down

0 comments on commit e79c9ef

Please sign in to comment.