from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]
SOURCE = (ROOT / "app" / "jasmin_service.py").read_text(encoding="utf-8")


def test_jasmin_country_normalizer_exists_and_handles_portugal_aliases():
    assert "def normalize_jasmin_country_key" in SOURCE
    assert '"PORTUGAL": "PT"' in SOURCE
    assert '"PO": "PT"' in SOURCE
    assert 'normalized.startswith("PORTUG")' in SOURCE


def test_customer_payload_uses_country_normalizer_not_two_char_truncation():
    assert '"country": normalize_jasmin_country_key(customer.get("country") or settings.jasmin_default_country or "PT")' in SOURCE
    assert '_compact(customer.get("country") or settings.jasmin_default_country or "PT", 2).upper()' not in SOURCE


def test_opportunity_extracted_customer_uses_country_normalizer():
    assert '"country": normalize_jasmin_country_key(merged.get("country") or settings.jasmin_default_country or "PT")' in SOURCE
    assert '_compact(merged.get("country") or settings.jasmin_default_country or "PT", 2).upper()' not in SOURCE
