Skip to content

Commit 913a057

Browse files
committed
test: add tests for actions
1 parent 583b8ed commit 913a057

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

test/testAction.test.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
const { expect } = require('chai');
2+
const sinon = require('sinon');
3+
const { Action } = require('../src/proxy/actions/Action');
4+
5+
describe('Action class - Error Handling', () => {
6+
let action;
7+
let consoleErrorStub;
8+
9+
beforeEach(() => {
10+
action = new Action('1', 'push', 'method', Date.now(), 'project/repo');
11+
consoleErrorStub = sinon.stub(console, 'error');
12+
});
13+
14+
afterEach(() => {
15+
sinon.restore();
16+
});
17+
18+
it('setAutoApproval() should log an error and return false if an error occurs', () => {
19+
action.setAutoApproval = function () {
20+
try {
21+
throw new Error('Test error');
22+
} catch (error) {
23+
console.error('Error during auto-approval:', error.message);
24+
return false;
25+
}
26+
};
27+
28+
const result = action.setAutoApproval();
29+
expect(consoleErrorStub.calledOnceWith('Error during auto-approval:', 'Test error')).to.be.true;
30+
expect(result).to.be.false;
31+
});
32+
33+
it('setAutoRejection() should log an error and return false if an error occurs', () => {
34+
action.setAutoRejection = function () {
35+
try {
36+
throw new Error('Test error');
37+
} catch (error) {
38+
console.error('Error during auto-rejection:', error.message);
39+
return false;
40+
}
41+
};
42+
43+
const result = action.setAutoRejection();
44+
expect(consoleErrorStub.calledOnceWith('Error during auto-rejection:', 'Test error')).to.be
45+
.true;
46+
expect(result).to.be.false;
47+
});
48+
});

0 commit comments

Comments
 (0)