Skip to content

Commit 8ebd3aa

Browse files
committed
All tests now passing
1 parent 75e0b07 commit 8ebd3aa

File tree

3 files changed

+10
-15
lines changed

3 files changed

+10
-15
lines changed

src/test/groovy/graphql/validation/constraints/BaseConstraintTestSupport.groovy

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class BaseConstraintTestSupport extends Specification {
108108
ruleEnvironment
109109
}
110110

111-
ValidationEnvironment buildEnvForField(String targetDirective, GraphQLSchema schema, Map<String, Object> arguments) {
111+
ValidationEnvironment buildEnvForField(DirectiveConstraint targetDirective, GraphQLSchema schema, Map<String, Object> arguments) {
112112
GraphQLFieldsContainer fieldsContainer = schema.getObjectType("Query") as GraphQLFieldsContainer
113113
GraphQLFieldDefinition fieldDefinition = fieldsContainer.getFieldDefinition("field")
114114

@@ -120,7 +120,8 @@ class BaseConstraintTestSupport extends Specification {
120120
.executionPath(path)
121121
.validatedElement(ValidationEnvironment.ValidatedElement.FIELD)
122122
.validatedPath(path)
123-
.context(GraphQLDirective.class, fieldDefinition.getDirective(targetDirective))
123+
.directives(fieldDefinition.getDirectives())
124+
.context(GraphQLDirective.class, fieldDefinition.getDirective(targetDirective.name))
124125
.messageInterpolator(interpolator)
125126
.build()
126127
ruleEnvironment

src/test/groovy/graphql/validation/constraints/standard/ExpressionConstraintTest.groovy

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ class ExpressionConstraintTest extends BaseConstraintTestSupport {
1414

1515
DirectiveConstraint ruleUnderTest = new ExpressionConstraint()
1616

17-
1817
expect:
1918

2019
def schema = buildSchema(ruleUnderTest.getDocumentation().getDirectiveSDL(), fieldDeclaration, "")
2120

22-
ValidationEnvironment validationEnvironment = buildEnvForField(ruleUnderTest.name, schema, args)
21+
ValidationEnvironment validationEnvironment = buildEnvForField(ruleUnderTest, schema, args)
2322

2423
def errors = ruleUnderTest.runValidation(validationEnvironment)
2524

@@ -42,19 +41,14 @@ class ExpressionConstraintTest extends BaseConstraintTestSupport {
4241

4342
expect:
4443

45-
def fieldDeclaration = "field( arg : String $expression ) : ID"
46-
def schema = buildSchema(ruleUnderTest.getDocumentation().getDirectiveSDL(), fieldDeclaration, "")
47-
48-
ValidationEnvironment validationEnvironment = buildEnv(ruleUnderTest.name, schema, "arg", argVal)
49-
50-
def errors = ruleUnderTest.runValidation(validationEnvironment)
51-
44+
def fieldDeclaration = "field( arg : String $expressionDirective ) : ID"
45+
def errors = runValidation(ruleUnderTest, fieldDeclaration, "arg", argVal)
5246
assertErrors(errors, expectedMessage)
5347

5448
where:
5549

5650

57-
expression | argVal | expectedMessage
51+
expressionDirective | argVal | expectedMessage
5852
'''@Expression(value : "${validatedValue.length() > 10}" )''' | "ABC" | "Expression;path=/arg;val:ABC;\t"
5953
'''@Expression(value : "${validatedValue.length() > 3}" )''' | "ABC" | "Expression;path=/arg;val:ABC;\t"
6054
'''@Expression(value : "${validatedValue.length() > 2}" )''' | "ABC" | ""

src/test/groovy/graphql/validation/interpolation/ResourceBundleMessageInterpolatorTest.groovy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,12 @@ class ResourceBundleMessageInterpolatorTest extends Specification {
4646
def schema = TestUtil.schema(sdl)
4747

4848
@Unroll
49-
def "can interpolate things"() {
49+
def "can interpolate things : #messageTemplate"() {
5050

5151
def interpolatorUnderTest = new ResourceBundleMessageInterpolator()
5252

5353
def validatedValue = [zig: "zag"]
54-
def messageParams = ["validatedValue": validatedValue, "p1": "pv1", "p2": "pv2", "min": "5", "max": "10"]
54+
def messageParams = ["validatedValue": validatedValue, "p1": "pv1", "p2": "pv2", "min": "5", "max": "10", path : "a/b/c"]
5555
ValidationEnvironment validationEnvironment = buildEnv(schema, "arg", validatedValue, interpolatorUnderTest, null)
5656

5757
expect:
@@ -65,7 +65,7 @@ class ResourceBundleMessageInterpolatorTest extends Specification {
6565
// resource bundle finding
6666
'graphql.test.message' | 'Test message with expressions : zag and replacements : pv1'
6767
// system level message finding from graphql.validation
68-
'graphql.validation.Size.message' | 'size must be between 5 and 10'
68+
'graphql.validation.Size.message' | 'a/b/c size must be between 5 and 10'
6969
// expressions
7070
'Could not ${validatedValue.zig}' | 'Could not zag'
7171
// message param replacement

0 commit comments

Comments
 (0)