github.com/ungtb10d/cli/v2@v2.0.0-20221110210412-98537dd9d6a1/api/query_builder_test.go (about) 1 package api 2 3 import "testing" 4 5 func 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},assignees(first:100){nodes{id,login,name},totalCount}", 25 }, 26 { 27 name: "compressed query", 28 fields: []string{"files"}, 29 want: "files(first: 100) {nodes {additions,deletions,path}}", 30 }, 31 { 32 name: "invalid fields", 33 fields: []string{"isPinned", "stateReason", "number"}, 34 want: "number", 35 }, 36 } 37 for _, tt := range tests { 38 t.Run(tt.name, func(t *testing.T) { 39 if got := PullRequestGraphQL(tt.fields); got != tt.want { 40 t.Errorf("PullRequestGraphQL() = %v, want %v", got, tt.want) 41 } 42 }) 43 } 44 } 45 46 func TestIssueGraphQL(t *testing.T) { 47 tests := []struct { 48 name string 49 fields []string 50 want string 51 }{ 52 { 53 name: "empty", 54 fields: []string(nil), 55 want: "", 56 }, 57 { 58 name: "simple fields", 59 fields: []string{"number", "title"}, 60 want: "number,title", 61 }, 62 { 63 name: "fields with nested structures", 64 fields: []string{"author", "assignees"}, 65 want: "author{login},assignees(first:100){nodes{id,login,name},totalCount}", 66 }, 67 { 68 name: "compressed query", 69 fields: []string{"files"}, 70 want: "files(first: 100) {nodes {additions,deletions,path}}", 71 }, 72 } 73 for _, tt := range tests { 74 t.Run(tt.name, func(t *testing.T) { 75 if got := IssueGraphQL(tt.fields); got != tt.want { 76 t.Errorf("IssueGraphQL() = %v, want %v", got, tt.want) 77 } 78 }) 79 } 80 }