Skip to content
This repository was archived by the owner on Dec 19, 2023. It is now read-only.

Commit b756b45

Browse files
feat(#475): make post public, add integration test for it
1 parent 613878f commit b756b45

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

graphql-spring-boot-test/src/main/java/com/graphql/spring/boot/test/GraphQLTestTemplate.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,12 @@ public GraphQLResponse postMultipart(String query, String variables) {
307307
return postRequest(RequestFactory.forMultipart(query, variables, headers));
308308
}
309309

310-
private GraphQLResponse post(String payload) {
310+
/**
311+
* Performs a GraphQL request with the provided payload.
312+
* @param payload the GraphQL payload
313+
* @return @return {@link GraphQLResponse} containing the result of query execution
314+
*/
315+
public GraphQLResponse post(String payload) {
311316
return postRequest(RequestFactory.forJson(payload, headers));
312317
}
313318

graphql-spring-boot-test/src/test/java/com/graphql/spring/boot/test/GraphQLTestTemplateIntegrationTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,23 @@ void testPerformWithAllInputs() throws IOException {
162162
.and().assertThatField(DATA_FIELD_QUERY_WITH_VARIABLES).asString().isEqualTo(INPUT_STRING_VALUE)
163163
.and().assertThatField(DATA_FIELD_FOO_BAR).as(FooBar.class).isEqualTo(new FooBar(FOO, BAR));
164164
}
165+
166+
@Test
167+
@DisplayName("Test post with custom payload.")
168+
void testPost() {
169+
// GIVEN
170+
final HttpHeaders httpHeaders = new HttpHeaders();
171+
httpHeaders.add(TEST_HEADER_NAME, TEST_HEADER_VALUE);
172+
final String payload = "{\"query\":"
173+
+ "\"query ($input: String!, $headerName: String!) "
174+
+ "{ queryWithVariables(input: $input) queryWithHeader(headerName: $headerName) }\", "
175+
+ "\"variables\": {\"input\": \"input-value\", \"headerName\": \"x-test\"}}";
176+
// WHEN - THEN
177+
graphQLTestTemplate
178+
.withHeaders(httpHeaders)
179+
.post(payload)
180+
.assertThatNoErrorsArePresent()
181+
.assertThatField(DATA_FIELD_QUERY_WITH_VARIABLES).asString().isEqualTo(INPUT_STRING_VALUE)
182+
.and().assertThatField(DATA_FIELD_QUERY_WITH_HEADER).asString().isEqualTo(TEST_HEADER_VALUE);
183+
}
165184
}

0 commit comments

Comments
 (0)