MCPcopy Create free account
hub / github.com/cli/cli / TestPullRequestGraphQL

Function TestPullRequestGraphQL

api/query_builder_test.go:5–63  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

3import "testing"
4
5func TestPullRequestGraphQL(t *testing.T) {
6 tests := []struct {
7 name string
8 fields []string
9 want string
10 }{
11 {
12 name: "empty",
13 fields: []string(nil),
14 want: "",
15 },
16 {
17 name: "simple fields",
18 fields: []string{"number", "title"},
19 want: "number,title",
20 },
21 {
22 name: "fields with nested structures",
23 fields: []string{"author", "assignees"},
24 want: "author{login,...on User{id,name}},assignees(first:100){nodes{id,login,name,databaseId},totalCount}",
25 },
26 {
27 name: "compressed query",
28 fields: []string{"files"},
29 want: "files(first: 100) {nodes {additions,deletions,path,changeType}}",
30 },
31 {
32 name: "invalid fields",
33 fields: []string{"isPinned", "stateReason", "number"},
34 want: "number",
35 },
36 {
37 name: "projectItems",
38 fields: []string{"projectItems"},
39 want: `projectItems(first:100){nodes{id, project{id,title}, status:fieldValueByName(name: "Status") { ... on ProjectV2ItemFieldSingleSelectValue{optionId,name}}},totalCount}`,
40 },
41 {
42 name: "repository",
43 fields: []string{"repository"},
44 want: "repository{id,name,nameWithOwner,databaseId,viewerPermission}",
45 },
46 {
47 // headRepository shares a Go type with the selection above, which
48 // carries two more fields. They are omitted from JSON when empty,
49 // so adding either name here would put them back into the output
50 // of `gh pr view --json headRepository`.
51 name: "headRepository",
52 fields: []string{"headRepository"},
53 want: "headRepository{id,name,nameWithOwner}",
54 },
55 }
56 for _, tt := range tests {
57 t.Run(tt.name, func(t *testing.T) {
58 if got := PullRequestGraphQL(tt.fields); got != tt.want {
59 t.Errorf("PullRequestGraphQL() = %v, want %v", got, tt.want)
60 }
61 })
62 }

Callers

nothing calls this directly

Calls 3

PullRequestGraphQLFunction · 0.85
RunMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected