|
| 1 | +"""Tests for approval CLI command""" |
| 2 | + |
| 3 | +import pytest |
| 4 | +from typer.testing import CliRunner |
| 5 | +from unittest.mock import patch, MagicMock |
| 6 | +from specify_cli.approval_command import approval_command |
| 7 | +import typer |
| 8 | + |
| 9 | + |
| 10 | +def test_approval_status_no_config(): |
| 11 | + """Test approval status when no config exists""" |
| 12 | + with patch("specify_cli.approval_command.ApprovalGatesConfig.load", return_value=None): |
| 13 | + # Create a simple typer app to test the command |
| 14 | + app = typer.Typer() |
| 15 | + app.command()(approval_command) |
| 16 | + |
| 17 | + runner = CliRunner() |
| 18 | + result = runner.invoke(app, ["--action", "status"]) |
| 19 | + assert result.exit_code == 0 |
| 20 | + assert "No approval gates configured" in result.stdout |
| 21 | + |
| 22 | + |
| 23 | +def test_approval_status_with_config(): |
| 24 | + """Test approval status with gates configured""" |
| 25 | + # Mock configuration |
| 26 | + mock_config = MagicMock() |
| 27 | + mock_config.gates = { |
| 28 | + "specify": {"enabled": True, "min_approvals": 1}, |
| 29 | + "plan": {"enabled": True, "min_approvals": 2}, |
| 30 | + } |
| 31 | + |
| 32 | + with patch("specify_cli.approval_command.ApprovalGatesConfig.load", return_value=mock_config): |
| 33 | + app = typer.Typer() |
| 34 | + app.command()(approval_command) |
| 35 | + |
| 36 | + runner = CliRunner() |
| 37 | + result = runner.invoke(app, ["--action", "status"]) |
| 38 | + assert result.exit_code == 0 |
| 39 | + assert "Approval gates enabled" in result.stdout |
| 40 | + assert "specify" in result.stdout |
| 41 | + assert "plan" in result.stdout |
| 42 | + |
| 43 | + |
| 44 | +def test_approval_default_action(): |
| 45 | + """Test approval command with default action (status)""" |
| 46 | + mock_config = MagicMock() |
| 47 | + mock_config.gates = { |
| 48 | + "specify": {"enabled": True, "min_approvals": 1}, |
| 49 | + } |
| 50 | + |
| 51 | + with patch("specify_cli.approval_command.ApprovalGatesConfig.load", return_value=mock_config): |
| 52 | + app = typer.Typer() |
| 53 | + app.command()(approval_command) |
| 54 | + |
| 55 | + runner = CliRunner() |
| 56 | + # Invoke without --action (should default to status) |
| 57 | + result = runner.invoke(app, []) |
| 58 | + assert result.exit_code == 0 |
| 59 | + assert "Approval gates enabled" in result.stdout |
0 commit comments