const { test } = require('node:test')
const assert = require('node:assert/strict')
const copyCommand = require('./copy')

test('copyCommand exits when --from or --to is missing', async () => {
  let exitCode
  const originalExit = process.exit
  process.exit = (code) => {
    exitCode = code
    throw new Error('process.exit')
  }

  try {
    await assert.rejects(() => copyCommand('hero', { from: null, to: [] }), /process\.exit/)
    assert.equal(exitCode, 1)
  } finally {
    process.exit = originalExit
  }
})

test('copyCommand exits when --to is empty', async () => {
  let exitCode
  const originalExit = process.exit
  process.exit = (code) => {
    exitCode = code
    throw new Error('process.exit')
  }

  try {
    await assert.rejects(
      () => copyCommand('hero', { from: 'app-a', to: [] }),
      /process\.exit/,
    )
    assert.equal(exitCode, 1)
  } finally {
    process.exit = originalExit
  }
})
