graphql_test.go

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