diff --git a/tests/test_cli.py b/tests/test_cli.py new file mode 100644 index 0000000..b685077 --- /dev/null +++ b/tests/test_cli.py @@ -0,0 +1,59 @@ +import pytest +from click.testing import CliRunner +from src.cli.main import main + + +class TestCLI: + @pytest.fixture + def runner(self): + return CliRunner() + + def test_main_help(self, runner): + result = runner.invoke(main, ["--help"]) + assert result.exit_code == 0 + assert "API Mock CLI" in result.output + + def test_main_version(self, runner): + result = runner.invoke(main, ["--version"]) + assert result.exit_code == 0 + assert "0.1.0" in result.output + + def test_init_command(self, runner, tmp_path): + result = runner.invoke(main, ["init", "--name", "test-api", "--path", str(tmp_path)]) + assert result.exit_code == 0 + assert "Created mock API project" in result.output + config_path = tmp_path / "test-api" / "config.yaml" + assert config_path.exists() + + def test_init_command_with_template(self, runner, tmp_path): + result = runner.invoke(main, [ + "init", + "--name", "full-api", + "--template", "full", + "--path", str(tmp_path) + ]) + assert result.exit_code == 0 + + def test_stop_no_server(self, runner): + result = runner.invoke(main, ["stop"]) + assert result.exit_code == 0 + assert "No running server found" in result.output + + def test_generate_command(self, runner, tmp_path): + result = runner.invoke(main, [ + "generate", "GetUser", + "--method", "GET", + "--path", "/api/users/{id}", + "--output", str(tmp_path / "endpoints.yaml") + ]) + assert result.exit_code == 0 + assert "Generated endpoint" in result.output + + def test_generate_with_status_code(self, runner, tmp_path): + result = runner.invoke(main, [ + "generate", "CreateItem", + "--method", "POST", + "--status-code", "201", + "--output", str(tmp_path / "endpoints.yaml") + ]) + assert result.exit_code == 0