|
| 1 | +import { describe, expect, it } from 'vitest' |
| 2 | +import { runEmbeddedCli } from '../embed' |
| 3 | + |
| 4 | +const identity = { endpoint: 'https://sim.test', apiKey: 'fixture', workspaceId: 'workspace' } |
| 5 | + |
| 6 | +/** Runs one embedded invocation, recording each request body it sends. */ |
| 7 | +async function run(argv: string[]) { |
| 8 | + const bodies: unknown[] = [] |
| 9 | + const result = await runEmbeddedCli(argv, { |
| 10 | + ...identity, |
| 11 | + transport: async (_url, init) => { |
| 12 | + bodies.push(JSON.parse(String(init?.body))) |
| 13 | + return Response.json({ data: { deletedItems: { files: 2 } } }) |
| 14 | + }, |
| 15 | + }) |
| 16 | + return { ...result, bodies } |
| 17 | +} |
| 18 | + |
| 19 | +describe('files batch-delete ids as trailing arguments', () => { |
| 20 | + it('sends ids given as arguments exactly as it sends --file-ids', async () => { |
| 21 | + const trailing = await run(['files', 'batch-delete', 'wf_a', 'wf_b', '--yes']) |
| 22 | + const flagged = await run(['files', 'batch-delete', '--file-ids', 'wf_a', 'wf_b', '--yes']) |
| 23 | + expect(trailing.exitCode).toBe(0) |
| 24 | + expect(trailing.bodies).toEqual([{ workspaceId: 'workspace', fileIds: ['wf_a', 'wf_b'] }]) |
| 25 | + expect(flagged.bodies).toEqual(trailing.bodies) |
| 26 | + }) |
| 27 | + |
| 28 | + it('refuses both forms at once, and neither, before any request', async () => { |
| 29 | + const both = await run(['files', 'batch-delete', 'wf_a', '--file-ids', 'wf_b', '--yes']) |
| 30 | + expect(both.exitCode).toBe(1) |
| 31 | + expect(both.stderr).toContain('as arguments or with --file-ids, not both') |
| 32 | + const neither = await run(['files', 'batch-delete', '--yes']) |
| 33 | + expect(neither.exitCode).toBe(1) |
| 34 | + expect(neither.stderr).toContain('--file-ids is required') |
| 35 | + expect([...both.bodies, ...neither.bodies]).toEqual([]) |
| 36 | + }) |
| 37 | + |
| 38 | + it('keeps the destructive confirmation for ids given as arguments', async () => { |
| 39 | + const unconfirmed = await run(['files', 'batch-delete', 'wf_a']) |
| 40 | + expect(unconfirmed.exitCode).toBe(1) |
| 41 | + expect(unconfirmed.stderr).toContain('Re-run with --yes to confirm') |
| 42 | + expect(unconfirmed.bodies).toEqual([]) |
| 43 | + }) |
| 44 | +}) |
0 commit comments