Skip to content

Commit

Permalink
graphql-java#427 - more tests for null variables values
Browse files Browse the repository at this point in the history
  • Loading branch information
bbakerman committed May 27, 2017
1 parent 5abd0ca commit 2159345
Showing 1 changed file with 73 additions and 23 deletions.
96 changes: 73 additions & 23 deletions src/test/groovy/graphql/NullValueSupportTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,32 @@ import graphql.execution.NonNullableValueCoercedAsNullException
import graphql.validation.ValidationError
import graphql.validation.ValidationErrorType
import spock.lang.Specification
import spock.lang.Unroll

/*
* Taken from http://facebook.github.io/graphql/#sec-Input-Objects
*
*
Test Case Original Value Variables Coerced Value
A { a: "abc", b: 123 } null { a: "abc", b: 123 }
B { a: 123, b: "123" } null { a: "123", b: 123 }
C { a: "abc" } null Error: Missing required field b
D { a: "abc", b: null } null Error: b must be non‐null.
E { a: null, b: 1 } null { a: null, b: 1 }
F { b: $var } { var: 123 } { b: 123 }
G { b: $var } {} Error: Missing required field b.
H { b: $var } { var: null } Error: b must be non‐null.
I { a: $var, b: 1 } { var: null } { a: null, b: 1 }
J { a: $var, b: 1 } {} { b: 1 }
Test Case Original Value Variables Coerced Value
--------------------------------------------------------------------------------------------
A { a: "abc", b: 123 } null { a: "abc", b: 123 }
B { a: 123, b: "123" } null { a: "123", b: 123 }
C { a: "abc" } null Error: Missing required field b
D { a: "abc", b: null } null Error: b must be non‐null.
E { a: null, b: 1 } null { a: null, b: 1 }
F { b: $var } { var: 123 } { b: 123 }
G { b: $var } {} Error: Missing required field b.
H { b: $var } { var: null } Error: b must be non‐null.
I { a: $var, b: 1 } { var: null } { a: null, b: 1 }
J { a: $var, b: 1 } {} { b: 1 }
These did not come from the spec but added by us as extra tests
K { $var } { a : "abc", b:123 } { a: "abc", b: 123 }
L { $var } { b:123 } { b: 123 }
M { $var } { a : "abc", b:null } Error: b must be non‐null.
N { $var } { a : "abc" } Error: b must be non‐null.
*/

Expand Down Expand Up @@ -48,7 +57,8 @@ class NullValueSupportTest extends Specification {
'''

def "test graphql spec examples that output results"() {
@Unroll
"test graphql spec examples that output results : #testCase"() {
def fetcher = new CapturingDataFetcher()

def schema = TestUtil.schema(graphqlSpecExamples, ["Mutation": ["mutate": fetcher]])
Expand All @@ -63,7 +73,7 @@ class NullValueSupportTest extends Specification {

where:

testCase | queryStr | variables || expectedArgs
testCase | queryStr | variables || expectedArgs

// ------------------------------
'A' | '''
Expand All @@ -72,7 +82,7 @@ class NullValueSupportTest extends Specification {
a
}
}
''' | [:] || [inputArg: [a: "abc", b: 123]]
''' | [:] || [inputArg: [a: "abc", b: 123]]

// ------------------------------
// coerced from string -> int and vice versus
Expand All @@ -97,7 +107,7 @@ class NullValueSupportTest extends Specification {
a
}
}
''' | [:] || [inputArg: [a: null, b: 1]]
''' | [:] || [inputArg: [a: null, b: 1]]

// ------------------------------
'F' | '''
Expand All @@ -106,7 +116,7 @@ class NullValueSupportTest extends Specification {
a
}
}
''' | [var: 123] || [inputArg: [b: 123]]
''' | [var: 123] || [inputArg: [b: 123]]

// ------------------------------
'I' | '''
Expand All @@ -115,7 +125,7 @@ class NullValueSupportTest extends Specification {
a
}
}
''' | [var: null] || [inputArg: [a: null, b: 1]]
''' | [var: null] || [inputArg: [a: null, b: 1]]

// ------------------------------
'J' | '''
Expand All @@ -124,10 +134,30 @@ class NullValueSupportTest extends Specification {
a
}
}
''' | [:] || [inputArg: [b: 1]]
''' | [:] || [inputArg: [b: 1]]

// ------------------------------
'K' | '''
mutation mutate($var : ExampleInputObject) {
mutate(inputArg : $var) {
a
}
}
''' | [var: [a: "abc", b: 123]] || [inputArg: [a: "abc", b: 123]]

// ------------------------------
'L' | '''
mutation mutate($var : ExampleInputObject) {
mutate(inputArg : $var) {
a
}
}
''' | [var: [b: 123]] || [inputArg: [b: 123]]

}

def "test graphql spec examples that output errors"() {
@Unroll
"test graphql spec examples that output errors #testCase"() {
def fetcher = new CapturingDataFetcher()

def schema = TestUtil.schema(graphqlSpecExamples, ["Mutation": ["mutate": fetcher]])
Expand Down Expand Up @@ -170,7 +200,8 @@ class NullValueSupportTest extends Specification {
''' | [:] || ValidationErrorType.WrongType
}

def "test graphql spec examples that output exception"() {
@Unroll
"test graphql spec examples that output exception : #testCase"() {
def fetcher = new CapturingDataFetcher()

def schema = TestUtil.schema(graphqlSpecExamples, ["Mutation": ["mutate": fetcher]])
Expand All @@ -185,7 +216,7 @@ class NullValueSupportTest extends Specification {

where:

testCase | queryStr | variables || expectedException
testCase | queryStr | variables || expectedException

// ------------------------------
'G' | '''
Expand All @@ -194,7 +225,7 @@ class NullValueSupportTest extends Specification {
a
}
}
''' | [:] || NonNullableValueCoercedAsNullException
''' | [:] || NonNullableValueCoercedAsNullException

// ------------------------------
'H' | '''
Expand All @@ -203,7 +234,26 @@ class NullValueSupportTest extends Specification {
a
}
}
''' | [var: null] || NonNullableValueCoercedAsNullException
''' | [var: null] || NonNullableValueCoercedAsNullException

// ------------------------------
'M' | '''
mutation mutate($var : ExampleInputObject) {
mutate(inputArg : $var) {
a
}
}
''' | [var: [a: "abc", b: null]] || NonNullableValueCoercedAsNullException

// ------------------------------
'N' | '''
mutation mutate($var : ExampleInputObject) {
mutate(inputArg : $var) {
a
}
}
''' | [var: [a: "abc"]] || NonNullableValueCoercedAsNullException


}

Expand Down

0 comments on commit 2159345

Please sign in to comment.