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