# tests/test_telegram_suppress.py
import pytest
from nanobot.bus.events import OutboundMessage
from nanobot.channels.telegram import TelegramChannel
from unittest.mock import AsyncMock, MagicMock


@pytest.mark.asyncio
async def test_suppressed_message_not_sent():
    """Test that messages with suppressed=True metadata are not sent to Telegram API."""

    config = MagicMock()
    config.token = "test-token"
    bus = MagicMock()

    channel = TelegramChannel(config, bus)

    # Mock the internal _app and bot directly (skip start())
    mock_app = MagicMock()
    mock_bot = AsyncMock()
    mock_app.bot = mock_bot
    channel._app = mock_app

    # Send a suppressed message
    msg = OutboundMessage(
        channel="telegram",
        chat_id="12345",
        content="[HIDDEN] This should not be sent",
        metadata={"suppressed": True}
    )

    await channel.send(msg)

    # Verify bot.send_message was NOT called
    mock_bot.send_message.assert_not_called()


@pytest.mark.asyncio
async def test_normal_message_sent():
    """Test that normal messages are sent to Telegram API."""

    config = MagicMock()
    config.token = "test-token"
    bus = MagicMock()

    channel = TelegramChannel(config, bus)

    # Mock the internal _app and bot directly (skip start())
    mock_app = MagicMock()
    mock_bot = AsyncMock()
    mock_app.bot = mock_bot
    channel._app = mock_app

    # Send a normal message
    msg = OutboundMessage(
        channel="telegram",
        chat_id="12345",
        content="Normal message",
        metadata={}
    )

    await channel.send(msg)

    # Verify bot.send_message WAS called
    mock_bot.send_message.assert_called_once()
