graphql_test.go

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