from pathlib import Path

ROOT = Path(__file__).resolve().parents[1]


def read(path: str) -> str:
    return (ROOT / path).read_text(encoding="utf-8")


def test_v4925_2_odoo_customer_sync_discovers_schema_before_search_read():
    sync = read("app/external_reconciliation_sync.py")
    assert "def _odoo_model_field_names" in sync
    assert "fields_get" in sync
    assert "def _odoo_partner_fields_for_available_schema" in sync
    assert "def _odoo_partner_domains_for_available_schema" in sync
    assert "ignored_optional_fields" in sync


def test_v4925_2_mobile_is_optional_for_odoo_partner_sync():
    sync = read("app/external_reconciliation_sync.py")
    helper = sync.split("def _odoo_partner_fields_for_available_schema", 1)[1].split("def _odoo_partner_domains_for_available_schema", 1)[0]
    assert '"mobile"' in helper
    assert 'if field != "mobile"' in helper
    assert "Invalid field 'mobile'" in sync
