Skip to content

Commit

Permalink
feat: add data to RouteStop changeset error for an invalid stop ID (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
meagharty authored Jan 14, 2025
1 parent 14583cd commit ccb0410
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
13 changes: 9 additions & 4 deletions lib/arrow/shuttles/route_stop.ex
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,14 @@ defmodule Arrow.Shuttles.RouteStop do
if display_stop_id = Ecto.Changeset.get_change(change, :display_stop_id) do
{stop_id, gtfs_stop_id, stop, error} =
case Shuttles.stop_or_gtfs_stop_for_stop_id(display_stop_id) do
%Stop{id: id} = stop -> {id, nil, stop, nil}
%GtfsStop{id: id} = stop -> {nil, id, stop, nil}
nil -> {nil, nil, nil, "not a valid stop ID"}
%Stop{id: id} = stop ->
{id, nil, stop, nil}

%GtfsStop{id: id} = stop ->
{nil, id, stop, nil}

nil ->
{nil, nil, nil, "not a valid stop ID '%{display_stop_id}'"}
end

change =
Expand All @@ -64,7 +69,7 @@ defmodule Arrow.Shuttles.RouteStop do
if is_nil(error) do
change
else
add_error(change, :display_stop_id, error)
add_error(change, :display_stop_id, error, display_stop_id: display_stop_id)
end
else
change
Expand Down
5 changes: 4 additions & 1 deletion test/arrow/shuttle/route_stop_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ defmodule Arrow.Shuttles.RouteStopTest do

assert %Ecto.Changeset{
valid?: false,
errors: [display_stop_id: {"not a valid stop ID", []}]
errors: [
display_stop_id:
{"not a valid stop ID '%{display_stop_id}'", [display_stop_id: "invalid_id"]}
]
} = changeset
end

Expand Down

0 comments on commit ccb0410

Please sign in to comment.