Skip to content

Commit 06be914

Browse files
committed
test: getDiff (preliminary)
1 parent b52ca15 commit 06be914

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

test/processors/getDiff.test.js

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
const path = require('path');
2+
const simpleGit = require('simple-git');
3+
const fs = require('fs');
4+
const { Action } = require('../../src/proxy/actions');
5+
const { exec } = require('../../src/proxy/processors/push-action/getDiff');
6+
7+
const chai = require('chai');
8+
const expect = chai.expect;
9+
10+
describe('getDiff', () => {
11+
let tempDir;
12+
let git;
13+
14+
before(async () => {
15+
// Create a temp repo to avoid mocking simple-git
16+
tempDir = path.join(__dirname, 'temp-test-repo');
17+
await fs.mkdir(tempDir, { recursive: true }, (err) => {
18+
if (err) {
19+
console.error(err);
20+
}
21+
});
22+
git = simpleGit(tempDir);
23+
24+
await git.init();
25+
await fs.writeFile(path.join(tempDir, 'test.txt'), 'initial content', (err) => {
26+
if (err) {
27+
console.error(err);
28+
}
29+
});
30+
await git.add('.');
31+
await git.commit('initial commit');
32+
});
33+
34+
after(async () => {
35+
await fs.rmdir(tempDir, { recursive: true }, (err) => {
36+
if (err) {
37+
console.error(err);
38+
}
39+
});
40+
});
41+
42+
it('should get diff between commits', async () => {
43+
await fs.writeFile(path.join(tempDir, 'test.txt'), 'modified content', (err) => {
44+
if (err) {
45+
console.error(err);
46+
}
47+
});
48+
await git.add('.');
49+
const commit = await git.commit('second commit');
50+
51+
const action = new Action(
52+
'1234567890',
53+
'push',
54+
'POST',
55+
1234567890,
56+
'test/repo'
57+
);
58+
action.proxyGitPath = __dirname; // Temp dir parent path
59+
action.repoName = 'temp-test-repo';
60+
action.commitFrom = 'HEAD~1';
61+
action.commitTo = 'HEAD';
62+
action.commitData = [
63+
{ parent: '0000000000000000000000000000000000000000' }
64+
];
65+
66+
const result = await exec({}, action);
67+
68+
expect(result.steps[0].error).to.be.false;
69+
expect(result.steps[0].content).to.include('modified content');
70+
});
71+
});

0 commit comments

Comments
 (0)