TestBaseRepoQueriesSelectDatabaseID guards the 3 queries that build the base repository. Each selection is written by hand, and a field left out of one of them is silently zero rather than an error, so the selection is asserted against the request instead of the response.
(t *testing.T)
| 139 | // of them is silently zero rather than an error, so the selection is asserted |
| 140 | // against the request instead of the response. |
| 141 | func TestBaseRepoQueriesSelectDatabaseID(t *testing.T) { |
| 142 | tests := []struct { |
| 143 | name string |
| 144 | matcher httpmock.Matcher |
| 145 | body string |
| 146 | call func(*Client) error |
| 147 | }{ |
| 148 | { |
| 149 | name: "GitHubRepo", |
| 150 | matcher: httpmock.GraphQL(`query RepositoryInfo\b`), |
| 151 | body: `{ "data": { "repository": { "id": "REPOID", "databaseId": 1234 } } }`, |
| 152 | call: func(client *Client) error { |
| 153 | _, err := GitHubRepo(client, ghrepo.New("OWNER", "REPO")) |
| 154 | return err |
| 155 | }, |
| 156 | }, |
| 157 | { |
| 158 | name: "RepoNetwork", |
| 159 | matcher: httpmock.GraphQL(`query RepositoryNetwork\b`), |
| 160 | body: `{ "data": { "repo_000": { "id": "REPOID", "databaseId": 1234 } } }`, |
| 161 | call: func(client *Client) error { |
| 162 | _, err := RepoNetwork(client, []ghrepo.Interface{ghrepo.New("OWNER", "REPO")}) |
| 163 | return err |
| 164 | }, |
| 165 | }, |
| 166 | { |
| 167 | name: "IssueRepoInfo", |
| 168 | matcher: httpmock.GraphQL(`query IssueRepositoryInfo\b`), |
| 169 | body: `{ "data": { "repository": { "id": "REPOID", "databaseId": 1234 } } }`, |
| 170 | call: func(client *Client) error { |
| 171 | _, err := IssueRepoInfo(client, ghrepo.New("OWNER", "REPO")) |
| 172 | return err |
| 173 | }, |
| 174 | }, |
| 175 | } |
| 176 | |
| 177 | for _, tt := range tests { |
| 178 | t.Run(tt.name, func(t *testing.T) { |
| 179 | httpReg := &httpmock.Registry{} |
| 180 | defer httpReg.Verify(t) |
| 181 | |
| 182 | var query string |
| 183 | httpReg.Register(tt.matcher, httpmock.GraphQLQuery(tt.body, func(q string, _ map[string]any) { |
| 184 | query = q |
| 185 | })) |
| 186 | |
| 187 | require.NoError(t, tt.call(newTestClient(httpReg))) |
| 188 | assert.Contains(t, query, "databaseId") |
| 189 | }) |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | func TestRepoNetworkUnmarshalsDatabaseID(t *testing.T) { |
| 194 | httpReg := &httpmock.Registry{} |
nothing calls this directly
no test coverage detected