jest.mock('simple-git', () => ({ simpleGit: jest.fn() })); jest.mock('axios'); import axios from 'axios'; import { simpleGit } from 'simple-git'; import { startTaskAgent } from '../src/services/startTaskAgent'; // Stub POST create_branch (axios as any).post = jest.fn().mockResolvedValue({ data: {} }); describe('startTaskAgent without remote origin', () => { const gitMock = { status: jest.fn(), getRemotes: jest.fn(), fetch: jest.fn(), checkout: jest.fn(), pull: jest.fn(), branch: jest.fn(), checkoutBranch: jest.fn(), revparse: jest.fn(), add: jest.fn(), commit: jest.fn(), push: jest.fn(), }; beforeEach(() => { jest.clearAllMocks(); (simpleGit as jest.Mock).mockReturnValue(gitMock); }); it('throws error when no origin remote is found', async () => { process.env.GITLAB_TOKEN = 'tok'; gitMock.status.mockResolvedValue({ files: [] }); // No remotes gitMock.getRemotes.mockResolvedValue([]); // Mock axios for project fetch to proceed past project ID retrieval (axios.get as jest.Mock) .mockResolvedValueOnce({ data: { id: 123 } }) .mockResolvedValueOnce({ data: { title: 'Task Title' }, status: 200, headers: {} }); await expect( startTaskAgent({ id: '5', gitlabToken: 'tok' } as any) ).rejects.toThrow('Remote origin introuvable dans le dépôt.'); }); });