@@ -20,14 +20,15 @@ describe('Jenkins', () => {
20
20
const repo = 'node-auto-test' ;
21
21
const prid = 123456 ;
22
22
const crumb = 'asdf1234' ;
23
+ const dummySHA = '51ce389dc1d539216d30bba0986a8c270801d65f' ;
23
24
24
25
before ( ( ) => {
25
26
sinon . stub ( FormData . prototype , 'append' ) . callsFake ( function ( key , value ) {
26
27
assert . strictEqual ( key , 'json' ) ;
27
28
const { parameter } = JSON . parse ( value ) ;
28
29
const expectedParameters = {
29
30
CERTIFY_SAFE : 'on' ,
30
- COMMIT_SHA_CHECK : 'deadbeef' ,
31
+ COMMIT_SHA_CHECK : dummySHA ,
31
32
TARGET_GITHUB_ORG : owner ,
32
33
TARGET_REPO_NAME : repo ,
33
34
PR_ID : prid ,
@@ -42,7 +43,7 @@ describe('Jenkins', () => {
42
43
43
44
this . _validated = true ;
44
45
45
- return FormData . prototype . append . wrappedMethod . bind ( this ) ( key , value ) ;
46
+ return Reflect . apply ( FormData . prototype . append . wrappedMethod , this , arguments ) ;
46
47
} ) ;
47
48
} ) ;
48
49
@@ -55,7 +56,7 @@ describe('Jenkins', () => {
55
56
. returns ( Promise . resolve ( { crumb } ) )
56
57
} ;
57
58
58
- const jobRunner = new RunPRJob ( cli , request , owner , repo , prid , true ) ;
59
+ const jobRunner = new RunPRJob ( cli , request , owner , repo , prid , dummySHA ) ;
59
60
assert . strictEqual ( await jobRunner . start ( ) , false ) ;
60
61
} ) ;
61
62
@@ -65,7 +66,7 @@ describe('Jenkins', () => {
65
66
json : sinon . stub ( ) . throws ( )
66
67
} ;
67
68
68
- const jobRunner = new RunPRJob ( cli , request , owner , repo , prid , true ) ;
69
+ const jobRunner = new RunPRJob ( cli , request , owner , repo , prid , dummySHA ) ;
69
70
assert . strictEqual ( await jobRunner . start ( ) , false ) ;
70
71
} ) ;
71
72
@@ -93,7 +94,7 @@ describe('Jenkins', () => {
93
94
json : sinon . stub ( ) . withArgs ( CI_CRUMB_URL )
94
95
. returns ( Promise . resolve ( { crumb } ) )
95
96
} ;
96
- const jobRunner = new RunPRJob ( cli , request , owner , repo , prid , 'deadbeef' ) ;
97
+ const jobRunner = new RunPRJob ( cli , request , owner , repo , prid , dummySHA ) ;
97
98
assert . ok ( await jobRunner . start ( ) ) ;
98
99
} ) ;
99
100
@@ -112,26 +113,56 @@ describe('Jenkins', () => {
112
113
json : sinon . stub ( ) . withArgs ( CI_CRUMB_URL )
113
114
. returns ( Promise . resolve ( { crumb } ) )
114
115
} ;
115
- const jobRunner = new RunPRJob ( cli , request , owner , repo , prid , true ) ;
116
+ const jobRunner = new RunPRJob ( cli , request , owner , repo , prid , dummySHA ) ;
116
117
assert . strictEqual ( await jobRunner . start ( ) , false ) ;
117
118
} ) ;
118
119
119
120
describe ( 'without --certify-safe flag' , { concurrency : false } , ( ) => {
121
+ before ( ( ) => {
122
+ sinon . replace ( PRData . prototype , 'getReviews' , function ( ) { } ) ;
123
+ sinon . replace ( PRData . prototype , 'getCommits' , function ( ) { } ) ;
124
+ } ) ;
120
125
afterEach ( ( ) => {
121
- sinon . restore ( ) ;
126
+ PRData . prototype . getCollaborators . restore ( ) ;
127
+ PRData . prototype . getComments . restore ( ) ;
128
+ PRChecker . prototype . getApprovedTipOfHead . restore ( ) ;
122
129
} ) ;
123
- for ( const certifySafe of [ true , false ] ) {
124
- it ( `should return ${ certifySafe } if PR checker reports it as ${
125
- certifySafe ? '' : 'potentially un'
126
- } safe`, async ( ) => {
130
+ for ( const { headIsApproved = false , collaborators = [ ] , comments = [ ] , expected } of [ {
131
+ headIsApproved : true ,
132
+ expected : true ,
133
+ } , {
134
+ headIsApproved : false ,
135
+ expected : false ,
136
+ } , {
137
+ collaborators : [ 'foo' ] ,
138
+ comments : [ { login : 'foo' } ] ,
139
+ expected : true ,
140
+ } , {
141
+ // Validates that passing full commit URL also works.
142
+ collaborators : [ 'foo' ] ,
143
+ comments : [ { login : 'foo' , body : `@nodejs-github-bot test https://github.com/nodejs/node/commit/${ dummySHA } .\n` } ] ,
144
+ expected : true ,
145
+ } , {
146
+ // Validates that non-collaborator commenting should have no effect.
147
+ collaborators : [ 'foo' ] ,
148
+ comments : [ { login : 'bar' } ] ,
149
+ expected : false ,
150
+ } ] ) {
151
+ it ( `should return ${ expected } with ${
152
+ JSON . stringify ( { headIsApproved, collaborators, comments } ) } `, async ( ) => {
127
153
const cli = new TestCLI ( ) ;
128
154
129
- sinon . replace ( PRData . prototype , 'getCollaborators' ,
130
- function ( ) { this . collaborators = [ ] ; } ) ;
131
- sinon . replace ( PRData . prototype , 'getComments' ,
132
- function ( ) { this . comments = [ ] ; } ) ;
133
- sinon . replace ( PRChecker . prototype , 'getApprovedTipOfHead' ,
134
- sinon . fake . returns ( certifySafe && 'deadbeef' ) ) ;
155
+ sinon . stub ( PRData . prototype , 'getCollaborators' ) . callsFake ( function ( ) {
156
+ this . collaborators = collaborators . map ( login => ( { login } ) ) ;
157
+ } ) ;
158
+ sinon . stub ( PRData . prototype , 'getComments' ) . callsFake ( function ( ) {
159
+ this . comments = comments . map ( ( { body, login } ) => ( {
160
+ body : body ?? `@nodejs-github-bot test ${ dummySHA } ` ,
161
+ author : { login }
162
+ } ) ) ;
163
+ } ) ;
164
+ sinon . stub ( PRChecker . prototype , 'getApprovedTipOfHead' ) . callsFake (
165
+ sinon . fake . returns ( headIsApproved && dummySHA ) ) ;
135
166
136
167
const request = {
137
168
gql : sinon . stub ( ) . returns ( {
@@ -156,7 +187,7 @@ describe('Jenkins', () => {
156
187
} ;
157
188
158
189
const jobRunner = new RunPRJob ( cli , request , owner , repo , prid , false ) ;
159
- assert . strictEqual ( await jobRunner . start ( ) , certifySafe ) ;
190
+ assert . strictEqual ( await jobRunner . start ( ) , expected ) ;
160
191
} ) ;
161
192
}
162
193
} ) ;
0 commit comments