"""Test scan command."""

import tempfile
from pathlib import Path

from typer.testing import CliRunner

from apiposture_pro.cli.app import app

runner = CliRunner()


def test_scan_without_license(temp_dir: Path) -> None:
    """Test scan fails without valid license."""
    project_dir = temp_dir / "sample_project"
    project_dir.mkdir()
    (project_dir / "main.py").write_text("from fastapi import FastAPI\napp = FastAPI()\n")

    result = runner.invoke(app, ["scan", str(project_dir)])

    assert result.exit_code == 1
    assert "No valid license found" in result.stdout


def test_scan_nonexistent_path() -> None:
    """Test scan fails with nonexistent path."""
    with tempfile.TemporaryDirectory() as tmpdir:
        nonexistent = Path(tmpdir) / "does_not_exist"

        result = runner.invoke(app, ["scan", str(nonexistent)])

        assert result.exit_code != 0
