Skip to content

Commit

Permalink
Added missing rule tests
Browse files Browse the repository at this point in the history
- Re-checked the number of tests against `graphql-js` to ensure that all tests have been ported
  • Loading branch information
sogko committed Nov 18, 2015
1 parent 7b9d6e3 commit 49b0dab
Show file tree
Hide file tree
Showing 11 changed files with 98 additions and 25 deletions.
67 changes: 64 additions & 3 deletions rules_arguments_of_correct_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,21 @@ func TestValidate_ArgValuesOfCorrectType_InvalidStringValues_UnquotedStringIntoS
})
}

func TestValidate_ArgValuesOfCorrectType_InvalidIntValues_StringIntoInt(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.ArgumentsOfCorrectTypeRule, `
{
complicatedArgs {
intArgField(intArg: "3")
}
}
`,
[]gqlerrors.FormattedError{
testutil.RuleError(
`Argument "intArg" expected type "Int" but got: "3".`,
4, 33,
),
})
}
func TestValidate_ArgValuesOfCorrectType_InvalidIntValues_BigIntIntoInt(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.ArgumentsOfCorrectTypeRule, `
{
Expand Down Expand Up @@ -203,6 +218,52 @@ func TestValidate_ArgValuesOfCorrectType_InvalidIntValues_FloatIntoInt(t *testin
})
}

func TestValidate_ArgValuesOfCorrectType_InvalidFloatValues_StringIntoFloat(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.ArgumentsOfCorrectTypeRule, `
{
complicatedArgs {
floatArgField(floatArg: "3.333")
}
}
`,
[]gqlerrors.FormattedError{
testutil.RuleError(
`Argument "floatArg" expected type "Float" but got: "3.333".`,
4, 37,
),
})
}
func TestValidate_ArgValuesOfCorrectType_InvalidFloatValues_BooleanIntoFloat(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.ArgumentsOfCorrectTypeRule, `
{
complicatedArgs {
floatArgField(floatArg: true)
}
}
`,
[]gqlerrors.FormattedError{
testutil.RuleError(
`Argument "floatArg" expected type "Float" but got: true.`,
4, 37,
),
})
}
func TestValidate_ArgValuesOfCorrectType_InvalidFloatValues_UnquotedIntoFloat(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.ArgumentsOfCorrectTypeRule, `
{
complicatedArgs {
floatArgField(floatArg: FOO)
}
}
`,
[]gqlerrors.FormattedError{
testutil.RuleError(
`Argument "floatArg" expected type "Float" but got: FOO.`,
4, 37,
),
})
}

func TestValidate_ArgValuesOfCorrectType_InvalidBooleanValues_IntIntoBoolean(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.ArgumentsOfCorrectTypeRule, `
{
Expand Down Expand Up @@ -264,7 +325,7 @@ func TestValidate_ArgValuesOfCorrectType_InvalidBooleanValues_UnquotedStringInto
})
}

func TestValidate_ArgValuesOfCorrectType_InvalidIDValues_FloatIntoID(t *testing.T) {
func TestValidate_ArgValuesOfCorrectType_InvalidIDValue_FloatIntoID(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.ArgumentsOfCorrectTypeRule, `
{
complicatedArgs {
Expand All @@ -279,7 +340,7 @@ func TestValidate_ArgValuesOfCorrectType_InvalidIDValues_FloatIntoID(t *testing.
),
})
}
func TestValidate_ArgValuesOfCorrectType_InvalidIDValues_BooleanIntoID(t *testing.T) {
func TestValidate_ArgValuesOfCorrectType_InvalidIDValue_BooleanIntoID(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.ArgumentsOfCorrectTypeRule, `
{
complicatedArgs {
Expand All @@ -294,7 +355,7 @@ func TestValidate_ArgValuesOfCorrectType_InvalidIDValues_BooleanIntoID(t *testin
),
})
}
func TestValidate_ArgValuesOfCorrectType_InvalidIDValues_UnquotedIntoID(t *testing.T) {
func TestValidate_ArgValuesOfCorrectType_InvalidIDValue_UnquotedIntoID(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.ArgumentsOfCorrectTypeRule, `
{
complicatedArgs {
Expand Down
3 changes: 0 additions & 3 deletions rules_default_values_of_correct_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ func TestValidate_VariableDefaultValuesOfCorrectType_VariablesWithValidDefaultVa
}
`)
}

func TestValidate_VariableDefaultValuesOfCorrectType_NoRequiredVariablesWithDefaultValues(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.DefaultValuesOfCorrectTypeRule, `
query UnreachableDefaultValues($a: Int! = 3, $b: String! = "default") {
Expand Down Expand Up @@ -69,7 +68,6 @@ func TestValidate_VariableDefaultValuesOfCorrectType_VariablesWithInvalidDefault
testutil.RuleError(`Variable "$c" of type "ComplexInput" has invalid default value: "notverycomplex".`, 5, 28),
})
}

func TestValidate_VariableDefaultValuesOfCorrectType_ComplexVariablesMissingRequiredField(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.DefaultValuesOfCorrectTypeRule, `
query MissingRequiredField($a: ComplexInput = {intField: 3}) {
Expand All @@ -80,7 +78,6 @@ func TestValidate_VariableDefaultValuesOfCorrectType_ComplexVariablesMissingRequ
testutil.RuleError(`Variable "$a" of type "ComplexInput" has invalid default value: {intField: 3}.`, 2, 53),
})
}

func TestValidate_VariableDefaultValuesOfCorrectType_ListVariablesWithInvalidItem(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.DefaultValuesOfCorrectTypeRule, `
query InvalidItem($a: [String] = ["one", 2]) {
Expand Down
1 change: 0 additions & 1 deletion rules_fragments_on_composite_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ func TestValidate_FragmentsOnCompositeTypes_UnionIsValidFragmentType(t *testing.
}
`)
}

func TestValidate_FragmentsOnCompositeTypes_ScalarIsInvalidFragmentType(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.FragmentsOnCompositeTypesRule, `
fragment scalarFragment on Boolean {
Expand Down
12 changes: 12 additions & 0 deletions rules_known_directives_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,18 @@ func TestValidate_KnownDirectives_WithNoDirectives(t *testing.T) {
}
`)
}
func TestValidate_KnownDirectives_WithKnownDirective(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.KnownDirectivesRule, `
{
dog @include(if: true) {
name
}
human @skip(if: false) {
name
}
}
`)
}
func TestValidate_KnownDirectives_WithUnknownDirective(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.KnownDirectivesRule, `
{
Expand Down
1 change: 0 additions & 1 deletion rules_lone_anonymous_operation_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ func TestValidate_AnonymousOperationMustBeAlone_AnonOperationWithFragment(t *tes
}
`)
}

func TestValidate_AnonymousOperationMustBeAlone_MultipleAnonOperations(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.LoneAnonymousOperationRule, `
{
Expand Down
15 changes: 13 additions & 2 deletions rules_no_fragment_cycles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ func TestValidate_NoCircularFragmentSpreads_SpreadingRecursivelyWithinFieldFails
testutil.RuleError(`Cannot spread fragment "fragA" within itself.`, 2, 45),
})
}

func TestValidate_NoCircularFragmentSpreads_NoSpreadingItselfDirectly(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.NoFragmentCyclesRule, `
fragment fragA on Dog { ...fragA }
Expand All @@ -65,15 +66,24 @@ func TestValidate_NoCircularFragmentSpreads_NoSpreadingItselfDirectlyWithinInlin
testutil.RuleError(`Cannot spread fragment "fragA" within itself.`, 4, 11),
})
}
func TestValidate_NoCircularFragmentSpreads_NoSpreadingItselfDirectlyMultiple(t *testing.T) {

func TestValidate_NoCircularFragmentSpreads_NoSpreadingItselfIndirectly(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.NoFragmentCyclesRule, `
fragment fragA on Dog { ...fragB }
fragment fragB on Dog { ...fragA }
`, []gqlerrors.FormattedError{
testutil.RuleError(`Cannot spread fragment "fragA" within itself via fragB.`, 2, 31, 3, 31),
})
}
func TestValidate_NoCircularFragmentSpreads_NoSpreadingItselfDirectlyWithinInlineFragmentMultiple(t *testing.T) {
func TestValidate_NoCircularFragmentSpreads_NoSpreadingItselfIndirectlyReportsOppositeOrder(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.NoFragmentCyclesRule, `
fragment fragB on Dog { ...fragA }
fragment fragA on Dog { ...fragB }
`, []gqlerrors.FormattedError{
testutil.RuleError(`Cannot spread fragment "fragB" within itself via fragA.`, 2, 31, 3, 31),
})
}
func TestValidate_NoCircularFragmentSpreads_NoSpreadingItselfIndirectlyWithinInlineFragment(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.NoFragmentCyclesRule, `
fragment fragA on Pet {
... on Dog {
Expand All @@ -89,6 +99,7 @@ func TestValidate_NoCircularFragmentSpreads_NoSpreadingItselfDirectlyWithinInlin
testutil.RuleError(`Cannot spread fragment "fragA" within itself via fragB.`, 4, 11, 9, 11),
})
}

func TestValidate_NoCircularFragmentSpreads_NoSpreadingItselfDeeply(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.NoFragmentCyclesRule, `
fragment fragA on Dog { ...fragB }
Expand Down
6 changes: 0 additions & 6 deletions rules_no_undefined_variables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ func TestValidate_NoUndefinedVariables_MultipleVariablesNotDefined(t *testing.T)
testutil.RuleError(`Variable "$c" is not defined.`, 3, 32),
})
}

func TestValidate_NoUndefinedVariables_VariableInFragmentNotDefinedByUnnamedQuery(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.NoUndefinedVariablesRule, `
{
Expand All @@ -143,7 +142,6 @@ func TestValidate_NoUndefinedVariables_VariableInFragmentNotDefinedByUnnamedQuer
testutil.RuleError(`Variable "$a" is not defined.`, 6, 18),
})
}

func TestValidate_NoUndefinedVariables_VariableInFragmentNotDefinedByOperation(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.NoUndefinedVariablesRule, `
query Foo($a: String, $b: String) {
Expand All @@ -166,7 +164,6 @@ func TestValidate_NoUndefinedVariables_VariableInFragmentNotDefinedByOperation(t
testutil.RuleError(`Variable "$c" is not defined by operation "Foo".`, 16, 18, 2, 7),
})
}

func TestValidate_NoUndefinedVariables_MultipleVariablesInFragmentsNotDefined(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.NoUndefinedVariablesRule, `
query Foo($b: String) {
Expand All @@ -190,7 +187,6 @@ func TestValidate_NoUndefinedVariables_MultipleVariablesInFragmentsNotDefined(t
testutil.RuleError(`Variable "$c" is not defined by operation "Foo".`, 16, 18, 2, 7),
})
}

func TestValidate_NoUndefinedVariables_SingleVariableInFragmentNotDefinedByMultipleOperations(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.NoUndefinedVariablesRule, `
query Foo($a: String) {
Expand All @@ -207,7 +203,6 @@ func TestValidate_NoUndefinedVariables_SingleVariableInFragmentNotDefinedByMulti
testutil.RuleError(`Variable "$b" is not defined by operation "Bar".`, 9, 25, 5, 7),
})
}

func TestValidate_NoUndefinedVariables_VariablesInFragmentNotDefinedByMultipleOperations(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.NoUndefinedVariablesRule, `
query Foo($b: String) {
Expand Down Expand Up @@ -243,7 +238,6 @@ func TestValidate_NoUndefinedVariables_VariableInFragmentUsedByOtherOperation(t
testutil.RuleError(`Variable "$b" is not defined by operation "Bar".`, 12, 18, 5, 7),
})
}

func TestValidate_NoUndefinedVariables_VaMultipleUndefinedVariablesProduceMultipleErrors(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.NoUndefinedVariablesRule, `
query Foo($b: String) {
Expand Down
2 changes: 0 additions & 2 deletions rules_no_unused_fragments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ func TestValidate_NoUnusedFragments_ContainsUnknownFragments(t *testing.T) {
testutil.RuleError(`Fragment "Unused2" is never used.`, 25, 7),
})
}

func TestValidate_NoUnusedFragments_ContainsUnknownFragmentsWithRefCycle(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.NoUnusedFragmentsRule, `
query Foo {
Expand Down Expand Up @@ -123,7 +122,6 @@ func TestValidate_NoUnusedFragments_ContainsUnknownFragmentsWithRefCycle(t *test
testutil.RuleError(`Fragment "Unused2" is never used.`, 26, 7),
})
}

func TestValidate_NoUnusedFragments_ContainsUnknownAndUndefFragments(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.NoUnusedFragmentsRule, `
query Foo {
Expand Down
6 changes: 4 additions & 2 deletions rules_possible_fragment_spreads_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ func TestValidate_PossibleFragmentSpreads_ObjectIntoContainingUnion(t *testing.T
fragment dogFragment on Dog { barkVolume }
`)
}

func TestValidate_PossibleFragmentSpreads_UnionIntoContainedObject(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.PossibleFragmentSpreadsRule, `
fragment unionWithinObject on Dog { ...catOrDogFragment }
Expand All @@ -49,6 +50,7 @@ func TestValidate_PossibleFragmentSpreads_UnionIntoOverlappingUnion(t *testing.T
fragment catOrDogFragment on CatOrDog { __typename }
`)
}

func TestValidate_PossibleFragmentSpreads_InterfaceIntoImplementedObject(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.PossibleFragmentSpreadsRule, `
fragment interfaceWithinObject on Dog { ...petFragment }
Expand Down Expand Up @@ -81,7 +83,6 @@ func TestValidate_PossibleFragmentSpreads_DifferentObjectIntoObject(t *testing.T
`type "Cat" can never be of type "Dog".`, 2, 51),
})
}

func TestValidate_PossibleFragmentSpreads_DifferentObjectIntoObjectInInlineFragment(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.PossibleFragmentSpreadsRule, `
fragment invalidObjectWithinObjectAnon on Cat {
Expand All @@ -92,6 +93,7 @@ func TestValidate_PossibleFragmentSpreads_DifferentObjectIntoObjectInInlineFragm
`type "Cat" can never be of type "Dog".`, 3, 9),
})
}

func TestValidate_PossibleFragmentSpreads_ObjectIntoNotImplementingInterface(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.PossibleFragmentSpreadsRule, `
fragment invalidObjectWithinInterface on Pet { ...humanFragment }
Expand All @@ -110,6 +112,7 @@ func TestValidate_PossibleFragmentSpreads_ObjectIntoNotContainingUnion(t *testin
`type "CatOrDog" can never be of type "Human".`, 2, 55),
})
}

func TestValidate_PossibleFragmentSpreads_UnionIntoNotContainedObject(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.PossibleFragmentSpreadsRule, `
fragment invalidUnionWithinObject on Human { ...catOrDogFragment }
Expand All @@ -128,7 +131,6 @@ func TestValidate_PossibleFragmentSpreads_UnionIntoNonOverlappingInterface(t *te
`type "Pet" can never be of type "HumanOrAlien".`, 2, 53),
})
}

func TestValidate_PossibleFragmentSpreads_UnionIntoNonOverlappingUnion(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.PossibleFragmentSpreadsRule, `
fragment invalidUnionWithinUnion on CatOrDog { ...humanOrAlienFragment }
Expand Down
8 changes: 4 additions & 4 deletions rules_provided_non_null_arguments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ func TestValidate_ProvidedNonNullArguments_IgnoresUnknownArguments(t *testing.T)
}
`)
}

func TestValidate_ProvidedNonNullArguments_ValidNonNullableValue_ArgOnOptionalArg(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.ProvidedNonNullArgumentsRule, `
{
Expand Down Expand Up @@ -107,6 +108,7 @@ func TestValidate_ProvidedNonNullArguments_ValidNonNullableValue_AllReqsAndOptsO
}
`)
}

func TestValidate_ProvidedNonNullArguments_InvalidNonNullableValue_MissingOneNonNullableArgument(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.ProvidedNonNullArgumentsRule, `
{
Expand All @@ -118,7 +120,6 @@ func TestValidate_ProvidedNonNullArguments_InvalidNonNullableValue_MissingOneNon
testutil.RuleError(`Field "multipleReqs" argument "req1" of type "Int!" is required but not provided.`, 4, 13),
})
}

func TestValidate_ProvidedNonNullArguments_InvalidNonNullableValue_MissingMultipleNonNullableArguments(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.ProvidedNonNullArgumentsRule, `
{
Expand All @@ -131,7 +132,6 @@ func TestValidate_ProvidedNonNullArguments_InvalidNonNullableValue_MissingMultip
testutil.RuleError(`Field "multipleReqs" argument "req2" of type "Int!" is required but not provided.`, 4, 13),
})
}

func TestValidate_ProvidedNonNullArguments_InvalidNonNullableValue_IncorrectValueAndMissingArgument(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.ProvidedNonNullArgumentsRule, `
{
Expand All @@ -151,7 +151,7 @@ func TestValidate_ProvidedNonNullArguments_DirectiveArguments_IgnoresUnknownDire
}
`)
}
func TestValidate_ProvidedNonNullArguments_InvalidNonNullableValue_WithDirectivesOfValidTypes(t *testing.T) {
func TestValidate_ProvidedNonNullArguments_DirectiveArguments_WithDirectivesOfValidTypes(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.ProvidedNonNullArgumentsRule, `
{
dog @include(if: true) {
Expand All @@ -163,7 +163,7 @@ func TestValidate_ProvidedNonNullArguments_InvalidNonNullableValue_WithDirective
}
`)
}
func TestValidate_ProvidedNonNullArguments_InvalidNonNullableValue_WithDirectiveWithMissingTypes(t *testing.T) {
func TestValidate_ProvidedNonNullArguments_DirectiveArguments_WithDirectiveWithMissingTypes(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.ProvidedNonNullArgumentsRule, `
{
dog @include {
Expand Down
2 changes: 1 addition & 1 deletion rules_scalar_leafs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func TestValidate_ScalarLeafs_ObjectTypeMissingSelection(t *testing.T) {
testutil.RuleError(`Field "human" of type "Human" must have a sub selection.`, 3, 9),
})
}

func TestValidate_ScalarLeafs_InterfaceTypeMissingSelection(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.ScalarLeafsRule, `
{
Expand All @@ -41,6 +40,7 @@ func TestValidate_ScalarLeafs_ValidScalarSelectionWithArgs(t *testing.T) {
}
`)
}

func TestValidate_ScalarLeafs_ScalarSelectionNotAllowedOnBoolean(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.ScalarLeafsRule, `
fragment scalarSelectionsNotAllowedOnBoolean on Dog {
Expand Down

0 comments on commit 49b0dab

Please sign in to comment.