Skip to content

Commit

Permalink
fix test failures due to map key ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
paulanthonywilson authored and edgurgel committed Nov 7, 2023
1 parent 24a3908 commit 0b8c71a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 19 deletions.
35 changes: 20 additions & 15 deletions test/httpoison_base_test.exs
Expand Up @@ -106,27 +106,32 @@ defmodule HTTPoisonBaseTest do
end

test "request body using params example" do
expect(:hackney, :request, fn :get, "http://localhost?foo=bar&key=fizz", [], "", [] ->
expected_query = %{"foo" => "bar", "key" => "fizz"}

expect(:hackney, :request, fn :get, "http://localhost?" <> query, [], "", [] ->
assert expected_query == URI.decode_query(query)
{:ok, 200, "headers", :client}
end)

expect(:hackney, :body, fn _, _ -> {:ok, "response"} end)

assert ExampleParamsOptions.get!("localhost", [], params: %{foo: "bar"}) ==
%HTTPoison.Response{
status_code: 200,
headers: "headers",
body: "response",
request_url: "http://localhost?foo=bar&key=fizz",
request: %HTTPoison.Request{
body: "",
headers: [],
method: :get,
options: [params: %{foo: "bar", key: "fizz"}],
params: %{foo: "bar", key: "fizz"},
url: "http://localhost?foo=bar&key=fizz"
}
assert %HTTPoison.Response{
status_code: 200,
headers: "headers",
body: "response",
request_url: "http://localhost?" <> request_url_query,
request: %HTTPoison.Request{
body: "",
headers: [],
method: :get,
options: [params: %{foo: "bar", key: "fizz"}],
params: %{foo: "bar", key: "fizz"},
url: "http://localhost?" <> url_query
}
} = ExampleParamsOptions.get!("localhost", [], params: %{foo: "bar"})

assert expected_query == URI.decode_query(request_url_query)
assert expected_query == URI.decode_query(url_query)
end

test "get!/1 raises error tuple" do
Expand Down
10 changes: 6 additions & 4 deletions test/httpoison_test.exs
Expand Up @@ -19,8 +19,10 @@ defmodule HTTPoisonTest do
assert args["baz"] == "bong"
assert args |> Map.keys() |> length == 2

assert Request.to_curl(response.request) ==
{:ok, "curl -X GET http://localhost:4002/get?baz=bong&foo=bar"}
assert {:ok, "curl -X GET http://localhost:4002/get?" <> query} =
Request.to_curl(response.request)

assert %{"baz" => "bong", "foo" => "bar"} == URI.decode_query(query)
end)
end

Expand Down Expand Up @@ -53,7 +55,7 @@ defmodule HTTPoisonTest do
end

test "post charlist body" do
assert_response(HTTPoison.post("localhost:4002/post", 'test'), fn response ->
assert_response(HTTPoison.post("localhost:4002/post", ~c"test"), fn response ->
assert Request.to_curl(response.request) == {:ok, "curl -X POST http://localhost:4002/post"}
end)
end
Expand Down Expand Up @@ -233,7 +235,7 @@ defmodule HTTPoisonTest do
end

test "char list URL" do
assert_response(HTTPoison.head('localhost:4002/get'), fn response ->
assert_response(HTTPoison.head(~c"localhost:4002/get"), fn response ->
assert Request.to_curl(response.request) ==
{:ok, "curl -X HEAD http://localhost:4002/get"}
end)
Expand Down

0 comments on commit 0b8c71a

Please sign in to comment.