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 actors {
54 name
55 email
56 avatarUrl
57 }
58 participants {
59 name
60 email
61 avatarUrl
62 }
63
64 createdAt
65 humanId
66 id
67 lastEdit
68 status
69 title
70
71 comments(first: 2) {
72 pageInfo {
73 endCursor
74 hasNextPage
75 startCursor
76 hasPreviousPage
77 }
78 nodes {
79 files
80 message
81 }
82 }
83
84 operations(first: 20) {
85 pageInfo {
86 endCursor
87 hasNextPage
88 startCursor
89 hasPreviousPage
90 }
91 nodes {
92 author {
93 name
94 email
95 avatarUrl
96 }
97 date
98 ... on CreateOperation {
99 title
100 message
101 files
102 }
103 ... on SetTitleOperation {
104 title
105 was
106 }
107 ... on AddCommentOperation {
108 files
109 message
110 }
111 ... on SetStatusOperation {
112 status
113 }
114 ... on LabelChangeOperation {
115 added
116 removed
117 }
118 }
119 }
120 }
121 }
122 }
123 }`
124
125 type Identity struct {
126 Name string `json:"name"`
127 Email string `json:"email"`
128 AvatarUrl string `json:"avatarUrl"`
129 }
130
131 var resp struct {
132 DefaultRepository struct {
133 AllBugs struct {
134 PageInfo models.PageInfo
135 Nodes []struct {
136 Author Identity
137 Actors []Identity
138 Participants []Identity
139 CreatedAt string `json:"createdAt"`
140 HumanId string `json:"humanId"`
141 Id string
142 LastEdit string `json:"lastEdit"`
143 Status string
144 Title string
145
146 Comments struct {
147 PageInfo models.PageInfo
148 Nodes []struct {
149 Files []string
150 Message string
151 }
152 }
153
154 Operations struct {
155 PageInfo models.PageInfo
156 Nodes []struct {
157 Author Identity
158 Date string
159 Title string
160 Files []string
161 Message string
162 Was string
163 Status string
164 Added []string
165 Removed []string
166 }
167 }
168 }
169 }
170 }
171 }
172
173 c.MustPost(query, &resp)
174}