import { describe, it, expect, vi, beforeEach } from 'vitest'; import { createProjectCommand } from '../../src/commands/project.js'; import type { ApiClient } from '../../src/api-client.js'; function mockClient(): ApiClient { return { get: vi.fn(async () => []), post: vi.fn(async () => ({ id: 'proj-1', name: 'my-project' })), put: vi.fn(async () => ({})), delete: vi.fn(async () => {}), } as unknown as ApiClient; } describe('project command', () => { let client: ReturnType; let output: string[]; const log = (...args: unknown[]) => output.push(args.map(String).join(' ')); beforeEach(() => { client = mockClient(); output = []; }); describe('profiles', () => { it('lists profiles for a project', async () => { vi.mocked(client.get).mockResolvedValue([ { id: 'prof-1', name: 'default', serverId: 'srv-1' }, ]); const cmd = createProjectCommand({ client, log }); await cmd.parseAsync(['profiles', 'proj-1'], { from: 'user' }); expect(client.get).toHaveBeenCalledWith('/api/v1/projects/proj-1/profiles'); expect(output.join('\n')).toContain('default'); }); it('shows empty message when no profiles', async () => { const cmd = createProjectCommand({ client, log }); await cmd.parseAsync(['profiles', 'proj-1'], { from: 'user' }); expect(output.join('\n')).toContain('No profiles assigned'); }); }); describe('set-profiles', () => { it('sets profiles for a project', async () => { const cmd = createProjectCommand({ client, log }); await cmd.parseAsync(['set-profiles', 'proj-1', 'prof-1', 'prof-2'], { from: 'user' }); expect(client.put).toHaveBeenCalledWith('/api/v1/projects/proj-1/profiles', { profileIds: ['prof-1', 'prof-2'], }); expect(output.join('\n')).toContain('2 profile(s)'); }); }); });