"""Tests for WebSocket functionality."""

import pytest
from unittest.mock import Mock, patch
from src.exchanges.coinbase import CoinbaseAdapter


def test_subscribe_ticker():
    """Test ticker subscription."""
    adapter = CoinbaseAdapter("test_key", "test_secret", sandbox=True)
    callback = Mock()
    
    adapter.subscribe_ticker("BTC/USD", callback)
    
    assert f'ticker_BTC/USD' in adapter._ws_callbacks
    assert adapter._ws_callbacks[f'ticker_BTC/USD'] == callback


def test_subscribe_orderbook():
    """Test orderbook subscription."""
    adapter = CoinbaseAdapter("test_key", "test_secret", sandbox=True)
    callback = Mock()
    
    adapter.subscribe_orderbook("BTC/USD", callback)
    
    assert f'orderbook_BTC/USD' in adapter._ws_callbacks


def test_subscribe_trades():
    """Test trades subscription."""
    adapter = CoinbaseAdapter("test_key", "test_secret", sandbox=True)
    callback = Mock()
    
    adapter.subscribe_trades("BTC/USD", callback)
    
    assert f'trades_BTC/USD' in adapter._ws_callbacks


def test_normalize_symbol():
    """Test symbol normalization."""
    adapter = CoinbaseAdapter("test_key", "test_secret", sandbox=True)
    
    assert adapter.normalize_symbol("BTC/USD") == "BTC-USD"
    assert adapter.normalize_symbol("ETH/USDT") == "ETH-USDT"
