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