"""Tests for projects 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_projects_calls_get(client):
    from fable_mcp.tools.projects import list_projects
    client.get = AsyncMock(return_value={"projects": []})
    await list_projects(client)
    client.get.assert_called_once_with("/api/projects")


@pytest.mark.asyncio
async def test_get_project_calls_correct_endpoint(client):
    from fable_mcp.tools.projects import get_project
    client.get = AsyncMock(return_value={"id": 2, "title": "Proj"})
    result = await get_project(client, project_id=2)
    client.get.assert_called_once_with("/api/projects/2")


@pytest.mark.asyncio
async def test_create_project_posts_payload(client):
    from fable_mcp.tools.projects import create_project
    client.post = AsyncMock(return_value={"id": 4, "title": "New"})
    await create_project(client, title="New", description="Desc")
    call_kwargs = client.post.call_args[1]
    assert call_kwargs["json"]["title"] == "New"
    assert call_kwargs["json"]["description"] == "Desc"


@pytest.mark.asyncio
async def test_update_project_patches(client):
    from fable_mcp.tools.projects import update_project
    client.patch = AsyncMock(return_value={"id": 4, "status": "active"})
    await update_project(client, project_id=4, status="active")
    assert "/api/projects/4" in client.patch.call_args[0][0]
