218f946e48
The MCP tool was sending {"body": ...} but the task logs API route
expects {"content": ...}, causing 400 errors.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
55 lines
1.8 KiB
Python
55 lines
1.8 KiB
Python
"""Tests for tasks MCP tools."""
|
|
import pytest
|
|
from unittest.mock import AsyncMock
|
|
|
|
|
|
@pytest.fixture
|
|
def client(mock_client):
|
|
return mock_client
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_list_tasks_calls_get(client):
|
|
from fable_mcp.tools.tasks import list_tasks
|
|
client.get = AsyncMock(return_value={"tasks": [], "total": 0})
|
|
await list_tasks(client)
|
|
client.get.assert_called_once()
|
|
assert "/api/tasks" in client.get.call_args[0][0]
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_get_task_calls_correct_endpoint(client):
|
|
from fable_mcp.tools.tasks import get_task
|
|
client.get = AsyncMock(return_value={"id": 7, "title": "Fix bug"})
|
|
result = await get_task(client, task_id=7)
|
|
client.get.assert_called_once_with("/api/tasks/7")
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_create_task_posts_payload(client):
|
|
from fable_mcp.tools.tasks import create_task
|
|
client.post = AsyncMock(return_value={"id": 3, "title": "New task"})
|
|
await create_task(client, title="New task")
|
|
call_kwargs = client.post.call_args[1]
|
|
assert call_kwargs["json"]["title"] == "New task"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_update_task_patches(client):
|
|
from fable_mcp.tools.tasks import update_task
|
|
client.patch = AsyncMock(return_value={"id": 3, "status": "done"})
|
|
await update_task(client, task_id=3, status="done")
|
|
client.patch.assert_called_once()
|
|
assert "/api/tasks/3" in client.patch.call_args[0][0]
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_add_task_log_posts_to_logs_endpoint(client):
|
|
from fable_mcp.tools.tasks import add_task_log
|
|
client.post = AsyncMock(return_value={"id": 1, "content": "progress"})
|
|
await add_task_log(client, task_id=9, content="progress")
|
|
client.post.assert_called_once()
|
|
path = client.post.call_args[0][0]
|
|
assert path == "/api/tasks/9/logs"
|
|
assert client.post.call_args[1]["json"]["content"] == "progress"
|