2018-11-21 20:56:12 +03:00
|
|
|
package graphql
|
2018-09-26 16:55:14 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2020-02-06 00:03:19 +03:00
|
|
|
"github.com/99designs/gqlgen/client"
|
2020-06-21 23:12:04 +03:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
2019-04-05 02:15:52 +03:00
|
|
|
|
2020-06-21 23:12:04 +03:00
|
|
|
"github.com/MichaelMure/git-bug/api/graphql/models"
|
|
|
|
"github.com/MichaelMure/git-bug/cache"
|
2019-02-16 15:48:46 +03:00
|
|
|
"github.com/MichaelMure/git-bug/misc/random_bugs"
|
|
|
|
"github.com/MichaelMure/git-bug/repository"
|
2018-09-26 16:55:14 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestQueries(t *testing.T) {
|
2020-10-04 20:56:16 +03:00
|
|
|
repo := repository.CreateGoGitTestRepo(false)
|
2020-06-23 19:02:54 +03:00
|
|
|
defer repository.CleanupTestRepos(repo)
|
2019-05-27 22:14:55 +03:00
|
|
|
|
|
|
|
random_bugs.FillRepoWithSeed(repo, 10, 42)
|
2018-09-26 16:55:14 +03:00
|
|
|
|
2020-06-21 23:12:04 +03:00
|
|
|
mrc := cache.NewMultiRepoCache()
|
|
|
|
_, err := mrc.RegisterDefaultRepository(repo)
|
|
|
|
require.NoError(t, err)
|
|
|
|
|
|
|
|
handler := NewHandler(mrc)
|
2018-09-26 16:55:14 +03:00
|
|
|
|
2020-02-06 01:42:49 +03:00
|
|
|
c := client.New(handler)
|
2018-09-26 16:55:14 +03:00
|
|
|
|
|
|
|
query := `
|
2019-04-05 02:15:52 +03:00
|
|
|
query {
|
2020-02-05 03:06:53 +03:00
|
|
|
repository {
|
2018-09-26 16:55:14 +03:00
|
|
|
allBugs(first: 2) {
|
|
|
|
pageInfo {
|
|
|
|
endCursor
|
|
|
|
hasNextPage
|
|
|
|
startCursor
|
|
|
|
hasPreviousPage
|
|
|
|
}
|
|
|
|
nodes{
|
|
|
|
author {
|
|
|
|
name
|
|
|
|
email
|
|
|
|
avatarUrl
|
|
|
|
}
|
|
|
|
|
|
|
|
createdAt
|
|
|
|
humanId
|
|
|
|
id
|
|
|
|
lastEdit
|
|
|
|
status
|
|
|
|
title
|
2019-04-05 02:13:17 +03:00
|
|
|
|
|
|
|
actors(first: 10) {
|
|
|
|
pageInfo {
|
|
|
|
endCursor
|
|
|
|
hasNextPage
|
|
|
|
startCursor
|
|
|
|
hasPreviousPage
|
|
|
|
}
|
2019-04-05 02:15:52 +03:00
|
|
|
nodes {
|
|
|
|
id
|
|
|
|
humanId
|
|
|
|
name
|
|
|
|
displayName
|
|
|
|
}
|
|
|
|
}
|
2019-04-05 02:13:17 +03:00
|
|
|
|
2019-04-05 02:15:52 +03:00
|
|
|
participants(first: 10) {
|
2019-04-05 02:13:17 +03:00
|
|
|
pageInfo {
|
|
|
|
endCursor
|
|
|
|
hasNextPage
|
|
|
|
startCursor
|
|
|
|
hasPreviousPage
|
|
|
|
}
|
2019-04-05 02:15:52 +03:00
|
|
|
nodes {
|
|
|
|
id
|
|
|
|
humanId
|
|
|
|
name
|
|
|
|
displayName
|
|
|
|
}
|
|
|
|
}
|
2018-09-26 16:55:14 +03:00
|
|
|
|
|
|
|
comments(first: 2) {
|
|
|
|
pageInfo {
|
|
|
|
endCursor
|
|
|
|
hasNextPage
|
|
|
|
startCursor
|
|
|
|
hasPreviousPage
|
|
|
|
}
|
|
|
|
nodes {
|
|
|
|
files
|
|
|
|
message
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
operations(first: 20) {
|
|
|
|
pageInfo {
|
|
|
|
endCursor
|
|
|
|
hasNextPage
|
|
|
|
startCursor
|
|
|
|
hasPreviousPage
|
|
|
|
}
|
|
|
|
nodes {
|
|
|
|
author {
|
|
|
|
name
|
|
|
|
email
|
|
|
|
avatarUrl
|
|
|
|
}
|
|
|
|
date
|
|
|
|
... on CreateOperation {
|
|
|
|
title
|
|
|
|
message
|
|
|
|
files
|
|
|
|
}
|
|
|
|
... on SetTitleOperation {
|
|
|
|
title
|
|
|
|
was
|
|
|
|
}
|
|
|
|
... on AddCommentOperation {
|
|
|
|
files
|
|
|
|
message
|
|
|
|
}
|
|
|
|
... on SetStatusOperation {
|
|
|
|
status
|
|
|
|
}
|
|
|
|
... on LabelChangeOperation {
|
2019-05-16 01:01:43 +03:00
|
|
|
added {
|
|
|
|
name
|
|
|
|
color {
|
|
|
|
R
|
|
|
|
G
|
|
|
|
B
|
|
|
|
}
|
|
|
|
}
|
|
|
|
removed {
|
|
|
|
name
|
|
|
|
color {
|
|
|
|
R
|
|
|
|
G
|
|
|
|
B
|
|
|
|
}
|
|
|
|
}
|
2018-09-26 16:55:14 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`
|
|
|
|
|
2019-03-31 23:32:35 +03:00
|
|
|
type Identity struct {
|
2019-04-05 02:13:17 +03:00
|
|
|
Id string `json:"id"`
|
|
|
|
HumanId string `json:"humanId"`
|
|
|
|
Name string `json:"name"`
|
|
|
|
Email string `json:"email"`
|
|
|
|
AvatarUrl string `json:"avatarUrl"`
|
|
|
|
DisplayName string `json:"displayName"`
|
2018-09-26 16:55:14 +03:00
|
|
|
}
|
|
|
|
|
2019-05-16 01:01:43 +03:00
|
|
|
type Label struct {
|
|
|
|
Name string
|
|
|
|
Color struct {
|
|
|
|
R, G, B int
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-26 16:55:14 +03:00
|
|
|
var resp struct {
|
2020-02-05 03:06:53 +03:00
|
|
|
Repository struct {
|
2018-09-26 16:55:14 +03:00
|
|
|
AllBugs struct {
|
|
|
|
PageInfo models.PageInfo
|
|
|
|
Nodes []struct {
|
2019-04-05 02:13:17 +03:00
|
|
|
Author Identity
|
|
|
|
CreatedAt string `json:"createdAt"`
|
|
|
|
HumanId string `json:"humanId"`
|
|
|
|
Id string
|
|
|
|
LastEdit string `json:"lastEdit"`
|
|
|
|
Status string
|
|
|
|
Title string
|
|
|
|
|
|
|
|
Actors struct {
|
|
|
|
PageInfo models.PageInfo
|
|
|
|
Nodes []Identity
|
|
|
|
}
|
|
|
|
|
|
|
|
Participants struct {
|
|
|
|
PageInfo models.PageInfo
|
|
|
|
Nodes []Identity
|
|
|
|
}
|
2018-09-26 16:55:14 +03:00
|
|
|
|
|
|
|
Comments struct {
|
|
|
|
PageInfo models.PageInfo
|
|
|
|
Nodes []struct {
|
|
|
|
Files []string
|
|
|
|
Message string
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Operations struct {
|
|
|
|
PageInfo models.PageInfo
|
|
|
|
Nodes []struct {
|
2019-03-31 23:32:35 +03:00
|
|
|
Author Identity
|
2018-09-26 16:55:14 +03:00
|
|
|
Date string
|
|
|
|
Title string
|
|
|
|
Files []string
|
|
|
|
Message string
|
|
|
|
Was string
|
|
|
|
Status string
|
2019-05-16 01:01:43 +03:00
|
|
|
Added []Label
|
|
|
|
Removed []Label
|
2018-09-26 16:55:14 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-21 23:12:04 +03:00
|
|
|
err = c.Post(query, &resp)
|
|
|
|
assert.NoError(t, err)
|
2018-09-26 16:55:14 +03:00
|
|
|
}
|