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

bump_dependencies #16

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## [1.0.3] - 2024-02-19
### Fixed
- Upgrade dependencies to get rid of warnings with newer elixir. elixir 1.14 is the lowest supported version in mix.exs.

## [1.0.2] - 2022-02-14
### Fixed
- Arguments with struct values are now passed through Jabbax instead of raising an error [@vtm9](https://github.com/vtm9).
Expand Down Expand Up @@ -35,6 +39,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

[Unreleased]: https://github.com/surgeventures/jabbax/compare/v1.0.2...HEAD

[1.0.3]: https://github.com/surgeventures/jabbax/compare/v1.0.2...v1.0.3
[1.0.2]: https://github.com/surgeventures/jabbax/compare/v1.0.1...v1.0.2
[1.0.1]: https://github.com/surgeventures/jabbax/compare/v1.0.0...v1.0.1
[1.0.1]: https://github.com/surgeventures/jabbax/compare/v0.2.1...v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,8 +197,8 @@ Here's an example Jabbax config that you could add to your `config.exs`, along w

```elixir
config :jabbax,
json_encoder: Poison,
json_decoder: Poison
json_encoder: Jason,
json_decoder: Jason
```

## License
Expand Down
2 changes: 1 addition & 1 deletion config/config.exs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
use Mix.Config
require Config
12 changes: 3 additions & 9 deletions lib/jabbax/deserializer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ defmodule Jabbax.Deserializer do

defp deserialize_relationships(relationship_map)
when is_map(relationship_map) or is_list(relationship_map) do
relationship_map
|> Enum.map(&deserialize_relationship_pair/1)
|> Enum.into(%{})
Map.new(relationship_map, &deserialize_relationship_pair/1)
end

defp deserialize_relationships(relationship),
Expand Down Expand Up @@ -107,9 +105,7 @@ defmodule Jabbax.Deserializer do
defp dig_and_deserialize_links(_), do: %{}

defp deserialize_links(link_map) do
link_map
|> Enum.map(&deserialize_link_pair/1)
|> Enum.into(%{})
Map.new(link_map, &deserialize_link_pair/1)
end

defp deserialize_link_pair({name, link}) do
Expand Down Expand Up @@ -195,9 +191,7 @@ defmodule Jabbax.Deserializer do
defp deserialize_key_values(nil), do: %{}

defp deserialize_key_values(key_values_map = %{}) do
key_values_map
|> Enum.map(&deserialize_key_value_pair/1)
|> Enum.into(%{})
Map.new(key_values_map, &deserialize_key_value_pair/1)
end

defp deserialize_key_value_pair({name, value}) do
Expand Down
15 changes: 4 additions & 11 deletions lib/jabbax/serializer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ defmodule Jabbax.Serializer do
defp serialize_relationships(relationship_map) when relationship_map == %{}, do: nil

defp serialize_relationships(relationship_map = %{}) do
relationship_map
|> Enum.map(&serialize_relationship_pair/1)
|> Enum.into(%{})
Map.new(relationship_map, &serialize_relationship_pair/1)
end

defp serialize_relationships(arg) do
Expand Down Expand Up @@ -113,9 +111,7 @@ defmodule Jabbax.Serializer do
defp serialize_links(link_map) when link_map == %{}, do: nil

defp serialize_links(link_map = %{}) do
link_map
|> Enum.map(&serialize_link_pair/1)
|> Enum.into(%{})
Map.new(link_map, &serialize_link_pair/1)
end

defp serialize_links(arg) do
Expand Down Expand Up @@ -219,9 +215,7 @@ defmodule Jabbax.Serializer do
defp serialize_key_values(key_values_map) when key_values_map == %{}, do: nil

defp serialize_key_values(key_values_map = %{}) do
key_values_map
|> Enum.map(&serialize_key_value_pair/1)
|> Enum.into(%{})
Map.new(key_values_map, &serialize_key_value_pair/1)
end

defp serialize_key_values(arg) do
Expand All @@ -247,8 +241,7 @@ defmodule Jabbax.Serializer do
defp struct_to_map_with_present_keys(struct = %{}) do
struct
|> Map.from_struct()
|> Enum.filter(fn {_, value} -> value != nil end)
|> Enum.into(%{})
|> Map.filter(fn {_, value} -> value != nil end)
end

defp put_empty_data(doc = %{data: _}), do: doc
Expand Down
10 changes: 5 additions & 5 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ defmodule Jabbax.Mixfile do
def project do
[
app: :jabbax,
version: "1.0.2",
elixir: "~> 1.4",
version: "1.0.3",
elixir: "~> 1.14",
build_embedded: Mix.env() == :prod,
start_permanent: Mix.env() == :prod,
deps: deps(),
Expand Down Expand Up @@ -33,16 +33,16 @@ defmodule Jabbax.Mixfile do
end

def application do
[extra_applications: [:logger], env: [json_encoder: Poison, json_decoder: Poison]]
[extra_applications: [:logger], env: [json_encoder: Jason, json_decoder: Jason]]
end

defp deps do
[
{:credo, "~> 1.5", only: [:dev, :test], runtime: false},
{:credo, "~> 1.6", only: [:dev, :test], runtime: false},
{:ex_doc, ">= 0.0.0", only: :dev, runtime: false},
{:dialyxir, "~> 1.0", only: [:dev, :test], runtime: false},
{:plug, "~> 1.12", optional: true},
{:poison, "~> 3.0", optional: true}
{:jason, "~> 1.0", optional: true}
]
end
end
31 changes: 15 additions & 16 deletions mix.lock
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
%{
"bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm", "7af5c7e09fe1d40f76c8e4f9dd2be7cebd83909f31fee7cd0e9eadc567da8353"},
"credo": {:hex, :credo, "1.5.6", "e04cc0fdc236fefbb578e0c04bd01a471081616e741d386909e527ac146016c6", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2.8", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "4b52a3e558bd64e30de62a648518a5ea2b6e3e5d2b164ef5296244753fc7eb17"},
"dialyxir": {:hex, :dialyxir, "1.1.0", "c5aab0d6e71e5522e77beff7ba9e08f8e02bad90dfbeffae60eaf0cb47e29488", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "07ea8e49c45f15264ebe6d5b93799d4dd56a44036cf42d0ad9c960bc266c0b9a"},
"earmark_parser": {:hex, :earmark_parser, "1.4.13", "0c98163e7d04a15feb62000e1a891489feb29f3d10cb57d4f845c405852bbef8", [:mix], [], "hexpm", "d602c26af3a0af43d2f2645613f65841657ad6efc9f0e361c3b6c06b578214ba"},
"bunt": {:hex, :bunt, "1.0.0", "081c2c665f086849e6d57900292b3a161727ab40431219529f13c4ddcf3e7a44", [:mix], [], "hexpm", "dc5f86aa08a5f6fa6b8096f0735c4e76d54ae5c9fa2c143e5a1fc7c1cd9bb6b5"},
"credo": {:hex, :credo, "1.7.4", "68ca5cf89071511c12fd9919eb84e388d231121988f6932756596195ccf7fd35", [:mix], [{:bunt, "~> 0.2.1 or ~> 1.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:file_system, "~> 0.2 or ~> 1.0", [hex: :file_system, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm", "9cf776d062c78bbe0f0de1ecaee183f18f2c3ec591326107989b054b7dddefc2"},
"dialyxir": {:hex, :dialyxir, "1.4.3", "edd0124f358f0b9e95bfe53a9fcf806d615d8f838e2202a9f430d59566b6b53b", [:mix], [{:erlex, ">= 0.2.6", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm", "bf2cfb75cd5c5006bec30141b131663299c661a864ec7fbbc72dfa557487a986"},
"earmark_parser": {:hex, :earmark_parser, "1.4.39", "424642f8335b05bb9eb611aa1564c148a8ee35c9c8a8bba6e129d51a3e3c6769", [:mix], [], "hexpm", "06553a88d1f1846da9ef066b87b57c6f605552cfbe40d20bd8d59cc6bde41944"},
"erlex": {:hex, :erlex, "0.2.6", "c7987d15e899c7a2f34f5420d2a2ea0d659682c06ac607572df55a43753aa12e", [:mix], [], "hexpm", "2ed2e25711feb44d52b17d2780eabf998452f6efda104877a3881c2f8c0c0c75"},
"ex_doc": {:hex, :ex_doc, "0.24.2", "e4c26603830c1a2286dae45f4412a4d1980e1e89dc779fcd0181ed1d5a05c8d9", [:mix], [{:earmark_parser, "~> 1.4.0", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "e134e1d9e821b8d9e4244687fb2ace58d479b67b282de5158333b0d57c6fb7da"},
"file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"},
"jason": {:hex, :jason, "1.2.2", "ba43e3f2709fd1aa1dce90aaabfd039d000469c05c56f0b8e31978e03fa39052", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "18a228f5f0058ee183f29f9eae0805c6e59d61c3b006760668d8d18ff0d12179"},
"makeup": {:hex, :makeup, "1.0.5", "d5a830bc42c9800ce07dd97fa94669dfb93d3bf5fcf6ea7a0c67b2e0e4a7f26c", [:mix], [{:nimble_parsec, "~> 0.5 or ~> 1.0", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "cfa158c02d3f5c0c665d0af11512fed3fba0144cf1aadee0f2ce17747fba2ca9"},
"makeup_elixir": {:hex, :makeup_elixir, "0.15.1", "b5888c880d17d1cc3e598f05cdb5b5a91b7b17ac4eaf5f297cb697663a1094dd", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.1", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "db68c173234b07ab2a07f645a5acdc117b9f99d69ebf521821d89690ae6c6ec8"},
"makeup_erlang": {:hex, :makeup_erlang, "0.1.1", "3fcb7f09eb9d98dc4d208f49cc955a34218fc41ff6b84df7c75b3e6e533cc65f", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "174d0809e98a4ef0b3309256cbf97101c6ec01c4ab0b23e926a9e17df2077cbb"},
"mime": {:hex, :mime, "2.0.1", "0de4c81303fe07806ebc2494d5321ce8fb4df106e34dd5f9d787b637ebadc256", [:mix], [], "hexpm", "7a86b920d2aedce5fb6280ac8261ac1a739ae6c1a1ad38f5eadf910063008942"},
"nimble_parsec": {:hex, :nimble_parsec, "1.1.0", "3a6fca1550363552e54c216debb6a9e95bd8d32348938e13de5eda962c0d7f89", [:mix], [], "hexpm", "08eb32d66b706e913ff748f11694b17981c0b04a33ef470e33e11b3d3ac8f54b"},
"plug": {:hex, :plug, "1.12.1", "645678c800601d8d9f27ad1aebba1fdb9ce5b2623ddb961a074da0b96c35187d", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "d57e799a777bc20494b784966dc5fbda91eb4a09f571f76545b72a634ce0d30b"},
"plug_crypto": {:hex, :plug_crypto, "1.2.2", "05654514ac717ff3a1843204b424477d9e60c143406aa94daf2274fdd280794d", [:mix], [], "hexpm", "87631c7ad914a5a445f0a3809f99b079113ae4ed4b867348dd9eec288cecb6db"},
"poison": {:hex, :poison, "3.1.0", "d9eb636610e096f86f25d9a46f35a9facac35609a7591b3be3326e99a0484665", [:mix], [], "hexpm", "fec8660eb7733ee4117b85f55799fd3833eb769a6df71ccf8903e8dc5447cfce"},
"telemetry": {:hex, :telemetry, "1.0.0", "0f453a102cdf13d506b7c0ab158324c337c41f1cc7548f0bc0e130bbf0ae9452", [:rebar3], [], "hexpm", "73bc09fa59b4a0284efb4624335583c528e07ec9ae76aca96ea0673850aec57a"},
"ex_doc": {:hex, :ex_doc, "0.31.1", "8a2355ac42b1cc7b2379da9e40243f2670143721dd50748bf6c3b1184dae2089", [:mix], [{:earmark_parser, "~> 1.4.39", [hex: :earmark_parser, repo: "hexpm", optional: false]}, {:makeup_c, ">= 0.1.1", [hex: :makeup_c, repo: "hexpm", optional: true]}, {:makeup_elixir, "~> 0.14", [hex: :makeup_elixir, repo: "hexpm", optional: false]}, {:makeup_erlang, "~> 0.1", [hex: :makeup_erlang, repo: "hexpm", optional: false]}], "hexpm", "3178c3a407c557d8343479e1ff117a96fd31bafe52a039079593fb0524ef61b0"},
"file_system": {:hex, :file_system, "1.0.0", "b689cc7dcee665f774de94b5a832e578bd7963c8e637ef940cd44327db7de2cd", [:mix], [], "hexpm", "6752092d66aec5a10e662aefeed8ddb9531d79db0bc145bb8c40325ca1d8536d"},
"jason": {:hex, :jason, "1.4.1", "af1504e35f629ddcdd6addb3513c3853991f694921b1b9368b0bd32beb9f1b63", [:mix], [{:decimal, "~> 1.0 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm", "fbb01ecdfd565b56261302f7e1fcc27c4fb8f32d56eab74db621fc154604a7a1"},
"makeup": {:hex, :makeup, "1.1.1", "fa0bc768698053b2b3869fa8a62616501ff9d11a562f3ce39580d60860c3a55e", [:mix], [{:nimble_parsec, "~> 1.2.2 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "5dc62fbdd0de44de194898b6710692490be74baa02d9d108bc29f007783b0b48"},
"makeup_elixir": {:hex, :makeup_elixir, "0.16.1", "cc9e3ca312f1cfeccc572b37a09980287e243648108384b97ff2b76e505c3555", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}, {:nimble_parsec, "~> 1.2.3 or ~> 1.3", [hex: :nimble_parsec, repo: "hexpm", optional: false]}], "hexpm", "e127a341ad1b209bd80f7bd1620a15693a9908ed780c3b763bccf7d200c767c6"},
"makeup_erlang": {:hex, :makeup_erlang, "0.1.4", "29563475afa9b8a2add1b7a9c8fb68d06ca7737648f28398e04461f008b69521", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm", "f4ed47ecda66de70dd817698a703f8816daa91272e7e45812469498614ae8b29"},
"mime": {:hex, :mime, "2.0.5", "dc34c8efd439abe6ae0343edbb8556f4d63f178594894720607772a041b04b02", [:mix], [], "hexpm", "da0d64a365c45bc9935cc5c8a7fc5e49a0e0f9932a761c55d6c52b142780a05c"},
"nimble_parsec": {:hex, :nimble_parsec, "1.4.0", "51f9b613ea62cfa97b25ccc2c1b4216e81df970acd8e16e8d1bdc58fef21370d", [:mix], [], "hexpm", "9c565862810fb383e9838c1dd2d7d2c437b3d13b267414ba6af33e50d2d1cf28"},
"plug": {:hex, :plug, "1.15.3", "712976f504418f6dff0a3e554c40d705a9bcf89a7ccef92fc6a5ef8f16a30a97", [:mix], [{:mime, "~> 1.0 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:plug_crypto, "~> 1.1.1 or ~> 1.2 or ~> 2.0", [hex: :plug_crypto, repo: "hexpm", optional: false]}, {:telemetry, "~> 0.4.3 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "cc4365a3c010a56af402e0809208873d113e9c38c401cabd88027ef4f5c01fd2"},
"plug_crypto": {:hex, :plug_crypto, "2.0.0", "77515cc10af06645abbfb5e6ad7a3e9714f805ae118fa1a70205f80d2d70fe73", [:mix], [], "hexpm", "53695bae57cc4e54566d993eb01074e4d894b65a3766f1c43e2c61a1b0f45ea9"},
"telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"},
}
38 changes: 24 additions & 14 deletions test/jabbax/parser_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,52 @@ defmodule Jabbax.ParserTest do
use Plug.Test
use Jabbax.Document

@sample_json %{
"data" => %{
"id" => "1",
"type" => "user",
"attributes" => %{
"name" => "Sample User"
@sample_json """
{
"data": {
"id": "1",
"type": "user",
"attributes": {
"name": "Sample User"
}
},
"jsonapi" => %{
"version" => "1.0"
"jsonapi": {
"version": "1.0"
}
}
"""

def parse(conn, opts \\ []) do
opts =
opts
|> Keyword.put_new(:parsers, [Jabbax.Parser])
|> Keyword.put_new(:json_decoder, Poison)
|> Keyword.put_new(:json_decoder, Jason)

Plug.Parsers.call(conn, Plug.Parsers.init(opts))
end

test "JSON API document" do
connection =
:post
|> conn("/", Poison.encode!(@sample_json))
|> conn("/", @sample_json)
|> put_req_header("content-type", "application/vnd.api+json")
|> parse()

assert connection.body_params == @sample_json
assert connection.body_params ==
%{
"data" => %{
"attributes" => %{"name" => "Sample User"},
"id" => "1",
"type" => "user"
},
"jsonapi" => %{"version" => "1.0"}
}
end

test "plain JSON content type without JSON parser" do
connection =
:post
|> conn("/", Poison.encode!(@sample_json))
|> conn("/", @sample_json)
|> put_req_header("content-type", "application/json")

assert_raise(Plug.Parsers.UnsupportedMediaTypeError, fn ->
Expand All @@ -49,7 +59,7 @@ defmodule Jabbax.ParserTest do
test "no content type" do
connection =
:post
|> conn("/", Poison.encode!(@sample_json))
|> conn("/", @sample_json)
|> parse()

assert connection.body_params == %{}
Expand All @@ -75,7 +85,7 @@ defmodule Jabbax.ParserTest do
test "custom body_reader" do
connection =
:post
|> conn("/", Poison.encode!(@sample_json))
|> conn("/", @sample_json)
|> put_req_header("content-type", "application/vnd.api+json")
|> parse(body_reader: {BodyReader, :read_body, []})

Expand Down
50 changes: 27 additions & 23 deletions test/jabbax/plug_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@ defmodule Jabbax.PlugTest do
use Plug.Test
use Jabbax.Document

@sample_json %{
"data" => %{
"id" => "1",
"type" => "user",
"attributes" => %{
"name" => "Sample User"
@sample_json """
{
"data": {
"id": "1",
"type": "user",
"attributes": {
"name": "Sample User"
}
},
"jsonapi" => %{
"version" => "1.0"
"jsonapi": {
"version": "1.0"
}
}
"""

@sample_doc %Document{
data: %Resource{
Expand All @@ -28,13 +30,13 @@ defmodule Jabbax.PlugTest do
}

def parse(conn, parsers) do
Plug.Parsers.call(conn, Plug.Parsers.init(parsers: parsers, json_decoder: Poison))
Plug.Parsers.call(conn, Plug.Parsers.init(parsers: parsers, json_decoder: Jason))
end

test "JSON API document" do
connection =
:post
|> conn("/", Poison.encode!(@sample_json))
|> conn("/", @sample_json)
|> put_req_header("content-type", "application/vnd.api+json")
|> parse([Jabbax.Parser])
|> Jabbax.Plug.call(Jabbax.Plug.init(nil))
Expand All @@ -45,7 +47,7 @@ defmodule Jabbax.PlugTest do
test "JSON API document with custom assign name" do
connection =
:post
|> conn("/", Poison.encode!(@sample_json))
|> conn("/", @sample_json)
|> put_req_header("content-type", "application/vnd.api+json")
|> parse([Jabbax.Parser])
|> Jabbax.Plug.call(Jabbax.Plug.init(assign: :custom_doc))
Expand All @@ -56,7 +58,7 @@ defmodule Jabbax.PlugTest do
test "other content type" do
connection =
:post
|> conn("/", Poison.encode!(@sample_json))
|> conn("/", @sample_json)
|> put_req_header("content-type", "application/json")
|> parse([:json, Jabbax.Parser])
|> Jabbax.Plug.call(Jabbax.Plug.init(nil))
Expand All @@ -65,26 +67,28 @@ defmodule Jabbax.PlugTest do
end

test "malformed body" do
malformed_body = %{
"data" => %{
"type" => "employees",
"relationships" => %{
"service" => %{
"dataaa" => %{
"type" => "services",
"id" => "21"
malformed_body = """
{
"data": {
"type": "employees",
"relationships": {
"service": {
"dataaa": {
"type": "services",
"id": "21"
}
}
}
},
"jsonapi" => %{
"version" => "1.0"
"jsonapi": {
"version": "1.0"
}
}
"""

assert_raise(Plug.Parsers.ParseError, fn ->
:post
|> conn("/", Poison.encode!(malformed_body))
|> conn("/", malformed_body)
|> put_req_header("content-type", "application/vnd.api+json")
|> parse([Jabbax.Parser])
|> Jabbax.Plug.call(Jabbax.Plug.init(nil))
Expand Down
2 changes: 1 addition & 1 deletion test/jabbax_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ defmodule JabbaxTest do

test "encode!" do
assert Jabbax.encode!(%Document{}) ==
~s({"jsonapi":{"version":"1.0"},"data":null})
~s({"data":null,"jsonapi":{"version":"1.0"}})
end
end