MCPcopy Index your code
hub / github.com/cli/cli / TestProjectsV2ItemsForIssue

Function TestProjectsV2ItemsForIssue

api/queries_projects_v2_test.go:98–164  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

96}
97
98func TestProjectsV2ItemsForIssue(t *testing.T) {
99 var tests = []struct {
100 name string
101 httpStubs func(*httpmock.Registry)
102 expectItems ProjectItems
103 expectError bool
104 }{
105 {
106 name: "retrieves project items for issue",
107 httpStubs: func(reg *httpmock.Registry) {
108 reg.Register(
109 httpmock.GraphQL(`query IssueProjectItems\b`),
110 httpmock.GraphQLQuery(`{"data":{"repository":{"issue":{"projectItems":{"nodes": [{"id":"projectItem1"},{"id":"projectItem2"}]}}}}}`,
111 func(query string, inputs map[string]interface{}) {}),
112 )
113 },
114 expectItems: ProjectItems{
115 Nodes: []*ProjectV2Item{
116 {ID: "projectItem1"},
117 {ID: "projectItem2"},
118 },
119 },
120 },
121 {
122 name: "fails to retrieve project items for issue",
123 httpStubs: func(reg *httpmock.Registry) {
124 reg.Register(
125 httpmock.GraphQL(`query IssueProjectItems\b`),
126 httpmock.GraphQLQuery(`{"data":{}, "errors": [{"message": "some gql error"}]}`,
127 func(query string, inputs map[string]interface{}) {}),
128 )
129 },
130 expectError: true,
131 },
132 {
133 name: "skips null project items for issue",
134 httpStubs: func(reg *httpmock.Registry) {
135 reg.Register(
136 httpmock.GraphQL(`query IssueProjectItems\b`),
137 httpmock.GraphQLQuery(`{"data":{"repository":{"issue":{"projectItems":{"totalCount":1,"nodes":[null]}}}}}`,
138 func(query string, inputs map[string]interface{}) {}),
139 )
140 },
141 expectItems: ProjectItems{},
142 },
143 }
144
145 for _, tt := range tests {
146 t.Run(tt.name, func(t *testing.T) {
147 reg := &httpmock.Registry{}
148 defer reg.Verify(t)
149 if tt.httpStubs != nil {
150 tt.httpStubs(reg)
151 }
152 client := newTestClient(reg)
153 repo, _ := ghrepo.FromFullName("OWNER/REPO")
154 issue := &Issue{Number: 1}
155 err := ProjectsV2ItemsForIssue(client, repo, issue)

Callers

nothing calls this directly

Calls 10

RegisterMethod · 0.95
VerifyMethod · 0.95
GraphQLFunction · 0.92
GraphQLQueryFunction · 0.92
FromFullNameFunction · 0.92
newTestClientFunction · 0.85
ProjectsV2ItemsForIssueFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected