Skip to content

Commit 3c4f006

Browse files
committed
Add a test for the current branch
1 parent 6db7e89 commit 3c4f006

File tree

2 files changed

+93
-0
lines changed

2 files changed

+93
-0
lines changed

command/pr_test.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,38 @@ func TestPRStatus_closedMerged(t *testing.T) {
182182
}
183183
}
184184

185+
func TestPRStatus_currentBranch_showTheMostRecentPR(t *testing.T) {
186+
initBlankContext("OWNER/REPO", "blueberries")
187+
http := initFakeHTTP()
188+
http.StubRepoResponse("OWNER", "REPO")
189+
190+
jsonFile, _ := os.Open("../test/fixtures/prStatusCurrentBranch.json")
191+
defer jsonFile.Close()
192+
http.StubResponse(200, jsonFile)
193+
194+
output, err := RunCommand(prStatusCmd, "pr status")
195+
if err != nil {
196+
t.Errorf("error running command `pr status`: %v", err)
197+
}
198+
199+
expectedLine := regexp.MustCompile(`#10 Blueberries are certainly a good fruit \[blueberries\]`)
200+
if !expectedLine.MatchString(output.String()) {
201+
t.Errorf("output did not match regexp /%s/\n> output\n%s\n", expectedLine, output)
202+
return
203+
}
204+
205+
unexpectedLines := []*regexp.Regexp{
206+
regexp.MustCompile(`#9 Blueberries are a good fruit \[blueberries\] - Merged`),
207+
regexp.MustCompile(`#8 Blueberries are probably a good fruit \[blueberries\] - Closed`),
208+
}
209+
for _, r := range unexpectedLines {
210+
if r.MatchString(output.String()) {
211+
t.Errorf("output unexpectedly match regexp /%s/\n> output\n%s\n", r, output)
212+
return
213+
}
214+
}
215+
}
216+
185217
func TestPRStatus_blankSlate(t *testing.T) {
186218
initBlankContext("OWNER/REPO", "blueberries")
187219
http := initFakeHTTP()
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"data": {
3+
"repository": {
4+
"pullRequests": {
5+
"totalCount": 3,
6+
"edges": [
7+
{
8+
"node": {
9+
"number": 10,
10+
"title": "Blueberries are certainly a good fruit",
11+
"state": "OPEN",
12+
"url": "https://github.com/PARENT/REPO/pull/10",
13+
"headRefName": "blueberries",
14+
"isDraft": false,
15+
"headRepositoryOwner": {
16+
"login": "OWNER/REPO"
17+
},
18+
"isCrossRepository": false
19+
}
20+
},
21+
{
22+
"node": {
23+
"number": 9,
24+
"title": "Blueberries are a good fruit",
25+
"state": "MERGED",
26+
"url": "https://github.com/PARENT/REPO/pull/9",
27+
"headRefName": "blueberries",
28+
"isDraft": false,
29+
"headRepositoryOwner": {
30+
"login": "OWNER/REPO"
31+
},
32+
"isCrossRepository": false
33+
}
34+
},
35+
{
36+
"node": {
37+
"number": 8,
38+
"title": "Blueberries are probably a good fruit",
39+
"state": "CLOSED",
40+
"url": "https://github.com/PARENT/REPO/pull/8",
41+
"headRefName": "blueberries",
42+
"isDraft": false,
43+
"headRepositoryOwner": {
44+
"login": "OWNER/REPO"
45+
},
46+
"isCrossRepository": false
47+
}
48+
}
49+
]
50+
}
51+
},
52+
"viewerCreated": {
53+
"totalCount": 0,
54+
"edges": []
55+
},
56+
"reviewRequested": {
57+
"totalCount": 0,
58+
"edges": []
59+
}
60+
}
61+
}

0 commit comments

Comments
 (0)