Skip to content

Commit

Permalink
Add test for issue #19
Browse files Browse the repository at this point in the history
  • Loading branch information
xinz committed Feb 14, 2023
1 parent ecb1f62 commit 6ba2fbd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 0 additions & 2 deletions lib/oasis/parser.ex
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ defmodule Oasis.Parser do
def parse(%{"type" => "null"}, nil), do: nil

def parse(%{"type" => "array"} = type, value) when is_list(value) do
# post request body as :urlencoded or :multipart
do_parse_array(type, value)
end

def parse(%{"type" => "object"} = type, value) when is_map(value) do
# post request body as :urlencoded or :multipart
do_parse_object(type, value)
end

Expand Down
6 changes: 6 additions & 0 deletions test/integration_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -498,6 +498,12 @@ defmodule Oasis.IntegrationTest do
start_supervised!({Finch, name: TestFinch})

headers = [{"content-type", "application/json"}]
body = "[{\"id2\":1,\"name2\":\"hello\"}]"

assert {:ok, response} = Finch.build(:post, "#{url}/test_post_json", headers, body) |> Finch.request(TestFinch)
assert response.status == 400 and
response.body == "Find body parameter `body_request` with error: Required properties id, name were not present."

body = "[{\"id\":1,\"name\":\"hello\"}]"

assert {:ok, response} = Finch.build(:post, "#{url}/test_post_json", headers, body) |> Finch.request(TestFinch)
Expand Down
3 changes: 2 additions & 1 deletion test/support/gen/plug/pre_test_post_json.ex
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ defmodule Oasis.Gen.Plug.PreTestPostJSON do
"properties" => %{
"id" => %{"type" => "integer"},
"name" => %{"type" => "string"}
}
},
"required" => ["id", "name"],
},
"type" => "array"
}
Expand Down

0 comments on commit 6ba2fbd

Please sign in to comment.