"""
Tests for database utilities - AC4 (dual DB URL conversion)
"""

import pytest

from database.utils import convert_to_async_url


class TestConvertToAsyncUrl:
    """AC4: PostgreSQL (prod) and SQLite (dev) URL conversion to async drivers."""

    def test_postgresql_converted_to_asyncpg(self):
        """postgresql:// -> postgresql+asyncpg://"""
        url = "postgresql://user:pass@localhost:5432/db"
        assert convert_to_async_url(url) == "postgresql+asyncpg://user:pass@localhost:5432/db"

    def test_postgres_converted_to_asyncpg(self):
        """postgres:// -> postgresql+asyncpg://"""
        url = "postgres://user:pass@localhost:5432/db"
        assert convert_to_async_url(url) == "postgresql+asyncpg://user:pass@localhost:5432/db"

    def test_sqlite_converted_to_aiosqlite(self):
        """sqlite:/// -> sqlite+aiosqlite:///"""
        url = "sqlite:///./data/translate.db"
        assert convert_to_async_url(url) == "sqlite+aiosqlite:///./data/translate.db"

    def test_unknown_url_unchanged(self):
        """Unknown scheme is returned unchanged."""
        url = "mysql://localhost/db"
        assert convert_to_async_url(url) == "mysql://localhost/db"
