Skip to content

Commit 49b0dab

Browse files
committed
Added missing rule tests
- Re-checked the number of tests against `graphql-js` to ensure that all tests have been ported
1 parent 7b9d6e3 commit 49b0dab

11 files changed

+98
-25
lines changed

rules_arguments_of_correct_type_test.go

+64-3
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,21 @@ func TestValidate_ArgValuesOfCorrectType_InvalidStringValues_UnquotedStringIntoS
142142
})
143143
}
144144

145+
func TestValidate_ArgValuesOfCorrectType_InvalidIntValues_StringIntoInt(t *testing.T) {
146+
testutil.ExpectFailsRule(t, graphql.ArgumentsOfCorrectTypeRule, `
147+
{
148+
complicatedArgs {
149+
intArgField(intArg: "3")
150+
}
151+
}
152+
`,
153+
[]gqlerrors.FormattedError{
154+
testutil.RuleError(
155+
`Argument "intArg" expected type "Int" but got: "3".`,
156+
4, 33,
157+
),
158+
})
159+
}
145160
func TestValidate_ArgValuesOfCorrectType_InvalidIntValues_BigIntIntoInt(t *testing.T) {
146161
testutil.ExpectFailsRule(t, graphql.ArgumentsOfCorrectTypeRule, `
147162
{
@@ -203,6 +218,52 @@ func TestValidate_ArgValuesOfCorrectType_InvalidIntValues_FloatIntoInt(t *testin
203218
})
204219
}
205220

221+
func TestValidate_ArgValuesOfCorrectType_InvalidFloatValues_StringIntoFloat(t *testing.T) {
222+
testutil.ExpectFailsRule(t, graphql.ArgumentsOfCorrectTypeRule, `
223+
{
224+
complicatedArgs {
225+
floatArgField(floatArg: "3.333")
226+
}
227+
}
228+
`,
229+
[]gqlerrors.FormattedError{
230+
testutil.RuleError(
231+
`Argument "floatArg" expected type "Float" but got: "3.333".`,
232+
4, 37,
233+
),
234+
})
235+
}
236+
func TestValidate_ArgValuesOfCorrectType_InvalidFloatValues_BooleanIntoFloat(t *testing.T) {
237+
testutil.ExpectFailsRule(t, graphql.ArgumentsOfCorrectTypeRule, `
238+
{
239+
complicatedArgs {
240+
floatArgField(floatArg: true)
241+
}
242+
}
243+
`,
244+
[]gqlerrors.FormattedError{
245+
testutil.RuleError(
246+
`Argument "floatArg" expected type "Float" but got: true.`,
247+
4, 37,
248+
),
249+
})
250+
}
251+
func TestValidate_ArgValuesOfCorrectType_InvalidFloatValues_UnquotedIntoFloat(t *testing.T) {
252+
testutil.ExpectFailsRule(t, graphql.ArgumentsOfCorrectTypeRule, `
253+
{
254+
complicatedArgs {
255+
floatArgField(floatArg: FOO)
256+
}
257+
}
258+
`,
259+
[]gqlerrors.FormattedError{
260+
testutil.RuleError(
261+
`Argument "floatArg" expected type "Float" but got: FOO.`,
262+
4, 37,
263+
),
264+
})
265+
}
266+
206267
func TestValidate_ArgValuesOfCorrectType_InvalidBooleanValues_IntIntoBoolean(t *testing.T) {
207268
testutil.ExpectFailsRule(t, graphql.ArgumentsOfCorrectTypeRule, `
208269
{
@@ -264,7 +325,7 @@ func TestValidate_ArgValuesOfCorrectType_InvalidBooleanValues_UnquotedStringInto
264325
})
265326
}
266327

267-
func TestValidate_ArgValuesOfCorrectType_InvalidIDValues_FloatIntoID(t *testing.T) {
328+
func TestValidate_ArgValuesOfCorrectType_InvalidIDValue_FloatIntoID(t *testing.T) {
268329
testutil.ExpectFailsRule(t, graphql.ArgumentsOfCorrectTypeRule, `
269330
{
270331
complicatedArgs {
@@ -279,7 +340,7 @@ func TestValidate_ArgValuesOfCorrectType_InvalidIDValues_FloatIntoID(t *testing.
279340
),
280341
})
281342
}
282-
func TestValidate_ArgValuesOfCorrectType_InvalidIDValues_BooleanIntoID(t *testing.T) {
343+
func TestValidate_ArgValuesOfCorrectType_InvalidIDValue_BooleanIntoID(t *testing.T) {
283344
testutil.ExpectFailsRule(t, graphql.ArgumentsOfCorrectTypeRule, `
284345
{
285346
complicatedArgs {
@@ -294,7 +355,7 @@ func TestValidate_ArgValuesOfCorrectType_InvalidIDValues_BooleanIntoID(t *testin
294355
),
295356
})
296357
}
297-
func TestValidate_ArgValuesOfCorrectType_InvalidIDValues_UnquotedIntoID(t *testing.T) {
358+
func TestValidate_ArgValuesOfCorrectType_InvalidIDValue_UnquotedIntoID(t *testing.T) {
298359
testutil.ExpectFailsRule(t, graphql.ArgumentsOfCorrectTypeRule, `
299360
{
300361
complicatedArgs {

rules_default_values_of_correct_type_test.go

-3
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ func TestValidate_VariableDefaultValuesOfCorrectType_VariablesWithValidDefaultVa
3333
}
3434
`)
3535
}
36-
3736
func TestValidate_VariableDefaultValuesOfCorrectType_NoRequiredVariablesWithDefaultValues(t *testing.T) {
3837
testutil.ExpectFailsRule(t, graphql.DefaultValuesOfCorrectTypeRule, `
3938
query UnreachableDefaultValues($a: Int! = 3, $b: String! = "default") {
@@ -69,7 +68,6 @@ func TestValidate_VariableDefaultValuesOfCorrectType_VariablesWithInvalidDefault
6968
testutil.RuleError(`Variable "$c" of type "ComplexInput" has invalid default value: "notverycomplex".`, 5, 28),
7069
})
7170
}
72-
7371
func TestValidate_VariableDefaultValuesOfCorrectType_ComplexVariablesMissingRequiredField(t *testing.T) {
7472
testutil.ExpectFailsRule(t, graphql.DefaultValuesOfCorrectTypeRule, `
7573
query MissingRequiredField($a: ComplexInput = {intField: 3}) {
@@ -80,7 +78,6 @@ func TestValidate_VariableDefaultValuesOfCorrectType_ComplexVariablesMissingRequ
8078
testutil.RuleError(`Variable "$a" of type "ComplexInput" has invalid default value: {intField: 3}.`, 2, 53),
8179
})
8280
}
83-
8481
func TestValidate_VariableDefaultValuesOfCorrectType_ListVariablesWithInvalidItem(t *testing.T) {
8582
testutil.ExpectFailsRule(t, graphql.DefaultValuesOfCorrectTypeRule, `
8683
query InvalidItem($a: [String] = ["one", 2]) {

rules_fragments_on_composite_types_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ func TestValidate_FragmentsOnCompositeTypes_UnionIsValidFragmentType(t *testing.
3838
}
3939
`)
4040
}
41-
4241
func TestValidate_FragmentsOnCompositeTypes_ScalarIsInvalidFragmentType(t *testing.T) {
4342
testutil.ExpectFailsRule(t, graphql.FragmentsOnCompositeTypesRule, `
4443
fragment scalarFragment on Boolean {

rules_known_directives_rule_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ func TestValidate_KnownDirectives_WithNoDirectives(t *testing.T) {
2020
}
2121
`)
2222
}
23+
func TestValidate_KnownDirectives_WithKnownDirective(t *testing.T) {
24+
testutil.ExpectPassesRule(t, graphql.KnownDirectivesRule, `
25+
{
26+
dog @include(if: true) {
27+
name
28+
}
29+
human @skip(if: false) {
30+
name
31+
}
32+
}
33+
`)
34+
}
2335
func TestValidate_KnownDirectives_WithUnknownDirective(t *testing.T) {
2436
testutil.ExpectFailsRule(t, graphql.KnownDirectivesRule, `
2537
{

rules_lone_anonymous_operation_rule_test.go

-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ func TestValidate_AnonymousOperationMustBeAlone_AnonOperationWithFragment(t *tes
4343
}
4444
`)
4545
}
46-
4746
func TestValidate_AnonymousOperationMustBeAlone_MultipleAnonOperations(t *testing.T) {
4847
testutil.ExpectFailsRule(t, graphql.LoneAnonymousOperationRule, `
4948
{

rules_no_fragment_cycles_test.go

+13-2
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ func TestValidate_NoCircularFragmentSpreads_SpreadingRecursivelyWithinFieldFails
4747
testutil.RuleError(`Cannot spread fragment "fragA" within itself.`, 2, 45),
4848
})
4949
}
50+
5051
func TestValidate_NoCircularFragmentSpreads_NoSpreadingItselfDirectly(t *testing.T) {
5152
testutil.ExpectFailsRule(t, graphql.NoFragmentCyclesRule, `
5253
fragment fragA on Dog { ...fragA }
@@ -65,15 +66,24 @@ func TestValidate_NoCircularFragmentSpreads_NoSpreadingItselfDirectlyWithinInlin
6566
testutil.RuleError(`Cannot spread fragment "fragA" within itself.`, 4, 11),
6667
})
6768
}
68-
func TestValidate_NoCircularFragmentSpreads_NoSpreadingItselfDirectlyMultiple(t *testing.T) {
69+
70+
func TestValidate_NoCircularFragmentSpreads_NoSpreadingItselfIndirectly(t *testing.T) {
6971
testutil.ExpectFailsRule(t, graphql.NoFragmentCyclesRule, `
7072
fragment fragA on Dog { ...fragB }
7173
fragment fragB on Dog { ...fragA }
7274
`, []gqlerrors.FormattedError{
7375
testutil.RuleError(`Cannot spread fragment "fragA" within itself via fragB.`, 2, 31, 3, 31),
7476
})
7577
}
76-
func TestValidate_NoCircularFragmentSpreads_NoSpreadingItselfDirectlyWithinInlineFragmentMultiple(t *testing.T) {
78+
func TestValidate_NoCircularFragmentSpreads_NoSpreadingItselfIndirectlyReportsOppositeOrder(t *testing.T) {
79+
testutil.ExpectFailsRule(t, graphql.NoFragmentCyclesRule, `
80+
fragment fragB on Dog { ...fragA }
81+
fragment fragA on Dog { ...fragB }
82+
`, []gqlerrors.FormattedError{
83+
testutil.RuleError(`Cannot spread fragment "fragB" within itself via fragA.`, 2, 31, 3, 31),
84+
})
85+
}
86+
func TestValidate_NoCircularFragmentSpreads_NoSpreadingItselfIndirectlyWithinInlineFragment(t *testing.T) {
7787
testutil.ExpectFailsRule(t, graphql.NoFragmentCyclesRule, `
7888
fragment fragA on Pet {
7989
... on Dog {
@@ -89,6 +99,7 @@ func TestValidate_NoCircularFragmentSpreads_NoSpreadingItselfDirectlyWithinInlin
8999
testutil.RuleError(`Cannot spread fragment "fragA" within itself via fragB.`, 4, 11, 9, 11),
90100
})
91101
}
102+
92103
func TestValidate_NoCircularFragmentSpreads_NoSpreadingItselfDeeply(t *testing.T) {
93104
testutil.ExpectFailsRule(t, graphql.NoFragmentCyclesRule, `
94105
fragment fragA on Dog { ...fragB }

rules_no_undefined_variables_test.go

-6
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ func TestValidate_NoUndefinedVariables_MultipleVariablesNotDefined(t *testing.T)
130130
testutil.RuleError(`Variable "$c" is not defined.`, 3, 32),
131131
})
132132
}
133-
134133
func TestValidate_NoUndefinedVariables_VariableInFragmentNotDefinedByUnnamedQuery(t *testing.T) {
135134
testutil.ExpectFailsRule(t, graphql.NoUndefinedVariablesRule, `
136135
{
@@ -143,7 +142,6 @@ func TestValidate_NoUndefinedVariables_VariableInFragmentNotDefinedByUnnamedQuer
143142
testutil.RuleError(`Variable "$a" is not defined.`, 6, 18),
144143
})
145144
}
146-
147145
func TestValidate_NoUndefinedVariables_VariableInFragmentNotDefinedByOperation(t *testing.T) {
148146
testutil.ExpectFailsRule(t, graphql.NoUndefinedVariablesRule, `
149147
query Foo($a: String, $b: String) {
@@ -166,7 +164,6 @@ func TestValidate_NoUndefinedVariables_VariableInFragmentNotDefinedByOperation(t
166164
testutil.RuleError(`Variable "$c" is not defined by operation "Foo".`, 16, 18, 2, 7),
167165
})
168166
}
169-
170167
func TestValidate_NoUndefinedVariables_MultipleVariablesInFragmentsNotDefined(t *testing.T) {
171168
testutil.ExpectFailsRule(t, graphql.NoUndefinedVariablesRule, `
172169
query Foo($b: String) {
@@ -190,7 +187,6 @@ func TestValidate_NoUndefinedVariables_MultipleVariablesInFragmentsNotDefined(t
190187
testutil.RuleError(`Variable "$c" is not defined by operation "Foo".`, 16, 18, 2, 7),
191188
})
192189
}
193-
194190
func TestValidate_NoUndefinedVariables_SingleVariableInFragmentNotDefinedByMultipleOperations(t *testing.T) {
195191
testutil.ExpectFailsRule(t, graphql.NoUndefinedVariablesRule, `
196192
query Foo($a: String) {
@@ -207,7 +203,6 @@ func TestValidate_NoUndefinedVariables_SingleVariableInFragmentNotDefinedByMulti
207203
testutil.RuleError(`Variable "$b" is not defined by operation "Bar".`, 9, 25, 5, 7),
208204
})
209205
}
210-
211206
func TestValidate_NoUndefinedVariables_VariablesInFragmentNotDefinedByMultipleOperations(t *testing.T) {
212207
testutil.ExpectFailsRule(t, graphql.NoUndefinedVariablesRule, `
213208
query Foo($b: String) {
@@ -243,7 +238,6 @@ func TestValidate_NoUndefinedVariables_VariableInFragmentUsedByOtherOperation(t
243238
testutil.RuleError(`Variable "$b" is not defined by operation "Bar".`, 12, 18, 5, 7),
244239
})
245240
}
246-
247241
func TestValidate_NoUndefinedVariables_VaMultipleUndefinedVariablesProduceMultipleErrors(t *testing.T) {
248242
testutil.ExpectFailsRule(t, graphql.NoUndefinedVariablesRule, `
249243
query Foo($b: String) {

rules_no_unused_fragments_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ func TestValidate_NoUnusedFragments_ContainsUnknownFragments(t *testing.T) {
8787
testutil.RuleError(`Fragment "Unused2" is never used.`, 25, 7),
8888
})
8989
}
90-
9190
func TestValidate_NoUnusedFragments_ContainsUnknownFragmentsWithRefCycle(t *testing.T) {
9291
testutil.ExpectFailsRule(t, graphql.NoUnusedFragmentsRule, `
9392
query Foo {
@@ -123,7 +122,6 @@ func TestValidate_NoUnusedFragments_ContainsUnknownFragmentsWithRefCycle(t *test
123122
testutil.RuleError(`Fragment "Unused2" is never used.`, 26, 7),
124123
})
125124
}
126-
127125
func TestValidate_NoUnusedFragments_ContainsUnknownAndUndefFragments(t *testing.T) {
128126
testutil.ExpectFailsRule(t, graphql.NoUnusedFragmentsRule, `
129127
query Foo {

rules_possible_fragment_spreads_test.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ func TestValidate_PossibleFragmentSpreads_ObjectIntoContainingUnion(t *testing.T
3131
fragment dogFragment on Dog { barkVolume }
3232
`)
3333
}
34+
3435
func TestValidate_PossibleFragmentSpreads_UnionIntoContainedObject(t *testing.T) {
3536
testutil.ExpectPassesRule(t, graphql.PossibleFragmentSpreadsRule, `
3637
fragment unionWithinObject on Dog { ...catOrDogFragment }
@@ -49,6 +50,7 @@ func TestValidate_PossibleFragmentSpreads_UnionIntoOverlappingUnion(t *testing.T
4950
fragment catOrDogFragment on CatOrDog { __typename }
5051
`)
5152
}
53+
5254
func TestValidate_PossibleFragmentSpreads_InterfaceIntoImplementedObject(t *testing.T) {
5355
testutil.ExpectPassesRule(t, graphql.PossibleFragmentSpreadsRule, `
5456
fragment interfaceWithinObject on Dog { ...petFragment }
@@ -81,7 +83,6 @@ func TestValidate_PossibleFragmentSpreads_DifferentObjectIntoObject(t *testing.T
8183
`type "Cat" can never be of type "Dog".`, 2, 51),
8284
})
8385
}
84-
8586
func TestValidate_PossibleFragmentSpreads_DifferentObjectIntoObjectInInlineFragment(t *testing.T) {
8687
testutil.ExpectFailsRule(t, graphql.PossibleFragmentSpreadsRule, `
8788
fragment invalidObjectWithinObjectAnon on Cat {
@@ -92,6 +93,7 @@ func TestValidate_PossibleFragmentSpreads_DifferentObjectIntoObjectInInlineFragm
9293
`type "Cat" can never be of type "Dog".`, 3, 9),
9394
})
9495
}
96+
9597
func TestValidate_PossibleFragmentSpreads_ObjectIntoNotImplementingInterface(t *testing.T) {
9698
testutil.ExpectFailsRule(t, graphql.PossibleFragmentSpreadsRule, `
9799
fragment invalidObjectWithinInterface on Pet { ...humanFragment }
@@ -110,6 +112,7 @@ func TestValidate_PossibleFragmentSpreads_ObjectIntoNotContainingUnion(t *testin
110112
`type "CatOrDog" can never be of type "Human".`, 2, 55),
111113
})
112114
}
115+
113116
func TestValidate_PossibleFragmentSpreads_UnionIntoNotContainedObject(t *testing.T) {
114117
testutil.ExpectFailsRule(t, graphql.PossibleFragmentSpreadsRule, `
115118
fragment invalidUnionWithinObject on Human { ...catOrDogFragment }
@@ -128,7 +131,6 @@ func TestValidate_PossibleFragmentSpreads_UnionIntoNonOverlappingInterface(t *te
128131
`type "Pet" can never be of type "HumanOrAlien".`, 2, 53),
129132
})
130133
}
131-
132134
func TestValidate_PossibleFragmentSpreads_UnionIntoNonOverlappingUnion(t *testing.T) {
133135
testutil.ExpectFailsRule(t, graphql.PossibleFragmentSpreadsRule, `
134136
fragment invalidUnionWithinUnion on CatOrDog { ...humanOrAlienFragment }

rules_provided_non_null_arguments_test.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ func TestValidate_ProvidedNonNullArguments_IgnoresUnknownArguments(t *testing.T)
1717
}
1818
`)
1919
}
20+
2021
func TestValidate_ProvidedNonNullArguments_ValidNonNullableValue_ArgOnOptionalArg(t *testing.T) {
2122
testutil.ExpectPassesRule(t, graphql.ProvidedNonNullArgumentsRule, `
2223
{
@@ -107,6 +108,7 @@ func TestValidate_ProvidedNonNullArguments_ValidNonNullableValue_AllReqsAndOptsO
107108
}
108109
`)
109110
}
111+
110112
func TestValidate_ProvidedNonNullArguments_InvalidNonNullableValue_MissingOneNonNullableArgument(t *testing.T) {
111113
testutil.ExpectFailsRule(t, graphql.ProvidedNonNullArgumentsRule, `
112114
{
@@ -118,7 +120,6 @@ func TestValidate_ProvidedNonNullArguments_InvalidNonNullableValue_MissingOneNon
118120
testutil.RuleError(`Field "multipleReqs" argument "req1" of type "Int!" is required but not provided.`, 4, 13),
119121
})
120122
}
121-
122123
func TestValidate_ProvidedNonNullArguments_InvalidNonNullableValue_MissingMultipleNonNullableArguments(t *testing.T) {
123124
testutil.ExpectFailsRule(t, graphql.ProvidedNonNullArgumentsRule, `
124125
{
@@ -131,7 +132,6 @@ func TestValidate_ProvidedNonNullArguments_InvalidNonNullableValue_MissingMultip
131132
testutil.RuleError(`Field "multipleReqs" argument "req2" of type "Int!" is required but not provided.`, 4, 13),
132133
})
133134
}
134-
135135
func TestValidate_ProvidedNonNullArguments_InvalidNonNullableValue_IncorrectValueAndMissingArgument(t *testing.T) {
136136
testutil.ExpectFailsRule(t, graphql.ProvidedNonNullArgumentsRule, `
137137
{
@@ -151,7 +151,7 @@ func TestValidate_ProvidedNonNullArguments_DirectiveArguments_IgnoresUnknownDire
151151
}
152152
`)
153153
}
154-
func TestValidate_ProvidedNonNullArguments_InvalidNonNullableValue_WithDirectivesOfValidTypes(t *testing.T) {
154+
func TestValidate_ProvidedNonNullArguments_DirectiveArguments_WithDirectivesOfValidTypes(t *testing.T) {
155155
testutil.ExpectPassesRule(t, graphql.ProvidedNonNullArgumentsRule, `
156156
{
157157
dog @include(if: true) {
@@ -163,7 +163,7 @@ func TestValidate_ProvidedNonNullArguments_InvalidNonNullableValue_WithDirective
163163
}
164164
`)
165165
}
166-
func TestValidate_ProvidedNonNullArguments_InvalidNonNullableValue_WithDirectiveWithMissingTypes(t *testing.T) {
166+
func TestValidate_ProvidedNonNullArguments_DirectiveArguments_WithDirectiveWithMissingTypes(t *testing.T) {
167167
testutil.ExpectFailsRule(t, graphql.ProvidedNonNullArgumentsRule, `
168168
{
169169
dog @include {

rules_scalar_leafs_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ func TestValidate_ScalarLeafs_ObjectTypeMissingSelection(t *testing.T) {
2424
testutil.RuleError(`Field "human" of type "Human" must have a sub selection.`, 3, 9),
2525
})
2626
}
27-
2827
func TestValidate_ScalarLeafs_InterfaceTypeMissingSelection(t *testing.T) {
2928
testutil.ExpectFailsRule(t, graphql.ScalarLeafsRule, `
3029
{
@@ -41,6 +40,7 @@ func TestValidate_ScalarLeafs_ValidScalarSelectionWithArgs(t *testing.T) {
4140
}
4241
`)
4342
}
43+
4444
func TestValidate_ScalarLeafs_ScalarSelectionNotAllowedOnBoolean(t *testing.T) {
4545
testutil.ExpectFailsRule(t, graphql.ScalarLeafsRule, `
4646
fragment scalarSelectionsNotAllowedOnBoolean on Dog {

0 commit comments

Comments
 (0)