1package graphql
2
3import (
4 "net/http/httptest"
5 "testing"
6
7 "github.com/vektah/gqlgen/client"
8
9 "github.com/MichaelMure/git-bug/graphql/models"
10 "github.com/MichaelMure/git-bug/misc/random_bugs"
11 "github.com/MichaelMure/git-bug/repository"
12 "github.com/MichaelMure/git-bug/util/test"
13)
14
15func CreateFilledRepo(bugNumber int) repository.ClockedRepo {
16 repo := test.CreateRepo(false)
17
18 var seed int64 = 42
19 options := random_bugs.DefaultOptions()
20
21 options.BugNumber = bugNumber
22
23 random_bugs.CommitRandomBugsWithSeed(repo, options, seed)
24 return repo
25}
26
27func TestQueries(t *testing.T) {
28 repo := CreateFilledRepo(10)
29
30 handler, err := NewHandler(repo)
31 if err != nil {
32 t.Fatal(err)
33 }
34
35 srv := httptest.NewServer(handler)
36 c := client.New(srv.URL)
37
38 query := `
39 query {
40 defaultRepository {
41 allBugs(first: 2) {
42 pageInfo {
43 endCursor
44 hasNextPage
45 startCursor
46 hasPreviousPage
47 }
48 nodes{
49 author {
50 name
51 email
52 avatarUrl
53 }
54
55 createdAt
56 humanId
57 id
58 lastEdit
59 status
60 title
61
62 actors(first: 10) {
63 pageInfo {
64 endCursor
65 hasNextPage
66 startCursor
67 hasPreviousPage
68 }
69 nodes {
70 id
71 humanId
72 name
73 displayName
74 }
75 }
76
77 participants(first: 10) {
78 pageInfo {
79 endCursor
80 hasNextPage
81 startCursor
82 hasPreviousPage
83 }
84 nodes {
85 id
86 humanId
87 name
88 displayName
89 }
90 }
91
92 comments(first: 2) {
93 pageInfo {
94 endCursor
95 hasNextPage
96 startCursor
97 hasPreviousPage
98 }
99 nodes {
100 files
101 message
102 }
103 }
104
105 operations(first: 20) {
106 pageInfo {
107 endCursor
108 hasNextPage
109 startCursor
110 hasPreviousPage
111 }
112 nodes {
113 author {
114 name
115 email
116 avatarUrl
117 }
118 date
119 ... on CreateOperation {
120 title
121 message
122 files
123 }
124 ... on SetTitleOperation {
125 title
126 was
127 }
128 ... on AddCommentOperation {
129 files
130 message
131 }
132 ... on SetStatusOperation {
133 status
134 }
135 ... on LabelChangeOperation {
136 added {
137 name
138 color {
139 R
140 G
141 B
142 }
143 }
144 removed {
145 name
146 color {
147 R
148 G
149 B
150 }
151 }
152 }
153 }
154 }
155 }
156 }
157 }
158 }`
159
160 type Identity struct {
161 Id string `json:"id"`
162 HumanId string `json:"humanId"`
163 Name string `json:"name"`
164 Email string `json:"email"`
165 AvatarUrl string `json:"avatarUrl"`
166 DisplayName string `json:"displayName"`
167 }
168
169 type Label struct {
170 Name string
171 Color struct {
172 R, G, B int
173 }
174 }
175
176 var resp struct {
177 DefaultRepository struct {
178 AllBugs struct {
179 PageInfo models.PageInfo
180 Nodes []struct {
181 Author Identity
182 CreatedAt string `json:"createdAt"`
183 HumanId string `json:"humanId"`
184 Id string
185 LastEdit string `json:"lastEdit"`
186 Status string
187 Title string
188
189 Actors struct {
190 PageInfo models.PageInfo
191 Nodes []Identity
192 }
193
194 Participants struct {
195 PageInfo models.PageInfo
196 Nodes []Identity
197 }
198
199 Comments struct {
200 PageInfo models.PageInfo
201 Nodes []struct {
202 Files []string
203 Message string
204 }
205 }
206
207 Operations struct {
208 PageInfo models.PageInfo
209 Nodes []struct {
210 Author Identity
211 Date string
212 Title string
213 Files []string
214 Message string
215 Was string
216 Status string
217 Added []Label
218 Removed []Label
219 }
220 }
221 }
222 }
223 }
224 }
225
226 c.MustPost(query, &resp)
227}