@@ -124,30 +124,79 @@ describe('pull - routineCheck', () => {
124124
125125 test ( 'yes diff, already has PR' , async ( ) => {
126126 github . repos . compareCommits . mockResolvedValue ( { data : { total_commits : 1 } } )
127- github . search . issues . mockResolvedValue ( { data : { total_count : 1 } } )
127+ github . search . issues . mockResolvedValueOnce ( { data : { total_count : 1 , items : [ { number : 12 } ] } } )
128+ . mockResolvedValueOnce ( { data : { total_count : 1 , items : [ { number : 13 } ] } } )
129+ . mockResolvedValueOnce ( { data : { total_count : 1 , items : [ { number : 14 } ] } } )
130+ github . pullRequests . get . mockResolvedValueOnce ( {
131+ number : 12 ,
132+ base : { ref : 'master' } ,
133+ head : { ref : 'master' , label : 'upstream:master' , sha : 'sha1-placeholder-12' } ,
134+ state : 'open' ,
135+ user : { login : 'pull[bot]' } ,
136+ mergeable : true ,
137+ mergeable_state : 'clean'
138+ } ) . mockResolvedValueOnce ( {
139+ number : 13 ,
140+ base : { ref : 'feature/new-1' } ,
141+ head : { ref : 'dev' , label : 'upstream:dev' , sha : 'sha1-placeholder-13' } ,
142+ state : 'open' ,
143+ user : { login : 'pull[bot]' } ,
144+ mergeable : true ,
145+ mergeable_state : 'clean'
146+ } ) . mockResolvedValueOnce ( {
147+ number : 14 ,
148+ base : { ref : 'hotfix/bug-1' } ,
149+ head : { ref : 'dev' , label : 'upstream:dev' , sha : 'sha1-placeholder-14' } ,
150+ state : 'open' ,
151+ user : { login : 'pull[bot]' } ,
152+ mergeable : true ,
153+ mergeable_state : 'clean'
154+ } )
128155
129156 const pull = getPull ( )
130157 await pull . routineCheck ( )
131158 expect ( github . repos . compareCommits ) . nthCalledWith ( 1 , {
132159 owner : 'wei' , repo : 'fork' , base : 'master' , head : 'upstream:master'
133160 } )
161+ expect ( github . search . issues ) . toHaveBeenCalled ( )
162+ expect ( github . pullRequests . get ) . toHaveBeenCalledWith ( { owner : 'wei' , repo : 'fork' , number : 12 } )
163+ expect ( github . pullRequests . merge ) . not . toHaveBeenCalledWith ( )
164+
134165 expect ( github . repos . compareCommits ) . nthCalledWith ( 2 , {
135166 owner : 'wei' , repo : 'fork' , base : 'feature/new-1' , head : 'upstream:dev'
136167 } )
168+ expect ( github . search . issues ) . toHaveBeenCalled ( )
169+ expect ( github . pullRequests . get ) . toHaveBeenCalledWith ( { owner : 'wei' , repo : 'fork' , number : 13 } )
170+ expect ( github . pullRequests . merge ) . toHaveBeenCalledWith ( { owner : 'wei' , repo : 'fork' , number : 13 } )
171+
137172 expect ( github . repos . compareCommits ) . nthCalledWith ( 3 , {
138173 owner : 'wei' , repo : 'fork' , base : 'hotfix/bug-1' , head : 'upstream:dev'
139174 } )
140175 expect ( github . search . issues ) . toHaveBeenCalled ( )
176+ expect ( github . pullRequests . get ) . toHaveBeenCalledWith ( { owner : 'wei' , repo : 'fork' , number : 14 } )
177+ expect ( github . gitdata . updateReference ) . toHaveBeenCalledWith (
178+ { owner : 'wei' , repo : 'fork' , ref : `heads/hotfix/bug-1` , sha : 'sha1-placeholder-14' , force : true }
179+ )
180+
141181 expect ( github . pullRequests . create ) . not . toHaveBeenCalled ( )
142182 expect ( github . issues . edit ) . not . toHaveBeenCalled ( )
143183 } )
144184
145185 test ( 'yes diff, no PR, create PR' , async ( ) => {
146186 github . repos . compareCommits . mockResolvedValue ( { data : { total_commits : 1 } } )
147187 github . search . issues
148- . mockResolvedValueOnce ( { data : { total_count : 1 } } )
188+ . mockResolvedValueOnce ( { data : { total_count : 1 , items : [ { number : 10 } ] } } )
149189 . mockResolvedValueOnce ( { data : { total_count : 0 } } )
150190 . mockResolvedValueOnce ( { data : { total_count : 0 } } )
191+ github . pullRequests . get . mockResolvedValueOnce ( {
192+ number : 10 ,
193+ base : { ref : 'master' } ,
194+ head : { ref : 'master' , label : 'upstream:master' , sha : 'sha1-placeholder' } ,
195+ state : 'open' ,
196+ user : { login : 'pull[bot]' } ,
197+ mergeable : true ,
198+ mergeable_state : 'clean'
199+ } )
151200 github . pullRequests . create
152201 . mockResolvedValueOnce ( { data : { number : 12 } } )
153202 . mockResolvedValueOnce ( { data : { number : 16 } } )
0 commit comments