44 "bytes"
55 "encoding/json"
66 "io/ioutil"
7- "os"
87 "os/exec"
98 "regexp"
109 "strings"
@@ -14,19 +13,19 @@ import (
1413 "github.com/cli/cli/pkg/httpmock"
1514 "github.com/cli/cli/test"
1615 "github.com/google/go-cmp/cmp"
16+ "github.com/stretchr/testify/assert"
1717)
1818
1919func TestIssueStatus (t * testing.T ) {
2020 initBlankContext ("" , "OWNER/REPO" , "master" )
2121 http := initFakeHTTP ()
2222 http .StubRepoResponse ("OWNER" , "REPO" )
2323 http .Register (
24- httpmock .GraphQL (`\bviewer \b` ),
24+ httpmock .GraphQL (`query UserCurrent \b` ),
2525 httpmock .StringResponse (`{"data":{"viewer":{"login":"octocat"}}}` ))
26-
27- jsonFile , _ := os .Open ("../test/fixtures/issueStatus.json" )
28- defer jsonFile .Close ()
29- http .StubResponse (200 , jsonFile )
26+ http .Register (
27+ httpmock .GraphQL (`query IssueStatus\b` ),
28+ httpmock .FileResponse ("../test/fixtures/issueStatus.json" ))
3029
3130 output , err := RunCommand ("issue status" )
3231 if err != nil {
@@ -53,17 +52,17 @@ func TestIssueStatus_blankSlate(t *testing.T) {
5352 http := initFakeHTTP ()
5453 http .StubRepoResponse ("OWNER" , "REPO" )
5554 http .Register (
56- httpmock .GraphQL (`\bviewer \b` ),
55+ httpmock .GraphQL (`query UserCurrent \b` ),
5756 httpmock .StringResponse (`{"data":{"viewer":{"login":"octocat"}}}` ))
58-
59- http . StubResponse ( 200 , bytes . NewBufferString ( `
60- { "data": { "repository": {
61- "hasIssuesEnabled ": true,
62- "assigned ": { "nodes": [] } ,
63- "mentioned ": { "nodes": [] },
64- "authored ": { "nodes": [] }
65- } } }
66- ` ))
57+ http . Register (
58+ httpmock . GraphQL ( `query IssueStatus\b` ),
59+ httpmock . StringResponse ( `
60+ { "data ": { "repository": {
61+ "hasIssuesEnabled ": true ,
62+ "assigned ": { "nodes": [] },
63+ "mentioned ": { "nodes": [] },
64+ "authored": { "nodes": [] }
65+ } } } ` ))
6766
6867 output , err := RunCommand ("issue status" )
6968 if err != nil {
@@ -93,14 +92,14 @@ func TestIssueStatus_disabledIssues(t *testing.T) {
9392 http := initFakeHTTP ()
9493 http .StubRepoResponse ("OWNER" , "REPO" )
9594 http .Register (
96- httpmock .GraphQL (`\bviewer \b` ),
95+ httpmock .GraphQL (`query UserCurrent \b` ),
9796 httpmock .StringResponse (`{"data":{"viewer":{"login":"octocat"}}}` ))
98-
99- http . StubResponse ( 200 , bytes . NewBufferString ( `
100- { "data": { "repository": {
101- "hasIssuesEnabled ": false
102- } } }
103- ` ))
97+ http . Register (
98+ httpmock . GraphQL ( `query IssueStatus\b` ),
99+ httpmock . StringResponse ( `
100+ { "data ": { "repository": {
101+ "hasIssuesEnabled": false
102+ } } } ` ))
104103
105104 _ , err := RunCommand ("issue status" )
106105 if err == nil || err .Error () != "the 'OWNER/REPO' repository has disabled issues" {
@@ -112,10 +111,9 @@ func TestIssueList(t *testing.T) {
112111 initBlankContext ("" , "OWNER/REPO" , "master" )
113112 http := initFakeHTTP ()
114113 http .StubRepoResponse ("OWNER" , "REPO" )
115-
116- jsonFile , _ := os .Open ("../test/fixtures/issueList.json" )
117- defer jsonFile .Close ()
118- http .StubResponse (200 , jsonFile )
114+ http .Register (
115+ httpmock .GraphQL (`query IssueList\b` ),
116+ httpmock .FileResponse ("../test/fixtures/issueList.json" ))
119117
120118 output , err := RunCommand ("issue list" )
121119 if err != nil {
@@ -145,13 +143,20 @@ func TestIssueList_withFlags(t *testing.T) {
145143 initBlankContext ("" , "OWNER/REPO" , "master" )
146144 http := initFakeHTTP ()
147145 http .StubRepoResponse ("OWNER" , "REPO" )
148-
149- http .StubResponse (200 , bytes .NewBufferString (`
150- { "data": { "repository": {
151- "hasIssuesEnabled": true,
152- "issues": { "nodes": [] }
153- } } }
154- ` ))
146+ http .Register (
147+ httpmock .GraphQL (`query IssueList\b` ),
148+ httpmock .GraphQLQuery (`
149+ { "data": { "repository": {
150+ "hasIssuesEnabled": true,
151+ "issues": { "nodes": [] }
152+ } } }` , func (_ string , params map [string ]interface {}) {
153+ assert .Equal (t , "probablyCher" , params ["assignee" ].(string ))
154+ assert .Equal (t , "foo" , params ["author" ].(string ))
155+ assert .Equal (t , "me" , params ["mention" ].(string ))
156+ assert .Equal (t , "1.x" , params ["milestone" ].(string ))
157+ assert .Equal (t , []interface {}{"web" , "bug" }, params ["labels" ].([]interface {}))
158+ assert .Equal (t , []interface {}{"OPEN" }, params ["states" ].([]interface {}))
159+ }))
155160
156161 output , err := RunCommand ("issue list -a probablyCher -l web,bug -s open -A foo --mention me --milestone 1.x" )
157162 if err != nil {
@@ -163,26 +168,6 @@ func TestIssueList_withFlags(t *testing.T) {
163168No issues match your search in OWNER/REPO
164169
165170` )
166-
167- bodyBytes , _ := ioutil .ReadAll (http .Requests [1 ].Body )
168- reqBody := struct {
169- Variables struct {
170- Assignee string
171- Labels []string
172- States []string
173- Author string
174- Mention string
175- Milestone string
176- }
177- }{}
178- _ = json .Unmarshal (bodyBytes , & reqBody )
179-
180- eq (t , reqBody .Variables .Assignee , "probablyCher" )
181- eq (t , reqBody .Variables .Labels , []string {"web" , "bug" })
182- eq (t , reqBody .Variables .States , []string {"OPEN" })
183- eq (t , reqBody .Variables .Author , "foo" )
184- eq (t , reqBody .Variables .Mention , "me" )
185- eq (t , reqBody .Variables .Milestone , "1.x" )
186171}
187172
188173func TestIssueList_withInvalidLimitFlag (t * testing.T ) {
@@ -371,10 +356,7 @@ func TestIssueView_Preview(t *testing.T) {
371356 initBlankContext ("" , "OWNER/REPO" , tc .ownerRepo )
372357 http := initFakeHTTP ()
373358 http .StubRepoResponse ("OWNER" , "REPO" )
374-
375- jsonFile , _ := os .Open (tc .fixture )
376- defer jsonFile .Close ()
377- http .StubResponse (200 , jsonFile )
359+ http .Register (httpmock .GraphQL (`query IssueByNumber\b` ), httpmock .FileResponse (tc .fixture ))
378360
379361 output , err := RunCommand (tc .command )
380362 if err != nil {
@@ -513,10 +495,10 @@ func TestIssueCreate_metadata(t *testing.T) {
513495 defer http .Verify (t )
514496
515497 http .Register (
516- httpmock .GraphQL (`\bviewerPermission \b` ),
498+ httpmock .GraphQL (`query RepositoryNetwork \b` ),
517499 httpmock .StringResponse (httpmock .RepoNetworkStubResponse ("OWNER" , "REPO" , "master" , "WRITE" )))
518500 http .Register (
519- httpmock .GraphQL (`\bhasIssuesEnabled \b` ),
501+ httpmock .GraphQL (`query RepositoryInfo \b` ),
520502 httpmock .StringResponse (`
521503 { "data": { "repository": {
522504 "id": "REPOID",
@@ -525,7 +507,7 @@ func TestIssueCreate_metadata(t *testing.T) {
525507 } } }
526508 ` ))
527509 http .Register (
528- httpmock .GraphQL (`\bu000: ` ),
510+ httpmock .GraphQL (`query RepositoryResolveMetadataIDs\b ` ),
529511 httpmock .StringResponse (`
530512 { "data": {
531513 "u000": { "login": "MonaLisa", "id": "MONAID" },
@@ -536,7 +518,7 @@ func TestIssueCreate_metadata(t *testing.T) {
536518 } }
537519 ` ))
538520 http .Register (
539- httpmock .GraphQL (`\bmilestones\( ` ),
521+ httpmock .GraphQL (`query RepositoryMilestoneList\b ` ),
540522 httpmock .StringResponse (`
541523 { "data": { "repository": { "milestones": {
542524 "nodes": [
@@ -547,7 +529,7 @@ func TestIssueCreate_metadata(t *testing.T) {
547529 } } } }
548530 ` ))
549531 http .Register (
550- httpmock .GraphQL (`\brepository\(.+\bprojects\( ` ),
532+ httpmock .GraphQL (`query RepositoryProjectList\b ` ),
551533 httpmock .StringResponse (`
552534 { "data": { "repository": { "projects": {
553535 "nodes": [
@@ -558,7 +540,7 @@ func TestIssueCreate_metadata(t *testing.T) {
558540 } } } }
559541 ` ))
560542 http .Register (
561- httpmock .GraphQL (`\borganization\(.+\bprojects\( ` ),
543+ httpmock .GraphQL (`query OrganizationProjectList\b ` ),
562544 httpmock .StringResponse (`
563545 { "data": { "organization": null },
564546 "errors": [{
@@ -569,7 +551,7 @@ func TestIssueCreate_metadata(t *testing.T) {
569551 }
570552 ` ))
571553 http .Register (
572- httpmock .GraphQL (`\bcreateIssue\( ` ),
554+ httpmock .GraphQL (`mutation IssueCreate\b ` ),
573555 httpmock .GraphQLMutation (`
574556 { "data": { "createIssue": { "issue": {
575557 "URL": "https://github.com/OWNER/REPO/issues/12"
0 commit comments