EspecJsonapi
Collection of matchers to help with testing JSONAPI responses with ESpec
Installation
If available in Hex, the package can be installed
by adding espec_jsonapi to your list of dependencies in mix.exs:
def deps do
[
{:espec_jsonapi, "~> 1.0.1"}
]
endExample
defmodule SomeSpec do
use ESpec
import EspecJsonapi
it "has the correct type" do
response = %{ "data" => %{ "type" => "user" } }
expect(response["data"]) |> to(have_type("user"))
end
endMatchers
expect(response["data"]) |> to(have_id("1"))expect(response["data"]) |> to(have_type("user"))expect(response["data"]) |> to(have_attribute("name"))expect(response["data"]) |> to(have_attribute("name") |> with_value("John"))expect(response["data"]) |> to(have_attributes(["age", "name", "gender"]))expect(response["data"]) |> to(have_relationship("author"))expect(response["data"]) |> to(have_relationship("author") |> with_data(%{ "id" => 1, "type" => "author"}))expect(response["data"]) |> to(have_relationships(["author", "owner", "comments"]))expect(response["data"]) |> to(have_link("self"))expect(response["data"]) |> to(have_link("self") |> with_value("http://api.example.com/users/12"))expect(response["data"]) |> to(have_links(["self", "author"]))