Skip to content

Commit c554cce

Browse files
committed
test: fix test for actions
1 parent 913a057 commit c554cce

File tree

2 files changed

+92
-48
lines changed

2 files changed

+92
-48
lines changed

test/chain.test.js

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,4 +338,96 @@ describe('proxy chain', function () {
338338

339339
dbStub.restore();
340340
});
341+
342+
it('executeChain should handle exceptions in attemptAutoApproval', async function () {
343+
const req = {};
344+
const action = {
345+
type: 'push',
346+
continue: () => true,
347+
allowPush: false,
348+
setAutoApproval: sinon.stub(),
349+
repoName: 'test-repo',
350+
commitTo: 'newCommitHash',
351+
};
352+
353+
mockPreProcessors.parseAction.resolves(action);
354+
mockPushProcessors.parsePush.resolves(action);
355+
mockPushProcessors.checkRepoInAuthorisedList.resolves(action);
356+
mockPushProcessors.checkCommitMessages.resolves(action);
357+
mockPushProcessors.checkAuthorEmails.resolves(action);
358+
mockPushProcessors.checkUserPushPermission.resolves(action);
359+
mockPushProcessors.checkIfWaitingAuth.resolves(action);
360+
mockPushProcessors.pullRemote.resolves(action);
361+
mockPushProcessors.writePack.resolves(action);
362+
363+
mockPushProcessors.preReceive.resolves({
364+
...action,
365+
steps: [{ error: false, logs: ['Push automatically approved by pre-receive hook.'] }],
366+
allowPush: true,
367+
autoApproved: true,
368+
});
369+
370+
mockPushProcessors.getDiff.resolves(action);
371+
mockPushProcessors.clearBareClone.resolves(action);
372+
mockPushProcessors.scanDiff.resolves(action);
373+
mockPushProcessors.blockForAuth.resolves(action);
374+
375+
const error = new Error('Database error');
376+
377+
const consoleErrorStub = sinon.stub(console, 'error');
378+
sinon.stub(db, 'authorise').rejects(error);
379+
await chain.executeChain(req);
380+
expect(consoleErrorStub.calledOnceWith('Error during auto-approval:', error.message)).to.be
381+
.true;
382+
db.authorise.restore();
383+
consoleErrorStub.restore();
384+
});
385+
386+
it('executeChain should handle exceptions in attemptAutoRejection', async function () {
387+
const req = {};
388+
const action = {
389+
type: 'push',
390+
continue: () => true,
391+
allowPush: false,
392+
setAutoRejection: sinon.stub(),
393+
repoName: 'test-repo',
394+
commitTo: 'newCommitHash',
395+
autoRejected: true,
396+
};
397+
398+
mockPreProcessors.parseAction.resolves(action);
399+
mockPushProcessors.parsePush.resolves(action);
400+
mockPushProcessors.checkRepoInAuthorisedList.resolves(action);
401+
mockPushProcessors.checkCommitMessages.resolves(action);
402+
mockPushProcessors.checkAuthorEmails.resolves(action);
403+
mockPushProcessors.checkUserPushPermission.resolves(action);
404+
mockPushProcessors.checkIfWaitingAuth.resolves(action);
405+
mockPushProcessors.pullRemote.resolves(action);
406+
mockPushProcessors.writePack.resolves(action);
407+
408+
mockPushProcessors.preReceive.resolves({
409+
...action,
410+
steps: [{ error: false, logs: ['Push automatically rejected by pre-receive hook.'] }],
411+
allowPush: false,
412+
autoRejected: true,
413+
});
414+
415+
mockPushProcessors.getDiff.resolves(action);
416+
mockPushProcessors.clearBareClone.resolves(action);
417+
mockPushProcessors.scanDiff.resolves(action);
418+
mockPushProcessors.blockForAuth.resolves(action);
419+
420+
const error = new Error('Database error');
421+
422+
const consoleErrorStub = sinon.stub(console, 'error');
423+
sinon.stub(db, 'reject').rejects(error);
424+
425+
await chain.executeChain(req);
426+
427+
expect(consoleErrorStub.calledOnceWith('Error during auto-rejection:', error.message)).to.be
428+
.true;
429+
430+
db.reject.restore();
431+
consoleErrorStub.restore();
432+
});
341433
});

test/testAction.test.js

Lines changed: 0 additions & 48 deletions
This file was deleted.

0 commit comments

Comments
 (0)