@@ -82,25 +82,53 @@ describe('deleteMergedBranch function', () => {
8282 } )
8383 } )
8484
85- describe ( 'branch is merged' , ( ) => {
85+ describe ( 'base not included in config' , ( ) => {
86+ it ( 'should log it didn\'t delete the branch' , async ( ) => {
87+ context . config = jest . fn ( ) . mockReturnValue ( {
88+ exclude : [ ] ,
89+ on_base : [ 'something' , 'other' , 'than' , 'the' , 'base' , 'branch' ]
90+ } )
91+ context . payload . pull_request . head . label = 'foo:bar'
92+ await deleteMergedBranch ( context )
93+ expect ( context . log . info ) . toBeCalledWith ( `Base does not match any 'on_base'. Keeping ${ context . payload . pull_request . head . label } ` )
94+ } )
95+
96+ it ( 'should NOT call the deleteReference method' , async ( ) => {
97+ context . config = jest . fn ( ) . mockReturnValue ( {
98+ exclude : [ ] ,
99+ on_base : [ 'something' , 'other' , 'than' , 'the' , 'base' , 'branch' ]
100+ } )
101+ context . payload . pull_request . head . label = 'foo:bar'
102+ await deleteMergedBranch ( context )
103+ expect ( context . github . git . deleteRef ) . not . toHaveBeenCalled ( )
104+ } )
105+ } )
106+
107+ describe . each ( [
108+ false ,
109+ true
110+ ] ) ( 'branch is merged' , ( baseExplicitlyIncluded ) => {
86111 beforeEach ( async ( ) => {
87112 context . payload . pull_request . merged = true
113+ if ( baseExplicitlyIncluded ) {
114+ context . config . on_base = [ context . payload . pull_request . base . ref ]
115+ }
88116 await deleteMergedBranch ( context )
89117 } )
90118
91- it ( 'should call the deleteReference method' , ( ) => {
119+ it ( 'should call the deleteReference method, base in on_base: ' + baseExplicitlyIncluded , ( ) => {
92120 expect ( context . github . git . deleteRef ) . toHaveBeenCalledWith ( {
93121 owner,
94122 ref : `heads/${ ref } ` ,
95123 repo
96124 } )
97125 } )
98126
99- it ( 'should log the delete' , ( ) => {
127+ it ( 'should log the delete, base in on_base: ' + baseExplicitlyIncluded , ( ) => {
100128 expect ( context . log . info ) . toBeCalledWith ( `Successfully deleted ${ owner } /${ repo } /heads/${ ref } which was merged` )
101129 } )
102130
103- describe ( 'deleteReference call fails' , ( ) => {
131+ describe ( 'deleteReference call fails, base in on_base: ' + baseExplicitlyIncluded , ( ) => {
104132 beforeEach ( async ( ) => {
105133 context . github . git . deleteRef = ''
106134 } )
0 commit comments