"""Tests for the Hello World MCP server."""

import pytest
from hello_world_mcp.server import app


@pytest.mark.asyncio
async def test_list_tools():
    """Test that the server lists the say_hello tool."""
    tools = await app.list_tools()()
    
    assert len(tools) == 1
    assert tools[0].name == "say_hello"
    assert "hello" in tools[0].description.lower()


@pytest.mark.asyncio
async def test_say_hello_with_name():
    """Test saying hello with a specific name."""
    result = await app.call_tool()("say_hello", {"name": "Alice"})
    
    assert len(result) == 1
    assert result[0].text == "Hello, Alice!"


@pytest.mark.asyncio
async def test_say_hello_without_name():
    """Test saying hello without a name (defaults to World)."""
    result = await app.call_tool()("say_hello", {})
    
    assert len(result) == 1
    assert result[0].text == "Hello, World!"


@pytest.mark.asyncio
async def test_unknown_tool():
    """Test that calling an unknown tool raises an error."""
    with pytest.raises(ValueError, match="Unknown tool"):
        await app.call_tool()("nonexistent_tool", {})
