Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encode the url because ids can have spaces #2011

Merged
merged 1 commit into from
Apr 26, 2024
Merged
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
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)
thecristen marked this conversation as resolved.
Show resolved Hide resolved
end

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