feat: refactor commitAndPush to use GIT_ASKPASS for authentication and add tests
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
import { commitAndPush } from './git.js';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
// Mock dependencies and environment
|
||||
jest.mock('fs');
|
||||
jest.mock('child_process', () => ({
|
||||
spawnSync: jest.fn(() => ({ status: 0, stdout: '', stderr: '' }))
|
||||
}));
|
||||
|
||||
describe('commitAndPush', () => {
|
||||
const workspace = '/tmp/workspace';
|
||||
const repoDir = path.join(workspace, 'repo');
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
fs.existsSync.mockReturnValue(false);
|
||||
fs.writeFileSync.mockImplementation(() => {});
|
||||
fs.unlinkSync.mockImplementation(() => {});
|
||||
});
|
||||
|
||||
it('should clone repo and configure git', async () => {
|
||||
await expect(commitAndPush(workspace)).resolves.not.toThrow();
|
||||
});
|
||||
|
||||
it('should not clone if repo exists', async () => {
|
||||
fs.existsSync.mockReturnValue(true);
|
||||
await expect(commitAndPush(workspace)).resolves.not.toThrow();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user