diff --git a/command/pr_test.go b/command/pr_test.go index 3fd4d9e9b..c2199013d 100644 --- a/command/pr_test.go +++ b/command/pr_test.go @@ -156,33 +156,6 @@ func TestPRStatus_reviewsAndChecks(t *testing.T) { } } -func TestPRStatus_closedMerged(t *testing.T) { - initBlankContext("OWNER/REPO", "blueberries") - http := initFakeHTTP() - http.StubRepoResponse("OWNER", "REPO") - - jsonFile, _ := os.Open("../test/fixtures/prStatusClosedMerged.json") - defer jsonFile.Close() - http.StubResponse(200, jsonFile) - - output, err := RunCommand(prStatusCmd, "pr status") - if err != nil { - t.Errorf("error running command `pr status`: %v", err) - } - - expected := []string{ - "- Checks passing - Changes requested", - "- Closed", - "- Merged", - } - - for _, line := range expected { - if !strings.Contains(output.String(), line) { - t.Errorf("output did not contain %q: %q", line, output.String()) - } - } -} - func TestPRStatus_currentBranch_showTheMostRecentPR(t *testing.T) { initBlankContext("OWNER/REPO", "blueberries") http := initFakeHTTP() @@ -215,6 +188,48 @@ func TestPRStatus_currentBranch_showTheMostRecentPR(t *testing.T) { } } +func TestPRStatus_currentBranch_Closed(t *testing.T) { + initBlankContext("OWNER/REPO", "blueberries") + http := initFakeHTTP() + http.StubRepoResponse("OWNER", "REPO") + + jsonFile, _ := os.Open("../test/fixtures/prStatusCurrentBranchClosed.json") + defer jsonFile.Close() + http.StubResponse(200, jsonFile) + + output, err := RunCommand(prStatusCmd, "pr status") + if err != nil { + t.Errorf("error running command `pr status`: %v", err) + } + + expectedLine := regexp.MustCompile(`#8 Blueberries are a good fruit \[blueberries\] - Closed`) + if !expectedLine.MatchString(output.String()) { + t.Errorf("output did not match regexp /%s/\n> output\n%s\n", expectedLine, output) + return + } +} + +func TestPRStatus_currentBranch_Merged(t *testing.T) { + initBlankContext("OWNER/REPO", "blueberries") + http := initFakeHTTP() + http.StubRepoResponse("OWNER", "REPO") + + jsonFile, _ := os.Open("../test/fixtures/prStatusCurrentBranchMerged.json") + defer jsonFile.Close() + http.StubResponse(200, jsonFile) + + output, err := RunCommand(prStatusCmd, "pr status") + if err != nil { + t.Errorf("error running command `pr status`: %v", err) + } + + expectedLine := regexp.MustCompile(`#8 Blueberries are a good fruit \[blueberries\] - Merged`) + if !expectedLine.MatchString(output.String()) { + t.Errorf("output did not match regexp /%s/\n> output\n%s\n", expectedLine, output) + return + } +} + func TestPRStatus_blankSlate(t *testing.T) { initBlankContext("OWNER/REPO", "blueberries") http := initFakeHTTP() diff --git a/test/fixtures/prStatusClosedMerged.json b/test/fixtures/prStatusCurrentBranchClosed.json similarity index 63% rename from test/fixtures/prStatusClosedMerged.json rename to test/fixtures/prStatusCurrentBranchClosed.json index 03e31637e..d5d366bd1 100644 --- a/test/fixtures/prStatusClosedMerged.json +++ b/test/fixtures/prStatusCurrentBranchClosed.json @@ -8,7 +8,7 @@ "node": { "number": 8, "title": "Blueberries are a good fruit", - "state": "OPEN", + "state": "CLOSED", "url": "https://github.com/cli/cli/pull/8", "headRefName": "blueberries", "reviewDecision": "CHANGES_REQUESTED", @@ -35,27 +35,8 @@ } }, "viewerCreated": { - "totalCount": 1, - "edges": [ - { - "node": { - "number": 10, - "state": "CLOSED", - "title": "Strawberries are not actually berries", - "url": "https://github.com/cli/cli/pull/10", - "headRefName": "strawberries" - } - }, - { - "node": { - "number": 9, - "state": "MERGED", - "title": "Bananas are berries", - "url": "https://github.com/cli/cli/pull/9", - "headRefName": "banananana" - } - } - ] + "totalCount": 0, + "edges": [] }, "reviewRequested": { "totalCount": 0, diff --git a/test/fixtures/prStatusCurrentBranchMerged.json b/test/fixtures/prStatusCurrentBranchMerged.json new file mode 100644 index 000000000..da54fdf64 --- /dev/null +++ b/test/fixtures/prStatusCurrentBranchMerged.json @@ -0,0 +1,46 @@ +{ + "data": { + "repository": { + "pullRequests": { + "totalCount": 1, + "edges": [ + { + "node": { + "number": 8, + "title": "Blueberries are a good fruit", + "state": "MERGED", + "url": "https://github.com/cli/cli/pull/8", + "headRefName": "blueberries", + "reviewDecision": "CHANGES_REQUESTED", + "commits": { + "nodes": [ + { + "commit": { + "statusCheckRollup": { + "contexts": { + "nodes": [ + { + "state": "SUCCESS" + } + ] + } + } + } + } + ] + } + } + } + ] + } + }, + "viewerCreated": { + "totalCount": 0, + "edges": [] + }, + "reviewRequested": { + "totalCount": 0, + "edges": [] + } + } +}