Check for missing errors in GraphQlTester#executeAndVerify

Prior to this commit, the `GraphQlTester#executeAndVerify` method would
check that an `"$.errors"` JSON path exists within the response and
contains no value.

This should fail with valid GraphQL responses, as the spec says that a
response with no error should not contain the errors map at all:
http://spec.graphql.org/draft/#sec-Errors

This commit changes the assertion and instead checks for the absence of
the errors map in the response.

Fixes gh-318
This commit is contained in:
Brian Clozel
2022-03-07 22:42:36 +01:00
parent b40375f1f2
commit c6d10d3ab8
2 changed files with 12 additions and 1 deletions

View File

@@ -170,7 +170,7 @@ final class DefaultGraphQlTester implements GraphQlTester {
@Override
public void executeAndVerify() {
execute().path("$.errors").valueIsEmpty();
execute().path("$.errors").pathDoesNotExist();
}
@Override

View File

@@ -186,6 +186,17 @@ public class GraphQlTesterTests extends GraphQlTesterTestSupport {
assertThat(input.getVariables()).containsEntry("keyOnly", null);
}
@Test
void errorsEmptyOnExecuteAndVerify() {
String document = "{me {name, friends}}";
setMockResponse("{\"me\": {\"name\":\"Luke Skywalker\", \"friends\":[]}}");
graphQlTester().document(document).executeAndVerify();
assertThat(requestInput().getDocument()).contains(document);
}
@Test
void errorsCheckedOnExecuteAndVerify() {