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