Skip to content
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
7 changes: 7 additions & 0 deletions lib/absinthe_error_payload/test_helper.ex
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,13 @@ defmodule AbsintheErrorPayload.TestHelper do
assert {field, expected} == {field, response}
end

defp assert_values_match({_field, %{} = sub_fields, expected, response}) do
sub_fields
|> Enum.to_list()
|> Enum.map(fn field_tuple -> value_tuple(field_tuple, expected, response) end)
|> Enum.each(&assert_values_match/1)
end

defp assert_values_match({field, _type, expected, response}) do
assert {field, expected} == {field, response}
end
Expand Down
47 changes: 47 additions & 0 deletions test/test_helper_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ defmodule AbsintheErrorPayload.TestHelperTest do
}
end

def nested_fields do
%{
root: :string,
single: %{
string: :string,
integer: :integer,
nillable: :nillable
}
}
end

def input do
%{
date: @time,
Expand Down Expand Up @@ -51,6 +62,17 @@ defmodule AbsintheErrorPayload.TestHelperTest do
}
end

def nested_input do
%{
root: "root string",
single: %{
string: "single nested string",
integer: 1,
nillable: nil
}
}
end

def graphql do
%{
"date" => to_string(@time),
Expand Down Expand Up @@ -78,6 +100,17 @@ defmodule AbsintheErrorPayload.TestHelperTest do
}
end

def nested_graphql do
%{
"root" => "root string",
"single" => %{
"string" => "single nested string",
"integer" => 1,
"nillable" => nil
}
}
end

describe "assert_equivalent_graphql/3" do
test "all types compare" do
assert_equivalent_graphql(input(), graphql(), fields())
Expand All @@ -94,6 +127,10 @@ defmodule AbsintheErrorPayload.TestHelperTest do
fields()
)
end

test "nested fields compare" do
assert_equivalent_graphql(nested_input(), nested_graphql(), nested_fields())
end
end

describe "assert_mutation_success/3" do
Expand All @@ -106,6 +143,16 @@ defmodule AbsintheErrorPayload.TestHelperTest do

assert_mutation_success(input(), mutation_response, fields())
end

test "matches result with nested fields" do
mutation_response = %{
"successful" => true,
"messages" => [],
"result" => nested_graphql()
}

assert_mutation_success(nested_input(), mutation_response, nested_fields())
end
end

describe "assert_mutation_failure/3" do
Expand Down