X Tutup
Skip to content
Merged
Changes from all commits
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
92 changes: 92 additions & 0 deletions src/test/groovy/graphql/i18n/I18nTest.groovy
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package graphql.i18n

import graphql.AssertException
import graphql.ExecutionInput
import graphql.TestUtil
import graphql.i18n.I18n.BundleType
import spock.lang.Specification

Expand All @@ -14,6 +16,43 @@ class I18nTest extends Specification {
thrown(AssertException)
}

def "missing resource bundles default to a base version"() {
// see https://saimana.com/list-of-country-locale-code/

def expected = "Validation error ({0}) : Type '{1}' definition is not executable"

when:
def i18n = I18n.i18n(BundleType.Validation, Locale.ENGLISH)
def msg = i18n.msg("ExecutableDefinitions.notExecutableType")

then:
msg == expected

when:
i18n = I18n.i18n(BundleType.Validation, Locale.CHINESE)
msg = i18n.msg("ExecutableDefinitions.notExecutableType")
then:
msg == expected

when:
i18n = I18n.i18n(BundleType.Validation, new Locale("en", "IN")) // India
msg = i18n.msg("ExecutableDefinitions.notExecutableType")
then:
msg == expected

when:
i18n = I18n.i18n(BundleType.Validation, new Locale("en", "FJ")) // Fiji
msg = i18n.msg("ExecutableDefinitions.notExecutableType")
then:
msg == expected

when:
i18n = I18n.i18n(BundleType.Validation, new Locale("")) // Nothing
msg = i18n.msg("ExecutableDefinitions.notExecutableType")
then:
msg == expected
}

def "all enums have resources and decent shapes"() {
when:
def bundleTypes = BundleType.values()
Expand All @@ -34,6 +73,59 @@ class I18nTest extends Specification {
message == "Validierungsfehler ({0}) : Type definition '{1}' ist nicht ausführbar"
}

def "integration test of valid messages"() {
def sdl = """
type Query {
field(arg : Int) : Subselection
}

type Subselection {
name : String
}
"""
def graphQL = TestUtil.graphQL(sdl).build()


when:
def locale = new Locale("en", "IN")
def ei = ExecutionInput.newExecutionInput().query("query missingSubselectionQ { field(arg : 1) }")
.locale(locale)
.build()
def er = graphQL.execute(ei)
then:
!er.errors.isEmpty()
er.errors[0].message == "Validation error (SubselectionRequired@[field]) : Subselection required for type 'Subselection' of field 'field'"

when:
locale = Locale.GERMANY
ei = ExecutionInput.newExecutionInput().query("query missingSubselectionQ { field(arg : 1) }")
.locale(locale)
.build()
er = graphQL.execute(ei)
then:
!er.errors.isEmpty()
er.errors[0].message == "Validierungsfehler (SubselectionRequired@[field]) : Unterauswahl erforderlich für Typ 'Subselection' des Feldes 'field'"

when:
locale = Locale.getDefault()
ei = ExecutionInput.newExecutionInput().query("query missingSubselectionQ { field(arg : 1) }")
.locale(locale)
.build()
er = graphQL.execute(ei)
then:
!er.errors.isEmpty()
er.errors[0].message == "Validation error (SubselectionRequired@[field]) : Subselection required for type 'Subselection' of field 'field'"

when:
// no locale - it should default
ei = ExecutionInput.newExecutionInput().query("query missingSubselectionQ { field(arg : 1) }")
.build()
er = graphQL.execute(ei)
then:
!er.errors.isEmpty()
er.errors[0].message == "Validation error (SubselectionRequired@[field]) : Subselection required for type 'Subselection' of field 'field'"
}

static def assertBundleStaticShape(ResourceBundle bundle) {
def enumeration = bundle.getKeys()
while (enumeration.hasMoreElements()) {
Expand Down
X Tutup