"""Additional tests for app.core.cache — exception paths in get/pop"""

import pytest
from unittest.mock import AsyncMock, patch


@pytest.mark.asyncio
async def test_get_parse_exception_return_none():
    """get raises JSONDecodeError on malformed data -> returns None"""
    from app.core.cache import CacheService
    cache = CacheService()
    mock_redis = AsyncMock()
    mock_redis.get.return_value = "{bad json"
    cache._redis = mock_redis
    result = await cache.get("bad-key")
    assert result is None


@pytest.mark.asyncio
async def test_pop_exception_return_none():
    """pop raises exception during get -> returns None"""
    from app.core.cache import CacheService
    cache = CacheService()
    mock_redis = AsyncMock()
    mock_redis.get.side_effect = Exception("redis error")
    cache._redis = mock_redis
    result = await cache.pop("error-key")
    assert result is None
