Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
update
  • Loading branch information
pelletier197 committed Jul 25, 2021
commit 50424e8bdcd5bfbdab993cea502b8ea8d04f5776
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
package graphql.validation.constraints

import graphql.validation.constraints.standard.ContainerSizeConstraint

import graphql.validation.constraints.standard.SizeConstraint
import spock.lang.Unroll

class AbstractDirectiveConstraintTest extends BaseConstraintTestSupport {

@Unroll
def "complex object argument constraints"() {
def sizeConstraint = new SizeConstraint()

def extraSDL = """
${sizeConstraint.getDocumentation().getDirectiveSDL()}

input ProductItem {
code : String @Size(max : 5)
price : String @Size(max : 3)
Expand All @@ -27,7 +24,7 @@ class AbstractDirectiveConstraintTest extends BaseConstraintTestSupport {

// this tests that we can walk a complex tree of types via one specific implementation
// but the same applies to all AbstractDirectiveConstraint classes
def constraintUnderTest = new ContainerSizeConstraint()
def constraintUnderTest = new SizeConstraint()

expect:

Expand All @@ -36,18 +33,18 @@ class AbstractDirectiveConstraintTest extends BaseConstraintTestSupport {

where:

fieldDeclaration | argVal | eSize | expectedMessage
fieldDeclaration | argVal | eSize | expectedMessage
// size can handle list elements
"field( testArg : [Product!] @ContainerSize(max : 2) ) : ID" | [[:], [:], [:]] | 1 | "graphql.validation.Size.message;path=/testArg;val:[[:], [:], [:]];\t"
"field( testArg : [Product!] ) : ID" | [[:], [:], [:]] | 0 | ""
// goes down into input types
"field( testArg : [Product!] @ContainerSize(max : 2) ) : ID" | [[name: "morethan7"], [:]] | 1 | "graphql.validation.Size.message;path=/testArg[0]/name;val:morethan7;\t"
"field( testArg : [Product!] ) : ID" | [[name: "morethan7"], [:]] | 1 | "graphql.validation.Size.message;path=/testArg[0]/name;val:morethan7;\t"
// shows that it traverses down lists
"field( testArg : [Product!] @ContainerSize(max : 2) ) : ID" | [[name: "ok"], [name: "notOkHere"]] | 1 | "graphql.validation.Size.message;path=/testArg[1]/name;val:notOkHere;\t"
"field( testArg : [Product!] ) : ID" | [[name: "ok"], [name: "notOkHere"]] | 1 | "graphql.validation.Size.message;path=/testArg[1]/name;val:notOkHere;\t"
// shows that it traverses down lists and objects
"field( testArg : [Product!] @ContainerSize(max : 2) ) : ID" | [[items: [[code: "morethan5", price: "morethan3"]]]] | 2 | "graphql.validation.Size.message;path=/testArg[0]/items[0]/code;val:morethan5;\tgraphql.validation.Size.message;path=/testArg[0]/items[0]/price;val:morethan3;\t"
"field( testArg : [Product!] ) : ID" | [[items: [[code: "morethan5", price: "morethan3"]]]] | 2 | "graphql.validation.Size.message;path=/testArg[0]/items[0]/code;val:morethan5;\tgraphql.validation.Size.message;path=/testArg[0]/items[0]/price;val:morethan3;\t"

// shows that it traverses down crazy lists and objects
"field( testArg : [Product!] @ContainerSize(max : 2) ) : ID" | [[crazyItems: [[[[code: "morethan5"]]]]]] | 1 | "graphql.validation.Size.message;path=/testArg[0]/crazyItems[0][0][0]/code;val:morethan5;\t"
"field( testArg : [Product!] ) : ID" | [[crazyItems: [[[[code: "morethan5"]]]]]] | 1 | "graphql.validation.Size.message;path=/testArg[0]/crazyItems[0][0][0]/code;val:morethan5;\t"
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class DirectiveConstraintsTest extends BaseConstraintTestSupport {
def rules = DirectiveConstraints.newDirectiveConstraints().build()

then:
rules.getConstraints().size() == 17
rules.getConstraints().size() == 19

when:
rules = DirectiveConstraints.newDirectiveConstraints().clearRules().build()
Expand Down Expand Up @@ -69,8 +69,8 @@ class DirectiveConstraintsTest extends BaseConstraintTestSupport {

"field( testArg : NoSizeDirectives ) : ID" | "Range"

"field( testArg : [Product!] @Size(max : 2) ) : ID" | "Size"
"field( testArg : Product! @Size(max : 2) ) : ID" | "Size"
"field( testArg : [Product!] @ContainerSize(max : 2) ) : ID" | "ContainerSize,Size"
"field( testArg : Product! @ContainerSize(max : 2) ) : ID" | "ContainerSize,Size"
"field( testArg : [Product!] ) : ID" | "Size"
}

Expand Down Expand Up @@ -116,7 +116,7 @@ class DirectiveConstraintsTest extends BaseConstraintTestSupport {
def declaration = directiveValidationRules.getDirectivesDeclaration()
then:
declaration != null
declaration.getDirectiveDefinitions().size() == 17
declaration.getDirectiveDefinitions().size() == 19

}
}