Skip to content

Commit 5a23113

Browse files
committed
Add tests for the Closed/Merged PR preview
1 parent 8cd6932 commit 5a23113

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed

command/pr_test.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,66 @@ func TestPRView_preview(t *testing.T) {
411411
}
412412
}
413413

414+
func TestPRView_previewClosedState(t *testing.T) {
415+
initBlankContext("OWNER/REPO", "master")
416+
http := initFakeHTTP()
417+
http.StubRepoResponse("OWNER", "REPO")
418+
419+
jsonFile, _ := os.Open("../test/fixtures/prViewPreviewClosedState.json")
420+
defer jsonFile.Close()
421+
http.StubResponse(200, jsonFile)
422+
423+
output, err := RunCommand(prViewCmd, "pr view -p 12")
424+
if err != nil {
425+
t.Errorf("error running command `pr view`: %v", err)
426+
}
427+
428+
eq(t, output.Stderr(), "")
429+
430+
expectedLines := []*regexp.Regexp{
431+
regexp.MustCompile(`Blueberries are from a fork`),
432+
regexp.MustCompile(`CLOSED • nobody wants to merge 12 commits into master from blueberries`),
433+
regexp.MustCompile(`blueberries taste good`),
434+
regexp.MustCompile(`View this pull request on GitHub: https://github.com/OWNER/REPO/pull/12`),
435+
}
436+
for _, r := range expectedLines {
437+
if !r.MatchString(output.String()) {
438+
t.Errorf("output did not match regexp /%s/\n> output\n%s\n", r, output)
439+
return
440+
}
441+
}
442+
}
443+
444+
func TestPRView_previewMergedState(t *testing.T) {
445+
initBlankContext("OWNER/REPO", "master")
446+
http := initFakeHTTP()
447+
http.StubRepoResponse("OWNER", "REPO")
448+
449+
jsonFile, _ := os.Open("../test/fixtures/prViewPreviewMergedState.json")
450+
defer jsonFile.Close()
451+
http.StubResponse(200, jsonFile)
452+
453+
output, err := RunCommand(prViewCmd, "pr view -p 12")
454+
if err != nil {
455+
t.Errorf("error running command `pr view`: %v", err)
456+
}
457+
458+
eq(t, output.Stderr(), "")
459+
460+
expectedLines := []*regexp.Regexp{
461+
regexp.MustCompile(`Blueberries are from a fork`),
462+
regexp.MustCompile(`MERGED • nobody wants to merge 12 commits into master from blueberries`),
463+
regexp.MustCompile(`blueberries taste good`),
464+
regexp.MustCompile(`View this pull request on GitHub: https://github.com/OWNER/REPO/pull/12`),
465+
}
466+
for _, r := range expectedLines {
467+
if !r.MatchString(output.String()) {
468+
t.Errorf("output did not match regexp /%s/\n> output\n%s\n", r, output)
469+
return
470+
}
471+
}
472+
}
473+
414474
func TestPRView_previewCurrentBranch(t *testing.T) {
415475
initBlankContext("OWNER/REPO", "blueberries")
416476
http := initFakeHTTP()
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"data": {
3+
"repository": {
4+
"pullRequest": {
5+
"number": 12,
6+
"title": "Blueberries are from a fork",
7+
"state": "CLOSED",
8+
"body": "**blueberries taste good**",
9+
"url": "https://github.com/OWNER/REPO/pull/12",
10+
"author": {
11+
"login": "nobody"
12+
},
13+
"commits": {
14+
"totalCount": 12
15+
},
16+
"baseRefName": "master",
17+
"headRefName": "blueberries",
18+
"headRepositoryOwner": {
19+
"login": "hubot"
20+
},
21+
"isCrossRepository": true
22+
}
23+
}
24+
}
25+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"data": {
3+
"repository": {
4+
"pullRequest": {
5+
"number": 12,
6+
"title": "Blueberries are from a fork",
7+
"state": "MERGED",
8+
"body": "**blueberries taste good**",
9+
"url": "https://github.com/OWNER/REPO/pull/12",
10+
"author": {
11+
"login": "nobody"
12+
},
13+
"commits": {
14+
"totalCount": 12
15+
},
16+
"baseRefName": "master",
17+
"headRefName": "blueberries",
18+
"headRepositoryOwner": {
19+
"login": "hubot"
20+
},
21+
"isCrossRepository": true
22+
}
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)