# tests/api/dependencies/test_event_bus.py
"""Tests for the event_bus dependency."""

from unittest.mock import AsyncMock, patch

import pytest

from app.api.dependencies.event_bus import get_event_bus
from app.services.event_bus import EventBus


@pytest.mark.asyncio
class TestGetEventBusDependency:
    """Tests for the get_event_bus FastAPI dependency."""

    async def test_get_event_bus_returns_event_bus(self):
        """Test that get_event_bus returns an EventBus instance."""
        mock_event_bus = AsyncMock(spec=EventBus)

        with patch(
            "app.api.dependencies.event_bus._get_connected_event_bus",
            return_value=mock_event_bus,
        ):
            result = await get_event_bus()

            assert result is mock_event_bus

    async def test_get_event_bus_calls_get_connected_event_bus(self):
        """Test that get_event_bus calls the underlying function."""
        mock_event_bus = AsyncMock(spec=EventBus)
        mock_get_connected = AsyncMock(return_value=mock_event_bus)

        with patch(
            "app.api.dependencies.event_bus._get_connected_event_bus",
            mock_get_connected,
        ):
            await get_event_bus()

            mock_get_connected.assert_called_once()
