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_3_odoo_sale_order_reference_never_becomes_customer_name():
    sync = read("app/external_reconciliation_sync.py")
    assert "def _looks_like_odoo_sale_order_reference" in sync
    assert "S\\d{4,}" in sync
    assert "def _odoo_fiscal_customer_name" in sync
    seed = sync.split("def _customer_seed_data_from_record", 1)[1].split("def _upsert_fiscal_customer_from_external_record", 1)[0]
    assert 'source_system == "odoo"' in seed
    assert "_odoo_fiscal_customer_name(record)" in seed
    assert "Never create/update a fiscal customer with an Odoo sale order reference" in seed


def test_v4925_3_includes_repair_script_for_existing_s00_customers():
    script = read("scripts/repair_odoo_sale_order_customer_names.py")
    assert "Dry-run by default" in script
    assert "metadata->>'source_system' = 'odoo'" in script
    assert "partner_name" in script
    assert "--apply" in script
