@@ -256,7 +256,6 @@ describe('proxy chain', function () {
256
256
setAutoApproval : sinon . stub ( ) ,
257
257
repoName : 'test-repo' ,
258
258
commitTo : 'newCommitHash' ,
259
- autoApproved : false ,
260
259
} ;
261
260
262
261
mockPreProcessors . parseAction . resolves ( action ) ;
@@ -290,7 +289,52 @@ describe('proxy chain', function () {
290
289
expect ( result . continue ) . to . be . a ( 'function' ) ;
291
290
292
291
expect ( dbStub . calledOnce ) . to . be . true ;
293
- expect ( dbStub . calledWith ( action . id , sinon . match ( { autoApproved : true } ) ) ) . to . be . true ;
292
+
293
+ dbStub . restore ( ) ;
294
+ } ) ;
295
+
296
+ it ( 'should reject push automatically and record in the database' , async function ( ) {
297
+ const req = { } ;
298
+ const action = {
299
+ type : 'push' ,
300
+ continue : ( ) => true ,
301
+ allowPush : false ,
302
+ setAutoRejection : sinon . stub ( ) ,
303
+ repoName : 'test-repo' ,
304
+ commitTo : 'newCommitHash' ,
305
+ } ;
306
+
307
+ mockPreProcessors . parseAction . resolves ( action ) ;
308
+ mockPushProcessors . parsePush . resolves ( action ) ;
309
+ mockPushProcessors . checkRepoInAuthorisedList . resolves ( action ) ;
310
+ mockPushProcessors . checkCommitMessages . resolves ( action ) ;
311
+ mockPushProcessors . checkAuthorEmails . resolves ( action ) ;
312
+ mockPushProcessors . checkUserPushPermission . resolves ( action ) ;
313
+ mockPushProcessors . checkIfWaitingAuth . resolves ( action ) ;
314
+ mockPushProcessors . pullRemote . resolves ( action ) ;
315
+ mockPushProcessors . writePack . resolves ( action ) ;
316
+
317
+ mockPushProcessors . preReceive . resolves ( {
318
+ ...action ,
319
+ steps : [ { error : false , logs : [ 'Push automatically rejected by pre-receive hook.' ] } ] ,
320
+ allowPush : true ,
321
+ autoRejected : true ,
322
+ } ) ;
323
+
324
+ mockPushProcessors . getDiff . resolves ( action ) ;
325
+ mockPushProcessors . clearBareClone . resolves ( action ) ;
326
+ mockPushProcessors . scanDiff . resolves ( action ) ;
327
+ mockPushProcessors . blockForAuth . resolves ( action ) ;
328
+
329
+ const dbStub = sinon . stub ( db , 'reject' ) . resolves ( true ) ;
330
+
331
+ const result = await chain . executeChain ( req ) ;
332
+
333
+ expect ( result . type ) . to . equal ( 'push' ) ;
334
+ expect ( result . allowPush ) . to . be . true ;
335
+ expect ( result . continue ) . to . be . a ( 'function' ) ;
336
+
337
+ expect ( dbStub . calledOnce ) . to . be . true ;
294
338
295
339
dbStub . restore ( ) ;
296
340
} ) ;
0 commit comments