Skip to content

Commit 62d8450

Browse files
committed
Add test for min and max on an integer
1 parent 4d625b6 commit 62d8450

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

graphql-builder/src/test/java/com/phocassoftware/graphql/builder/JakartaValidationDirectiveTest.java

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.util.stream.Collectors;
1515

1616
import static org.junit.jupiter.api.Assertions.assertEquals;
17+
import static org.junit.jupiter.api.Assertions.assertNull;
1718

1819
class JakartaValidationDirectiveTest {
1920
@Test
@@ -44,12 +45,39 @@ void testJakartaSizeDirectiveArgumentDefinition() {
4445
}
4546

4647
@Test
47-
void testJakartaValidationIsApplied() {
48+
void testJakartaSizeValidationIsApplied() {
4849
var name = "Roger";
4950
Map<String, String> response = execute("mutation setName($name: String!){setName(name: $name)} ", Map.of("name", name)).getData();
5051
var result = response.get("setName");
5152

5253
assertEquals(name, result);
54+
55+
name = "Po";
56+
response = execute("mutation setName($name: String!){setName(name: $name)} ", Map.of("name", name)).getData();
57+
58+
// TODO: response is currently null, I would expect it to return an error.
59+
assertNull(response);
60+
}
61+
62+
@Test
63+
void testJakartaMinAndMaxValidationIsApplied() {
64+
var age = 4;
65+
Map<String, Integer> response = execute("mutation setAge($age: Int!){setAge(age: $age)} ", Map.of("age", age)).getData();
66+
var result = response.get("setAge");
67+
68+
assertEquals(age, result);
69+
70+
age = 2;
71+
response = execute("mutation setAge($age: int!){setAge(age: $age)} ", Map.of("age", age)).getData();
72+
73+
// TODO: response is currently null, I would expect it to return an error.
74+
assertNull(response);
75+
76+
age = 100;
77+
response = execute("mutation setAge($age: int!){setAge(age: $age)} ", Map.of("age", age)).getData();
78+
79+
// TODO: response is currently null, I would expect it to return an error.
80+
assertNull(response);
5381
}
5482

5583
private ExecutionResult execute(String query, Map<String, Object> variables) {

graphql-builder/src/test/java/com/phocassoftware/graphql/builder/type/directive/Cat.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import com.phocassoftware.graphql.builder.annotations.Entity;
1515
import com.phocassoftware.graphql.builder.annotations.Mutation;
1616
import com.phocassoftware.graphql.builder.annotations.Query;
17+
import jakarta.validation.constraints.Max;
18+
import jakarta.validation.constraints.Min;
1719
import jakarta.validation.constraints.Size;
1820

1921
@Entity
@@ -48,6 +50,11 @@ public static String setName(@Size(min = 3) String name) {
4850
return name;
4951
}
5052

53+
@Mutation
54+
public static int setAge(@Min(value = 3) @Max(value = 99) int age) {
55+
return age;
56+
}
57+
5158
@Query
5259
@Admin("tabby")
5360
public static String allowed(String name) {

0 commit comments

Comments
 (0)