absinthe_error_payload icon indicating copy to clipboard operation
absinthe_error_payload copied to clipboard

Make the test helpers compatible with nested fields

Open niels opened this issue 3 years ago • 0 comments

Previously, a GraphQL document containing nested fields could not be tested if one of the values was null / nil. The library stringifies the expected response, coercing nil to "". The assert_values_match was not able to take into account the field being defined as nillable because it wasn't aware of the nesting. This led to the below mismatch:

  1) test assert_equivalent_graphql/3 nested fields compare (AbsintheErrorPayload.TestHelperTest)
     test/test_helper_test.exs:131
     Assertion with == failed
     code:  assert {field, expected} == {field, response}
     left:  {
              :single,
              %{
                "integer" => "1",
                "nillable" => "",
                "string" => "single nested string"
              }
            }
     right: {
              :single,
              %{
                "integer" => 1,
                "nillable" => nil,
                "string" => "single nested string"
              }
            }
     stacktrace:
       (elixir 1.11.3) lib/enum.ex:798: Enum."-each/2-lists^foreach/1-0-"/2
       test/test_helper_test.exs:132: (test)

This PR adds a new assert_values_match so that nested field definitions get recursively resolved.

niels avatar Apr 10 '21 15:04 niels