Skip to content

Commit

Permalink
feat : adds integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
rajadilipkolli committed Mar 10, 2024
1 parent 55d2321 commit 5fd5eda
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public Mono<Map<Customer, List<Orders>>> orders(List<Customer> customers) {
}

@MutationMapping
Mono<Customer> addCustomer(@Argument @NotBlank String name) {
Mono<Customer> addCustomer(@Argument @NotBlank(message = "Name cant be blank") String name) {
return this.customerGraphQLService.addCustomer(name);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.example.graphql;

import static graphql.ErrorType.ValidationError;

import com.example.graphql.common.AbstractIntegrationTest;
import com.example.graphql.dtos.Customer;
import com.example.graphql.dtos.CustomerDTO;
Expand All @@ -20,16 +22,16 @@ void query_all_customers() {
this.graphQlTester
.document(
"""
{
customers {
id
name
orders {
id
}
}
}
""")
query {
customers {
id
name
orders {
id
}
}
}
""")
.execute()
.path("customers[*]")
.hasValue()
Expand All @@ -42,13 +44,13 @@ void query_customers_by_name() {
this.graphQlTester
.document(
"""
query ($name: String) {
customersByName(name: $name) {
id
name
}
}
""")
query ($name: String) {
customersByName(name: $name) {
id
name
}
}
""")
.variable("name", "raja")
.execute()
.path("customersByName[*]")
Expand All @@ -62,13 +64,13 @@ void query_insert() {
String randomString = RandomStringUtils.randomAlphabetic(5);
String query =
"""
mutation addCustomer($cname: String) {
addCustomer(name: $cname) {
id
name
}
}
""";
mutation addCustomer($cname: String) {
addCustomer(name: $cname) {
id
name
}
}
""";
this.graphQlTester
.document(query)
.variable("cname", randomString)
Expand All @@ -81,4 +83,31 @@ mutation addCustomer($cname: String) {
.entity(String.class)
.isEqualTo(randomString);
}

@Test
void query_insert_failure() {
String query =
"""
mutation addCustomer($cname: String) {
addCustomer(name: $cname) {
id
name
}
}
""";
this.graphQlTester
.document(query)
.variable("cname", null)
.execute()
.errors()
.expect(error -> error.getErrorType() == ValidationError)
.verify()
.path("$.data")
.matchesJson(
"""
{
"addCustomer": null
}
""");
}
}

0 comments on commit 5fd5eda

Please sign in to comment.