import { Command } from 'commander'; import * as saModule from '../src/services/qualimetrie/securityAgent'; // Mock securityAgent to control CLI jest.mock('../src/services/qualimetrie/securityAgent', () => ({ ...jest.requireActual('../src/services/qualimetrie/securityAgent'), securityAgent: jest.fn(), })); const { cli, securityAgent } = saModule; describe('securityAgent CLI', () => { beforeEach(() => jest.clearAllMocks()); it('exposes correct command and description', () => { expect(cli.command).toBe('qualimetrie:security'); expect(cli.description).toMatch(/vulnérabilités/); }); it('builder returns the same command', () => { const cmd = new Command(); expect(cli.builder(cmd)).toBe(cmd); }); it('handler logs securityAgent result', async () => { const fakeRes = { vulnerabilities: ['v1'] }; (securityAgent as jest.Mock).mockResolvedValue(fakeRes); const logSpy = jest.spyOn(console, 'log').mockImplementation(() => {}); await cli.handler(undefined); expect(securityAgent).toHaveBeenCalled(); expect(logSpy).toHaveBeenCalledWith(fakeRes); logSpy.mockRestore(); }); });