|
9 | 9 |
|
10 | 10 | "github.com/cli/cli/context" |
11 | 11 | "github.com/cli/cli/git" |
| 12 | + "github.com/cli/cli/pkg/httpmock" |
12 | 13 | "github.com/cli/cli/test" |
13 | 14 | ) |
14 | 15 |
|
@@ -408,20 +409,27 @@ func TestPRCreate_survey_defaults_multicommit(t *testing.T) { |
408 | 409 | func TestPRCreate_survey_defaults_monocommit(t *testing.T) { |
409 | 410 | initBlankContext("", "OWNER/REPO", "feature") |
410 | 411 | http := initFakeHTTP() |
411 | | - http.StubRepoResponse("OWNER", "REPO") |
412 | | - http.StubResponse(200, bytes.NewBufferString(` |
413 | | - { "data": { "repository": { "forks": { "nodes": [ |
414 | | - ] } } } } |
| 412 | + defer http.Verify(t) |
| 413 | + http.Register(httpmock.GraphQL(`\bviewerPermission\b`), httpmock.StringResponse(httpmock.RepoNetworkStubResponse("OWNER", "REPO", "master", "WRITE"))) |
| 414 | + http.Register(httpmock.GraphQL(`\bforks\(`), httpmock.StringResponse(` |
| 415 | + { "data": { "repository": { "forks": { "nodes": [ |
| 416 | + ] } } } } |
415 | 417 | `)) |
416 | | - http.StubResponse(200, bytes.NewBufferString(` |
| 418 | + http.Register(httpmock.GraphQL(`\bpullRequests\(`), httpmock.StringResponse(` |
417 | 419 | { "data": { "repository": { "pullRequests": { "nodes" : [ |
418 | 420 | ] } } } } |
419 | 421 | `)) |
420 | | - http.StubResponse(200, bytes.NewBufferString(` |
| 422 | + http.Register(httpmock.GraphQL(`\bcreatePullRequest\(`), httpmock.GraphQLMutation(` |
421 | 423 | { "data": { "createPullRequest": { "pullRequest": { |
422 | 424 | "URL": "https://github.com/OWNER/REPO/pull/12" |
423 | 425 | } } } } |
424 | | - `)) |
| 426 | + `, func(inputs map[string]interface{}) { |
| 427 | + eq(t, inputs["repositoryId"], "REPOID") |
| 428 | + eq(t, inputs["title"], "the sky above the port") |
| 429 | + eq(t, inputs["body"], "was the color of a television, turned to a dead channel") |
| 430 | + eq(t, inputs["baseRefName"], "master") |
| 431 | + eq(t, inputs["headRefName"], "feature") |
| 432 | + })) |
425 | 433 |
|
426 | 434 | cs, cmdTeardown := test.InitCmdStubber() |
427 | 435 | defer cmdTeardown() |
@@ -456,29 +464,6 @@ func TestPRCreate_survey_defaults_monocommit(t *testing.T) { |
456 | 464 |
|
457 | 465 | output, err := RunCommand(`pr create`) |
458 | 466 | eq(t, err, nil) |
459 | | - |
460 | | - bodyBytes, _ := ioutil.ReadAll(http.Requests[3].Body) |
461 | | - reqBody := struct { |
462 | | - Variables struct { |
463 | | - Input struct { |
464 | | - RepositoryID string |
465 | | - Title string |
466 | | - Body string |
467 | | - BaseRefName string |
468 | | - HeadRefName string |
469 | | - } |
470 | | - } |
471 | | - }{} |
472 | | - _ = json.Unmarshal(bodyBytes, &reqBody) |
473 | | - |
474 | | - expectedBody := "was the color of a television, turned to a dead channel" |
475 | | - |
476 | | - eq(t, reqBody.Variables.Input.RepositoryID, "REPOID") |
477 | | - eq(t, reqBody.Variables.Input.Title, "the sky above the port") |
478 | | - eq(t, reqBody.Variables.Input.Body, expectedBody) |
479 | | - eq(t, reqBody.Variables.Input.BaseRefName, "master") |
480 | | - eq(t, reqBody.Variables.Input.HeadRefName, "feature") |
481 | | - |
482 | 467 | eq(t, output.String(), "https://github.com/OWNER/REPO/pull/12\n") |
483 | 468 | } |
484 | 469 |
|
|
0 commit comments