|
| 1 | +"""Tests for task status change helper.""" |
| 2 | + |
| 3 | +from unittest.mock import patch |
| 4 | + |
| 5 | +import pytest |
| 6 | + |
| 7 | +from omnifocus_mcp.mcp_tools.tasks.status_helper import change_task_status |
| 8 | + |
| 9 | + |
| 10 | +class TestChangeTaskStatus: |
| 11 | + """Tests for change_task_status helper.""" |
| 12 | + |
| 13 | + @pytest.fixture |
| 14 | + def mock_execute(self): |
| 15 | + """Create a mock for execute_omnijs_with_params.""" |
| 16 | + with patch("omnifocus_mcp.mcp_tools.response.execute_omnijs_with_params") as mock: |
| 17 | + yield mock |
| 18 | + |
| 19 | + @pytest.mark.asyncio |
| 20 | + async def test_complete_task(self, mock_execute): |
| 21 | + """Test marking a task as completed.""" |
| 22 | + mock_execute.return_value = { |
| 23 | + "success": True, |
| 24 | + "message": "Task status changed to completed", |
| 25 | + "taskId": "task-123", |
| 26 | + } |
| 27 | + |
| 28 | + success, message = await change_task_status("task-123", "completed") |
| 29 | + |
| 30 | + assert success is True |
| 31 | + assert "completed" in message |
| 32 | + mock_execute.assert_called_once() |
| 33 | + params = mock_execute.call_args[0][1] |
| 34 | + assert params["task_id"] == "task-123" |
| 35 | + assert params["status"] == "completed" |
| 36 | + |
| 37 | + @pytest.mark.asyncio |
| 38 | + async def test_drop_task(self, mock_execute): |
| 39 | + """Test dropping a task.""" |
| 40 | + mock_execute.return_value = { |
| 41 | + "success": True, |
| 42 | + "message": "Task status changed to dropped", |
| 43 | + "taskId": "task-123", |
| 44 | + } |
| 45 | + |
| 46 | + success, message = await change_task_status("task-123", "dropped") |
| 47 | + |
| 48 | + assert success is True |
| 49 | + assert "dropped" in message |
| 50 | + |
| 51 | + @pytest.mark.asyncio |
| 52 | + async def test_mark_incomplete(self, mock_execute): |
| 53 | + """Test marking a task as incomplete.""" |
| 54 | + mock_execute.return_value = { |
| 55 | + "success": True, |
| 56 | + "message": "Task status changed to incomplete", |
| 57 | + "taskId": "task-123", |
| 58 | + } |
| 59 | + |
| 60 | + success, message = await change_task_status("task-123", "incomplete") |
| 61 | + |
| 62 | + assert success is True |
| 63 | + assert "incomplete" in message |
| 64 | + |
| 65 | + @pytest.mark.asyncio |
| 66 | + async def test_task_not_found(self, mock_execute): |
| 67 | + """Test error when task is not found.""" |
| 68 | + mock_execute.return_value = {"error": "Task not found: bad-id"} |
| 69 | + |
| 70 | + success, message = await change_task_status("bad-id", "completed") |
| 71 | + |
| 72 | + assert success is False |
| 73 | + assert "not found" in message |
| 74 | + |
| 75 | + @pytest.mark.asyncio |
| 76 | + async def test_invalid_status(self, mock_execute): |
| 77 | + """Test error for invalid status value.""" |
| 78 | + mock_execute.return_value = {"error": "Invalid status: bogus"} |
| 79 | + |
| 80 | + success, message = await change_task_status("task-123", "bogus") |
| 81 | + |
| 82 | + assert success is False |
| 83 | + assert "Invalid status" in message |
| 84 | + |
| 85 | + @pytest.mark.asyncio |
| 86 | + async def test_script_name(self, mock_execute): |
| 87 | + """Test that the correct script name is used.""" |
| 88 | + mock_execute.return_value = { |
| 89 | + "success": True, |
| 90 | + "message": "Task status changed to completed", |
| 91 | + "taskId": "task-123", |
| 92 | + } |
| 93 | + |
| 94 | + await change_task_status("task-123", "completed") |
| 95 | + |
| 96 | + script_name = mock_execute.call_args[0][0] |
| 97 | + assert script_name == "change_task_status" |
0 commit comments