Skip to content

Commit 6ce00a9

Browse files
committed
Testing I18n lookup - an integration test
1 parent 9e1e732 commit 6ce00a9

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

‎src/test/groovy/graphql/i18n/I18nTest.groovy‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package graphql.i18n
22

33
import graphql.AssertException
4+
import graphql.ExecutionInput
5+
import graphql.TestUtil
46
import graphql.i18n.I18n.BundleType
57
import spock.lang.Specification
68

@@ -71,6 +73,49 @@ class I18nTest extends Specification {
7173
message == "Validierungsfehler ({0}) : Type definition '{1}' ist nicht ausführbar"
7274
}
7375

76+
def "integration test of valid messages"() {
77+
def sdl = """
78+
type Query {
79+
field(arg : Int) : Subselection
80+
}
81+
82+
type Subselection {
83+
name : String
84+
}
85+
"""
86+
def graphQL = TestUtil.graphQL(sdl).build()
87+
88+
89+
when:
90+
def locale = new Locale("en", "IN")
91+
def ei = ExecutionInput.newExecutionInput().query("query missingSubselectionQ { field(arg : 1) }")
92+
.locale(locale)
93+
.build()
94+
def er = graphQL.execute(ei)
95+
then:
96+
!er.errors.isEmpty()
97+
er.errors[0].message == "Validation error (SubselectionRequired@[field]) : Subselection required for type 'Subselection' of field 'field'"
98+
99+
when:
100+
locale = Locale.getDefault()
101+
ei = ExecutionInput.newExecutionInput().query("query missingSubselectionQ { field(arg : 1) }")
102+
.locale(locale)
103+
.build()
104+
er = graphQL.execute(ei)
105+
then:
106+
!er.errors.isEmpty()
107+
er.errors[0].message == "Validation error (SubselectionRequired@[field]) : Subselection required for type 'Subselection' of field 'field'"
108+
109+
when:
110+
// no locale - it should default
111+
ei = ExecutionInput.newExecutionInput().query("query missingSubselectionQ { field(arg : 1) }")
112+
.build()
113+
er = graphQL.execute(ei)
114+
then:
115+
!er.errors.isEmpty()
116+
er.errors[0].message == "Validation error (SubselectionRequired@[field]) : Subselection required for type 'Subselection' of field 'field'"
117+
}
118+
74119
static def assertBundleStaticShape(ResourceBundle bundle) {
75120
def enumeration = bundle.getKeys()
76121
while (enumeration.hasMoreElements()) {

0 commit comments

Comments
 (0)