graphql_test.go

  1package tests
  2
  3import (
  4	"net/http/httptest"
  5	"testing"
  6
  7	"github.com/MichaelMure/git-bug/graphql"
  8	"github.com/MichaelMure/git-bug/graphql/models"
  9	"github.com/vektah/gqlgen/client"
 10)
 11
 12func TestQueries(t *testing.T) {
 13	repo := createFilledRepo(10)
 14
 15	handler, err := graphql.NewHandler(repo)
 16	if err != nil {
 17		t.Fatal(err)
 18	}
 19
 20	srv := httptest.NewServer(handler)
 21	c := client.New(srv.URL)
 22
 23	query := `
 24      query {
 25        defaultRepository {
 26          allBugs(first: 2) {
 27            pageInfo {
 28              endCursor
 29              hasNextPage
 30              startCursor
 31              hasPreviousPage
 32            }
 33            nodes{
 34              author {
 35                name
 36                email
 37                avatarUrl
 38              }
 39      
 40              createdAt
 41              humanId
 42              id
 43              lastEdit
 44              status
 45              title
 46      
 47              comments(first: 2) {
 48                pageInfo {
 49                  endCursor
 50                  hasNextPage
 51                  startCursor
 52                  hasPreviousPage
 53                }
 54                nodes {
 55                  files
 56                  message
 57                }
 58              }
 59      
 60              operations(first: 20) {
 61                pageInfo {
 62                  endCursor
 63                  hasNextPage
 64                  startCursor
 65                  hasPreviousPage
 66                }
 67                nodes {
 68                  author {
 69                    name
 70                    email
 71                    avatarUrl
 72                  }
 73                  date
 74                  ... on CreateOperation {
 75                    title
 76                    message
 77                    files
 78                  }
 79                  ... on SetTitleOperation {
 80                    title
 81                    was
 82                  }
 83                  ... on AddCommentOperation {
 84                    files
 85                    message
 86                  }
 87                  ... on SetStatusOperation {
 88                    status
 89                  }
 90                  ... on LabelChangeOperation {
 91                    added
 92                    removed
 93                  }
 94                }
 95              }
 96            }
 97          }
 98        }
 99      }`
100
101	type Person struct {
102		Name      string `json:"name"`
103		Email     string `json:"email"`
104		AvatarUrl string `json:"avatarUrl"`
105	}
106
107	var resp struct {
108		DefaultRepository struct {
109			AllBugs struct {
110				PageInfo models.PageInfo
111				Nodes    []struct {
112					Author    Person
113					CreatedAt string `json:"createdAt"`
114					HumanId   string `json:"humanId"`
115					Id        string
116					LastEdit  string `json:"lastEdit"`
117					Status    string
118					Title     string
119
120					Comments struct {
121						PageInfo models.PageInfo
122						Nodes    []struct {
123							Files   []string
124							Message string
125						}
126					}
127
128					Operations struct {
129						PageInfo models.PageInfo
130						Nodes    []struct {
131							Author  Person
132							Date    string
133							Title   string
134							Files   []string
135							Message string
136							Was     string
137							Status  string
138							Added   []string
139							Removed []string
140						}
141					}
142				}
143			}
144		}
145	}
146
147	c.MustPost(query, &resp)
148}