@@ -176,39 +176,89 @@ func TestPRList_filteringAssignee(t *testing.T) {
176176 }
177177}
178178
179- func TestPRList_filteringAssigneeLabels (t * testing.T ) {
180- http := initFakeHTTP ()
181- defer http .Verify (t )
179+ func TestPRList_filteringDraft (t * testing.T ) {
180+ tests := []struct {
181+ name string
182+ cli string
183+ expectedQuery string
184+ }{
185+ {
186+ name : "draft" ,
187+ cli : "--draft" ,
188+ expectedQuery : `repo:OWNER/REPO is:pr is:open draft:true` ,
189+ },
190+ {
191+ name : "non-draft" ,
192+ cli : "--draft=false" ,
193+ expectedQuery : `repo:OWNER/REPO is:pr is:open draft:false` ,
194+ },
195+ }
182196
183- _ , err := runCommand (http , true , `-l one,two -a hubot` )
184- if err == nil && err .Error () != "multiple labels with --assignee are not supported" {
185- t .Fatal (err )
197+ for _ , test := range tests {
198+ t .Run (test .name , func (t * testing.T ) {
199+ http := initFakeHTTP ()
200+ defer http .Verify (t )
201+
202+ http .Register (
203+ httpmock .GraphQL (`query PullRequestSearch\b` ),
204+ httpmock .GraphQLQuery (`{}` , func (_ string , params map [string ]interface {}) {
205+ assert .Equal (t , test .expectedQuery , params ["q" ].(string ))
206+ }))
207+
208+ _ , err := runCommand (http , true , test .cli )
209+ if err != nil {
210+ t .Fatal (err )
211+ }
212+ })
186213 }
187214}
188215
189216func TestPRList_withInvalidLimitFlag (t * testing.T ) {
190217 http := initFakeHTTP ()
191218 defer http .Verify (t )
192-
193219 _ , err := runCommand (http , true , `--limit=0` )
194- if err == nil && err .Error () != "invalid limit: 0" {
195- t .Errorf ("error running command `issue list`: %v" , err )
196- }
220+ assert .EqualError (t , err , "invalid value for --limit: 0" )
197221}
198222
199223func TestPRList_web (t * testing.T ) {
200- http := initFakeHTTP ()
201- defer http .Verify (t )
224+ tests := []struct {
225+ name string
226+ cli string
227+ expectedBrowserURL string
228+ }{
229+ {
230+ name : "filters" ,
231+ cli : "-a peter -l bug -l docs -L 10 -s merged -B trunk" ,
232+ expectedBrowserURL : "https://github.com/OWNER/REPO/pulls?q=is%3Apr+is%3Amerged+assignee%3Apeter+label%3Abug+label%3Adocs+base%3Atrunk" ,
233+ },
234+ {
235+ name : "draft" ,
236+ cli : "--draft=true" ,
237+ expectedBrowserURL : "https://github.com/OWNER/REPO/pulls?q=is%3Apr+is%3Aopen+draft%3Atrue" ,
238+ },
239+ {
240+ name : "non-draft" ,
241+ cli : "--draft=0" ,
242+ expectedBrowserURL : "https://github.com/OWNER/REPO/pulls?q=is%3Apr+is%3Aopen+draft%3Afalse" ,
243+ },
244+ }
202245
203- _ , cmdTeardown := run .Stub ()
204- defer cmdTeardown (t )
246+ for _ , test := range tests {
247+ t .Run (test .name , func (t * testing.T ) {
248+ http := initFakeHTTP ()
249+ defer http .Verify (t )
205250
206- output , err := runCommand (http , true , "--web -a peter -l bug -l docs -L 10 -s merged -B trunk" )
207- if err != nil {
208- t .Errorf ("error running command `pr list` with `--web` flag: %v" , err )
209- }
251+ _ , cmdTeardown := run .Stub ()
252+ defer cmdTeardown (t )
210253
211- assert .Equal (t , "" , output .String ())
212- assert .Equal (t , "Opening github.com/OWNER/REPO/pulls in your browser.\n " , output .Stderr ())
213- assert .Equal (t , "https://github.com/OWNER/REPO/pulls?q=is%3Apr+is%3Amerged+assignee%3Apeter+label%3Abug+label%3Adocs+base%3Atrunk" , output .BrowsedURL )
254+ output , err := runCommand (http , true , "--web " + test .cli )
255+ if err != nil {
256+ t .Errorf ("error running command `pr list` with `--web` flag: %v" , err )
257+ }
258+
259+ assert .Equal (t , "" , output .String ())
260+ assert .Equal (t , "Opening github.com/OWNER/REPO/pulls in your browser.\n " , output .Stderr ())
261+ assert .Equal (t , test .expectedBrowserURL , output .BrowsedURL )
262+ })
263+ }
214264}
0 commit comments