Skip to content

Commit d2174d2

Browse files
committed
feat: add test for auto rejection
1 parent f723307 commit d2174d2

File tree

1 file changed

+46
-2
lines changed

1 file changed

+46
-2
lines changed

test/chain.test.js

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,6 @@ describe('proxy chain', function () {
256256
setAutoApproval: sinon.stub(),
257257
repoName: 'test-repo',
258258
commitTo: 'newCommitHash',
259-
autoApproved: false,
260259
};
261260

262261
mockPreProcessors.parseAction.resolves(action);
@@ -290,7 +289,52 @@ describe('proxy chain', function () {
290289
expect(result.continue).to.be.a('function');
291290

292291
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;
294338

295339
dbStub.restore();
296340
});

0 commit comments

Comments
 (0)