Closed
Description
The GraphQLTestTemplate
is great to test general query and mutation, but when I tried to test file upload, not sure how to add a Part
object to the request.
The postMultipart
accept a json
string, there is a serialization error when running the following test.
@SneakyThrows
@Test
public void uploadFile() {
var part = """
{
"query": "mutation upload($file:Upload!){
upload(file:file)
}"
}
""";
var variables = Map.of("file", new MockPart("test", "test.txt", "test content".getBytes()));
GraphQLResponse response = testTemplate.postMultipart(part, objectMapper.writeValueAsString(variables));
assertNotNull(response);
assertThat(response.isOk()).isTrue();
assertThat(response.get("$.data.upload", Boolean.class)).isTrue();
}
BTW, how to subscribe the subscription event via GraphQLTestTemplate
?
Metadata
Metadata
Assignees
Labels
No labels