From 9ddd50ffa912109fdf78ba08f84fb607764a46d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 19 Dec 2019 17:37:57 +0100 Subject: [PATCH] Add tests for `pr status` reviews and checks output --- api/queries_pr.go | 10 ---- command/pr_test.go | 26 +++++++++ test/fixtures/prStatus.json | 6 +- test/fixtures/prStatusChecks.json | 93 +++++++++++++++++++++++++++++++ 4 files changed, 121 insertions(+), 14 deletions(-) create mode 100644 test/fixtures/prStatusChecks.json diff --git a/api/queries_pr.go b/api/queries_pr.go index 01ece0369..10572d487 100644 --- a/api/queries_pr.go +++ b/api/queries_pr.go @@ -126,10 +126,6 @@ func PullRequests(client *Client, ghRepo Repo, currentPRNumber int, currentPRHea Edges []struct { Node PullRequest } - PageInfo struct { - HasNextPage bool - EndCursor string - } } type response struct { @@ -207,9 +203,6 @@ func PullRequests(client *Client, ghRepo Repo, currentPRNumber int, currentPRHea ...prWithReviews } } - pageInfo { - hasNextPage - } } reviewRequested: search(query: $reviewerQuery, type: ISSUE, first: $per_page) { edges { @@ -217,9 +210,6 @@ func PullRequests(client *Client, ghRepo Repo, currentPRNumber int, currentPRHea ...pr } } - pageInfo { - hasNextPage - } } } ` diff --git a/command/pr_test.go b/command/pr_test.go index e73caf208..8333fb1ef 100644 --- a/command/pr_test.go +++ b/command/pr_test.go @@ -95,6 +95,32 @@ func TestPRStatus(t *testing.T) { } } +func TestPRStatus_reviewsAndChecks(t *testing.T) { + initBlankContext("OWNER/REPO", "blueberries") + http := initFakeHTTP() + + jsonFile, _ := os.Open("../test/fixtures/prStatusChecks.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", + "- Checks pending - approved", + "- 1/3 checks failing - review required", + } + + for _, line := range expected { + if !strings.Contains(output.String(), line) { + t.Errorf("output did not contain %q: %q", line, output.String()) + } + } +} + func TestPRStatus_blankSlate(t *testing.T) { initBlankContext("OWNER/REPO", "blueberries") http := initFakeHTTP() diff --git a/test/fixtures/prStatus.json b/test/fixtures/prStatus.json index f6cd8d1cd..f2b0ca5b3 100644 --- a/test/fixtures/prStatus.json +++ b/test/fixtures/prStatus.json @@ -27,8 +27,7 @@ "headRefName": "strawberries" } } - ], - "pageInfo": { "hasNextPage": false } + ] }, "reviewRequested": { "edges": [ @@ -48,7 +47,6 @@ "headRefName": "figs" } } - ], - "pageInfo": { "hasNextPage": false } + ] } }} \ No newline at end of file diff --git a/test/fixtures/prStatusChecks.json b/test/fixtures/prStatusChecks.json new file mode 100644 index 000000000..620e5267d --- /dev/null +++ b/test/fixtures/prStatusChecks.json @@ -0,0 +1,93 @@ +{ + "data":{ + "repository": { + "pullRequests": { + "edges": [] + } + }, + "viewerCreated": { + "edges": [ + { + "node": { + "number": 8, + "title": "Strawberries are not actually berries", + "url": "https://github.com/github/gh-cli/pull/8", + "headRefName": "strawberries", + "reviewDecision": "CHANGES_REQUESTED", + "commits": { + "nodes": [{ + "commit": { + "statusCheckRollup": { + "contexts": { + "nodes": [{ + "state": "SUCCESS" + }] + } + } + } + }] + } + } + }, + { + "node": { + "number": 7, + "title": "Bananas are berries", + "url": "https://github.com/github/gh-cli/pull/7", + "headRefName": "banananana", + "reviewDecision": "APPROVED", + "commits": { + "nodes": [{ + "commit": { + "statusCheckRollup": { + "contexts": { + "nodes": [{ + "status": "IN_PROGRESS", + "conclusion": "" + }] + } + } + } + }] + } + } + }, + { + "node": { + "number": 6, + "title": "Avocado is probably not a berry", + "url": "https://github.com/github/gh-cli/pull/6", + "headRefName": "avo", + "reviewDecision": "REVIEW_REQUIRED", + "commits": { + "nodes": [{ + "commit": { + "statusCheckRollup": { + "contexts": { + "nodes": [ + { + "status": "IN_PROGRESS", + "conclusion": "" + }, + { + "state": "FAILURE" + }, + { + "status": "COMPLETED", + "conclusion": "NEUTRAL" + } + ] + } + } + } + }] + } + } + } + ] + }, + "reviewRequested": { + "edges": [] + } + } +}