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