Files
code-review/app/git.test.js
T

31 lines
873 B
JavaScript

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();
});
});