import { describe, it, expect, vi, beforeAll } from 'vitest'; import { createCli } from '../src/cli'; import { addCommands } from '../src/commands'; import { UuidServiceImpl, InvalidArgumentTypeError } from '../src/modules/uuid'; import { Cli } from '../src/packages/cli-wrapper'; vi.mock('process'); describe('blah', () => { let cli: Cli; beforeAll(() => { cli = createCli({ name: 'cli-test', logger: false, }); addCommands(cli); }); it('returns result when successful', async () => { const response = await cli.test().run(['uuid', 'username']); expect(response.exitCode).toBe(0); }); it('returns error when given invalid inputs', async () => { vi.spyOn(UuidServiceImpl.prototype, 'getUsernameUuid').mockImplementationOnce(() => { throw new InvalidArgumentTypeError('Invalid input'); }); const response = await cli.test().run(['uuid', 'username']); expect(response.exitCode).toBe(-1); }); it('returns error when an unexpected error occurs', async () => { vi.spyOn(UuidServiceImpl.prototype, 'getUsernameUuid').mockImplementationOnce(() => { throw new Error('Unexpected error'); }); const response = await cli.test().run(['uuid', 'username']); expect(response.exitCode).toBe(-3); }); it('returns error when given insufficient arguments', async () => { const response = await cli.test().run(['uuid']); expect(response.exitCode).toBe(-1); }); describe('on interactive mode', () => { it('prompts values for insufficient arguments', async () => { const response = await cli .test() .promptValue({ username: 'username', }) .run(['uuid', '-i']); expect(response.exitCode).not.toBe(-1); }); }); });