from types import SimpleNamespace

import pytest

from agent.tools.product_search_helpers import build_starrocks_query


@pytest.mark.asyncio
async def test_code_search_supports_missing_middle_character_with_loose_pattern():
    params = SimpleNamespace(
        description="",
        product_name=None,
        magento_ref_code="6ST25W05",
        gender_by_product=None,
        age_by_product=None,
        master_color=None,
        price_min=None,
        price_max=None,
        discount_min=None,
        discount_max=None,
        discovery_mode=None,
    )

    sql, sql_params = await build_starrocks_query(params)

    assert "REPLACE(UPPER(internal_ref_code), '-', '') LIKE %s" in sql
    assert "REPLACE(UPPER(magento_ref_code), '-', '') LIKE %s" in sql
    assert "REPLACE(UPPER(product_color_code), '-', '') LIKE %s" in sql
    assert "%6%S%T%2%5%W%0%5%" in sql_params
