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

Function TestPRRevert_multipleInvocations

pkg/cmd/pr/revert/revert_test.go:248–325  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

246}
247
248func TestPRRevert_multipleInvocations(t *testing.T) {
249 http := &httpmock.Registry{}
250 defer http.Verify(t)
251
252 shared.StubFinderForRunCommandStyleTests(t, "123", &api.PullRequest{
253 ID: "SOME-ID",
254 Number: 123,
255 State: "MERGED",
256 Title: "The title of the PR",
257 }, ghrepo.New("OWNER", "REPO"))
258
259 http.Register(
260 httpmock.GraphQL(`mutation PullRequestRevert\b`),
261 httpmock.GraphQLMutation(`
262 { "data": { "revertPullRequest": { "pullRequest": {
263 "ID": "SOME-ID"
264 }, "revertPullRequest": {
265 "ID": "NEW-ID",
266 "Number": 456,
267 "URL": "https://github.com/OWNER/REPO/pull/456"
268 } } } }
269 `,
270 func(inputs map[string]interface{}) {
271 assert.Equal(t, inputs["pullRequestId"], "SOME-ID")
272 }),
273 )
274
275 output, err := runCommand(http, true, "123")
276 // Revert PR is created and only its URL is printed.
277 assert.NoError(t, err)
278 assert.Equal(t, "https://github.com/OWNER/REPO/pull/456\n", output.String())
279 assert.Equal(t, "", output.Stderr())
280
281 // Invoke the same command, behavior depends solely on API response
282 shared.StubFinderForRunCommandStyleTests(t, "123", &api.PullRequest{
283 ID: "SOME-ID",
284 Number: 123,
285 State: "MERGED",
286 Title: "The title of the PR",
287 }, ghrepo.New("OWNER", "REPO"))
288
289 http.Register(
290 httpmock.GraphQL(`mutation PullRequestRevert\b`),
291 httpmock.GraphQLMutation(`
292 { "data": { "revertPullRequest": { "pullRequest": {
293 "ID": "SOME-ID"
294 }, "revertPullRequest": {
295 "ID": "NEW-ID",
296 "Number": 456,
297 "URL": "https://github.com/OWNER/REPO/pull/456"
298 } } } }
299 `,
300 func(inputs map[string]interface{}) {
301 assert.Equal(t, inputs["pullRequestId"], "SOME-ID")
302 }),
303 )
304
305 output, err = runCommand(http, true, "123")

Callers

nothing calls this directly

Calls 10

VerifyMethod · 0.95
RegisterMethod · 0.95
NewFunction · 0.92
GraphQLFunction · 0.92
GraphQLMutationFunction · 0.92
EqualMethod · 0.80
StderrMethod · 0.80
runCommandFunction · 0.70
StringMethod · 0.45

Tested by

no test coverage detected