import { Command } from 'commander'; import * as sendModule from '../src/services/sendTaskAgent'; describe('sendTaskAgent CLI', () => { const { cli } = sendModule; beforeEach(() => jest.clearAllMocks()); it('exposes correct command and description', () => { expect(cli.command).toBe('send-task'); expect(cli.description).toMatch(/Crée et push/); }); it('builder registers argument and options', () => { const cmd = new Command(); cli.builder(cmd); // Argument 'id' const argsMeta = (cmd as any)._args as Array<{ _name: string }>; expect(argsMeta).toHaveLength(1); expect(argsMeta[0]._name).toBe('id'); // Options const longs = cmd.options.map((o) => o.long); expect(longs).toEqual( expect.arrayContaining([ '--targetBranch', '--repoPath', '--gitlabToken', '--gitlabUrl', '--workDir', '--teleportToken', ]) ); }); it('handler calls sendTaskAgent and logs result', async () => { const fakeResult = { mrIid: 7, branch: 'b', commitSha: 'c', webUrl: 'u' }; const spySend = jest.spyOn(sendModule, 'sendTaskAgent').mockResolvedValue(fakeResult as any); const logSpy = jest.spyOn(console, 'log').mockImplementation(() => {}); const opts = { targetBranch: 'dev', repoPath: '/repo', gitlabToken: 'tok', gitlabUrl: 'url', workDir: 'wd', teleportToken: 'jt', }; await cli.handler('42', opts); expect(spySend).toHaveBeenCalledWith({ id: '42', ...opts }); expect(logSpy).toHaveBeenCalledWith( `MR créée: !${fakeResult.mrIid} (${fakeResult.webUrl}), branche ${fakeResult.branch} à ${fakeResult.commitSha}` ); logSpy.mockRestore(); }); });