From 78f7df273628f086e4234f946e4f8023e68bfd7d Mon Sep 17 00:00:00 2001 From: rstoyanchev Date: Tue, 30 Jan 2024 09:24:01 +0000 Subject: [PATCH] Consistently check errors in GraphQlTester Closes gh-891 --- .../test/tester/DefaultGraphQlTester.java | 3 ++- .../graphql/test/tester/GraphQlTesterTests.java | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/spring-graphql-test/src/main/java/org/springframework/graphql/test/tester/DefaultGraphQlTester.java b/spring-graphql-test/src/main/java/org/springframework/graphql/test/tester/DefaultGraphQlTester.java index 38063898..882cd0a1 100644 --- a/spring-graphql-test/src/main/java/org/springframework/graphql/test/tester/DefaultGraphQlTester.java +++ b/spring-graphql-test/src/main/java/org/springframework/graphql/test/tester/DefaultGraphQlTester.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -296,6 +296,7 @@ final class DefaultGraphQlTester implements GraphQlTester { @Override public Path path(String path, Consumer pathConsumer) { + this.delegate.verifyErrors(); return DefaultPath.forNestedPath(null, path, this.delegate, pathConsumer); } diff --git a/spring-graphql-test/src/test/java/org/springframework/graphql/test/tester/GraphQlTesterTests.java b/spring-graphql-test/src/test/java/org/springframework/graphql/test/tester/GraphQlTesterTests.java index e8a0b324..20ec2061 100644 --- a/spring-graphql-test/src/test/java/org/springframework/graphql/test/tester/GraphQlTesterTests.java +++ b/spring-graphql-test/src/test/java/org/springframework/graphql/test/tester/GraphQlTesterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2023 the original author or authors. + * Copyright 2002-2024 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -292,6 +292,21 @@ public class GraphQlTesterTests extends GraphQlTesterTestSupport { assertThat(getActualRequestDocument()).contains(document); } + @Test // gh-891 + void errorsCheckedOnTraverseWithConsumer() { + + String document = "{me {name, friends}}"; + getGraphQlService().setError(document, builder -> builder.message("Invalid query")); + + assertThatThrownBy(() -> + graphQlTester().document(document) + .execute() + .path("me", it -> it.path("name").hasValue())) + .hasMessageContaining("Response has 1 unexpected error(s)"); + + assertThat(getActualRequestDocument()).contains(document); + } + @Test void errorsPartiallyFiltered() {