Skip to content

Commit

Permalink
encode the url because ids can have spaces (#2011)
Browse files Browse the repository at this point in the history
  • Loading branch information
anthonyshull authored Apr 26, 2024
1 parent d9737d4 commit 316db52
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/mbta/api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule MBTA.Api do

@impl MBTA.Api.Behaviour
def get_json(url, params \\ []) do
case client() |> @req.get(url: url, params: params) do
case client() |> @req.get(url: URI.encode(url), params: params) do
{:ok, response} -> JsonApi.parse(response.body)
{:error, reason} -> {:error, reason}
end
Expand Down
16 changes: 16 additions & 0 deletions test/mbta/api_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@ defmodule MBTA.ApiTest do
setup :verify_on_exit!

describe "get_json/1" do
test "encodes the url" do
url = "/my busted id"

expect(Req.Mock, :new, fn _ ->
%Req.Request{}
end)

expect(Req.Mock, :get, fn _, options ->
assert options[:url] == URI.encode(url)

{:ok, %Req.Response{status: 200, body: ~s({"data": []})}}
end)

Api.get_json(url)
end

test "normal responses return a JsonApi struct" do
expect(Req.Mock, :new, fn _ ->
%Req.Request{}
Expand Down

0 comments on commit 316db52

Please sign in to comment.