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


@pytest.mark.asyncio
async def test_create_milestone_posts_to_project_endpoint(client):
    from fable_mcp.tools.milestones import create_milestone
    client.post = AsyncMock(return_value={"id": 10, "title": "M1"})
    await create_milestone(client, project_id=3, title="M1")
    path = client.post.call_args[0][0]
    assert path == "/api/projects/3/milestones"
    assert client.post.call_args[1]["json"]["title"] == "M1"


@pytest.mark.asyncio
async def test_update_milestone_patches(client):
    from fable_mcp.tools.milestones import update_milestone
    client.patch = AsyncMock(return_value={"id": 10, "status": "completed"})
    await update_milestone(client, project_id=3, milestone_id=10, status="completed")
    path = client.patch.call_args[0][0]
    assert "/api/projects/3/milestones/10" in path
