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

Replace JSX with Jason #409

Merged
merged 3 commits into from
May 10, 2020
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 mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ defmodule HTTPoison.Mixfile do
[
{:hackney, "~> 1.15 and >= 1.15.2"},
{:mimic, "~> 0.1", only: :test},
{:exjsx, "~> 3.1", only: :test},
{:jason, "~> 1.2", only: :test},
{:httparrot, "~> 1.2", only: :test},
{:earmark, "~> 1.0", only: :dev},
{:ex_doc, "~> 0.18", only: :dev},
Expand Down
15 changes: 6 additions & 9 deletions test/httpoison_test.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
defmodule HTTPoisonTest do
use ExUnit.Case, async: true
import PathHelpers
alias Jason

test "get" do
assert_response(HTTPoison.get("localhost:8080/deny"), fn response ->
Expand All @@ -12,7 +13,7 @@ defmodule HTTPoisonTest do
resp = HTTPoison.get("localhost:8080/get", [], params: %{foo: "bar", baz: "bong"})

assert_response(resp, fn response ->
args = JSX.decode!(response.body)["args"]
args = Jason.decode!(response.body)["args"]
assert args["foo"] == "bar"
assert args["baz"] == "bong"
assert args |> Map.keys() |> length == 2
Expand All @@ -28,7 +29,7 @@ defmodule HTTPoisonTest do
)

assert_response(resp, fn response ->
args = JSX.decode!(response.body)["args"]
args = Jason.decode!(response.body)["args"]
assert args["foo"] == ["first", "second"]
assert args["baz"] == "bong"
assert args["bar"] == "zing"
Expand Down Expand Up @@ -159,11 +160,7 @@ defmodule HTTPoisonTest do

test "send cookies" do
response = HTTPoison.get!("localhost:8080/cookies", %{}, hackney: [cookie: ["foo=1; bar=2"]])

assert response.body
|> String.replace(~r/\s|\r?\n/, "")
|> String.replace(~r/\"/, "'")
|> JSX.decode!() == %{"cookies" => %{"foo" => "1", "bar" => "2"}}
assert Jason.decode!(response.body) == %{"cookies" => %{"foo" => "1", "bar" => "2"}}
end

test "receive cookies" do
Expand Down Expand Up @@ -239,13 +236,13 @@ defmodule HTTPoisonTest do

test "post streaming body" do
expected = %{"some" => "bytes"}
enumerable = JSX.encode!(expected) |> String.split("")
enumerable = Jason.encode!(expected) |> String.split("")
headers = %{"Content-type" => "application/json"}
response = HTTPoison.post("localhost:8080/post", {:stream, enumerable}, headers)
assert_response(response)
{:ok, %HTTPoison.Response{body: body}} = response

assert JSX.decode!(body)["json"] == expected
assert Jason.decode!(body)["json"] == expected
end

test "max_body_length limits body size" do
Expand Down