diff --git a/lib/absinthe_error_payload/test_helper.ex b/lib/absinthe_error_payload/test_helper.ex index ba17d30..16ec485 100644 --- a/lib/absinthe_error_payload/test_helper.ex +++ b/lib/absinthe_error_payload/test_helper.ex @@ -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 diff --git a/test/test_helper_test.exs b/test/test_helper_test.exs index 7a7a53e..b9195a5 100644 --- a/test/test_helper_test.exs +++ b/test/test_helper_test.exs @@ -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, @@ -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), @@ -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()) @@ -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 @@ -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