forked from graphql-go/graphql
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rules_unique_argument_names_test.go
112 lines (109 loc) · 3.55 KB
/
rules_unique_argument_names_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package graphql_test
import (
"testing"
"github.com/graphql-go/graphql"
"github.com/graphql-go/graphql/gqlerrors"
"github.com/graphql-go/graphql/testutil"
)
func TestValidate_UniqueArgumentNames_NoArgumentsOnField(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.UniqueArgumentNamesRule, `
{
field
}
`)
}
func TestValidate_UniqueArgumentNames_NoArgumentsOnDirective(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.UniqueArgumentNamesRule, `
{
field @directive
}
`)
}
func TestValidate_UniqueArgumentNames_ArgumentOnField(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.UniqueArgumentNamesRule, `
{
field(arg: "value")
}
`)
}
func TestValidate_UniqueArgumentNames_ArgumentOnDirective(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.UniqueArgumentNamesRule, `
{
field @directive(arg: "value")
}
`)
}
func TestValidate_UniqueArgumentNames_SameArgumentOnTwoFields(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.UniqueArgumentNamesRule, `
{
one: field(arg: "value")
two: field(arg: "value")
}
`)
}
func TestValidate_UniqueArgumentNames_SameArgumentOnFieldAndDirective(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.UniqueArgumentNamesRule, `
{
field(arg: "value") @directive(arg: "value")
}
`)
}
func TestValidate_UniqueArgumentNames_SameArgumentOnTwoDirectives(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.UniqueArgumentNamesRule, `
{
field @directive1(arg: "value") @directive2(arg: "value")
}
`)
}
func TestValidate_UniqueArgumentNames_MultipleFieldArguments(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.UniqueArgumentNamesRule, `
{
field(arg1: "value", arg2: "value", arg3: "value")
}
`)
}
func TestValidate_UniqueArgumentNames_MultipleDirectiveArguments(t *testing.T) {
testutil.ExpectPassesRule(t, graphql.UniqueArgumentNamesRule, `
{
field @directive(arg1: "value", arg2: "value", arg3: "value")
}
`)
}
func TestValidate_UniqueArgumentNames_DuplicateFieldArguments(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.UniqueArgumentNamesRule, `
{
field(arg1: "value", arg1: "value")
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`There can be only one argument named "arg1".`, 3, 15, 3, 30),
})
}
func TestValidate_UniqueArgumentNames_ManyDuplicateFieldArguments(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.UniqueArgumentNamesRule, `
{
field(arg1: "value", arg1: "value", arg1: "value")
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`There can be only one argument named "arg1".`, 3, 15, 3, 30),
testutil.RuleError(`There can be only one argument named "arg1".`, 3, 15, 3, 45),
})
}
func TestValidate_UniqueArgumentNames_DuplicateDirectiveArguments(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.UniqueArgumentNamesRule, `
{
field @directive(arg1: "value", arg1: "value")
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`There can be only one argument named "arg1".`, 3, 26, 3, 41),
})
}
func TestValidate_UniqueArgumentNames_ManyDuplicateDirectiveArguments(t *testing.T) {
testutil.ExpectFailsRule(t, graphql.UniqueArgumentNamesRule, `
{
field @directive(arg1: "value", arg1: "value", arg1: "value")
}
`, []gqlerrors.FormattedError{
testutil.RuleError(`There can be only one argument named "arg1".`, 3, 26, 3, 41),
testutil.RuleError(`There can be only one argument named "arg1".`, 3, 26, 3, 56),
})
}