Skip to content

Commit 8194897

Browse files
committed
fix: getDiff empty commitData check test
1 parent 19ae3e0 commit 8194897

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

src/proxy/processors/push-action/getDiff.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const exec = async (req: any, action: Action): Promise<Action> => {
1010
// https://stackoverflow.com/questions/40883798/how-to-get-git-diff-of-the-first-commit
1111
let commitFrom = `4b825dc642cb6eb9a060e54bf8d69288fbee4904`;
1212

13-
if (!action.commitData) {
13+
if (!action.commitData || action.commitData.length === 0) {
1414
throw new Error('No commit data found');
1515
}
1616

test/processors/getDiff.test.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,64 @@ describe('getDiff', () => {
5656
expect(result.steps[0].content).to.include('modified content');
5757
expect(result.steps[0].content).to.include('initial content');
5858
});
59+
60+
it('should get diff between commits with no changes', async () => {
61+
const action = new Action(
62+
'1234567890',
63+
'push',
64+
'POST',
65+
1234567890,
66+
'test/repo'
67+
);
68+
action.proxyGitPath = __dirname; // Temp dir parent path
69+
action.repoName = 'temp-test-repo';
70+
action.commitFrom = 'HEAD~1';
71+
action.commitTo = 'HEAD';
72+
action.commitData = [
73+
{ parent: '0000000000000000000000000000000000000000' }
74+
];
75+
76+
const result = await exec({}, action);
77+
78+
expect(result.steps[0].error).to.be.false;
79+
expect(result.steps[0].content).to.include('initial content');
80+
});
81+
82+
it('should throw an error if no commit data is provided', async () => {
83+
const action = new Action(
84+
'1234567890',
85+
'push',
86+
'POST',
87+
1234567890,
88+
'test/repo'
89+
);
90+
action.proxyGitPath = __dirname; // Temp dir parent path
91+
action.repoName = 'temp-test-repo';
92+
action.commitFrom = 'HEAD~1';
93+
action.commitTo = 'HEAD';
94+
action.commitData = [];
95+
96+
const result = await exec({}, action);
97+
expect(result.steps[0].error).to.be.true;
98+
expect(result.steps[0].errorMessage).to.contain('No commit data found');
99+
});
100+
101+
it('should throw an error if no commit data is provided', async () => {
102+
const action = new Action(
103+
'1234567890',
104+
'push',
105+
'POST',
106+
1234567890,
107+
'test/repo'
108+
);
109+
action.proxyGitPath = __dirname; // Temp dir parent path
110+
action.repoName = 'temp-test-repo';
111+
action.commitFrom = 'HEAD~1';
112+
action.commitTo = 'HEAD';
113+
action.commitData = undefined;
114+
115+
const result = await exec({}, action);
116+
expect(result.steps[0].error).to.be.true;
117+
expect(result.steps[0].errorMessage).to.contain('No commit data found');
118+
});
59119
});

0 commit comments

Comments
 (0)