(t *testing.T)
| 96 | } |
| 97 | |
| 98 | func 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) |
nothing calls this directly
no test coverage detected