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