X Tutup
Skip to content

Commit 9ddd50f

Browse files
committed
Add tests for pr status reviews and checks output
1 parent fd1da2f commit 9ddd50f

File tree

4 files changed

+121
-14
lines changed

4 files changed

+121
-14
lines changed

api/queries_pr.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,6 @@ func PullRequests(client *Client, ghRepo Repo, currentPRNumber int, currentPRHea
126126
Edges []struct {
127127
Node PullRequest
128128
}
129-
PageInfo struct {
130-
HasNextPage bool
131-
EndCursor string
132-
}
133129
}
134130

135131
type response struct {
@@ -207,19 +203,13 @@ func PullRequests(client *Client, ghRepo Repo, currentPRNumber int, currentPRHea
207203
...prWithReviews
208204
}
209205
}
210-
pageInfo {
211-
hasNextPage
212-
}
213206
}
214207
reviewRequested: search(query: $reviewerQuery, type: ISSUE, first: $per_page) {
215208
edges {
216209
node {
217210
...pr
218211
}
219212
}
220-
pageInfo {
221-
hasNextPage
222-
}
223213
}
224214
}
225215
`

command/pr_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,32 @@ func TestPRStatus(t *testing.T) {
9595
}
9696
}
9797

98+
func TestPRStatus_reviewsAndChecks(t *testing.T) {
99+
initBlankContext("OWNER/REPO", "blueberries")
100+
http := initFakeHTTP()
101+
102+
jsonFile, _ := os.Open("../test/fixtures/prStatusChecks.json")
103+
defer jsonFile.Close()
104+
http.StubResponse(200, jsonFile)
105+
106+
output, err := RunCommand(prStatusCmd, "pr status")
107+
if err != nil {
108+
t.Errorf("error running command `pr status`: %v", err)
109+
}
110+
111+
expected := []string{
112+
"- Checks passing - changes requested",
113+
"- Checks pending - approved",
114+
"- 1/3 checks failing - review required",
115+
}
116+
117+
for _, line := range expected {
118+
if !strings.Contains(output.String(), line) {
119+
t.Errorf("output did not contain %q: %q", line, output.String())
120+
}
121+
}
122+
}
123+
98124
func TestPRStatus_blankSlate(t *testing.T) {
99125
initBlankContext("OWNER/REPO", "blueberries")
100126
http := initFakeHTTP()

test/fixtures/prStatus.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,7 @@
2727
"headRefName": "strawberries"
2828
}
2929
}
30-
],
31-
"pageInfo": { "hasNextPage": false }
30+
]
3231
},
3332
"reviewRequested": {
3433
"edges": [
@@ -48,7 +47,6 @@
4847
"headRefName": "figs"
4948
}
5049
}
51-
],
52-
"pageInfo": { "hasNextPage": false }
50+
]
5351
}
5452
}}

test/fixtures/prStatusChecks.json

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
{
2+
"data":{
3+
"repository": {
4+
"pullRequests": {
5+
"edges": []
6+
}
7+
},
8+
"viewerCreated": {
9+
"edges": [
10+
{
11+
"node": {
12+
"number": 8,
13+
"title": "Strawberries are not actually berries",
14+
"url": "https://github.com/github/gh-cli/pull/8",
15+
"headRefName": "strawberries",
16+
"reviewDecision": "CHANGES_REQUESTED",
17+
"commits": {
18+
"nodes": [{
19+
"commit": {
20+
"statusCheckRollup": {
21+
"contexts": {
22+
"nodes": [{
23+
"state": "SUCCESS"
24+
}]
25+
}
26+
}
27+
}
28+
}]
29+
}
30+
}
31+
},
32+
{
33+
"node": {
34+
"number": 7,
35+
"title": "Bananas are berries",
36+
"url": "https://github.com/github/gh-cli/pull/7",
37+
"headRefName": "banananana",
38+
"reviewDecision": "APPROVED",
39+
"commits": {
40+
"nodes": [{
41+
"commit": {
42+
"statusCheckRollup": {
43+
"contexts": {
44+
"nodes": [{
45+
"status": "IN_PROGRESS",
46+
"conclusion": ""
47+
}]
48+
}
49+
}
50+
}
51+
}]
52+
}
53+
}
54+
},
55+
{
56+
"node": {
57+
"number": 6,
58+
"title": "Avocado is probably not a berry",
59+
"url": "https://github.com/github/gh-cli/pull/6",
60+
"headRefName": "avo",
61+
"reviewDecision": "REVIEW_REQUIRED",
62+
"commits": {
63+
"nodes": [{
64+
"commit": {
65+
"statusCheckRollup": {
66+
"contexts": {
67+
"nodes": [
68+
{
69+
"status": "IN_PROGRESS",
70+
"conclusion": ""
71+
},
72+
{
73+
"state": "FAILURE"
74+
},
75+
{
76+
"status": "COMPLETED",
77+
"conclusion": "NEUTRAL"
78+
}
79+
]
80+
}
81+
}
82+
}
83+
}]
84+
}
85+
}
86+
}
87+
]
88+
},
89+
"reviewRequested": {
90+
"edges": []
91+
}
92+
}
93+
}

0 commit comments

Comments
 (0)
X Tutup