Skip to content

Commit

Permalink
Merge pull request #409 from niklaslong/jason
Browse files Browse the repository at this point in the history
Replace JSX with Jason
  • Loading branch information
edgurgel authored May 10, 2020
2 parents b651028 + f868198 commit ae7a8ea
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
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

0 comments on commit ae7a8ea

Please sign in to comment.