"""Smoke: fetch_json toleruje dict z asyncpg (bez reálné DB)."""

from __future__ import annotations

import asyncio
from unittest.mock import AsyncMock

from app.db_json import fetch_json


def test_fetch_json_returns_dict() -> None:
    async def _run() -> None:
        conn = AsyncMock()
        conn.fetchval = AsyncMock(return_value={"a": 1})
        out = await fetch_json(conn, "select ems.fn_x()", 1)
        assert out == {"a": 1}

    asyncio.run(_run())


def test_fetch_json_parses_str() -> None:
    async def _run() -> None:
        conn = AsyncMock()
        conn.fetchval = AsyncMock(return_value='{"b": 2}')
        out = await fetch_json(conn, "select 1")
        assert out == {"b": 2}

    asyncio.run(_run())
