from pathlib import Path

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


def read(path: str) -> str:
    return (ROOT / path).read_text()


def test_jasmin_money_object_helper_exists():
    source = read("app/reconciliation_service.py")
    assert "def _jasmin_money_value" in source
    assert '"amount", "baseAmount", "reportingAmount", "value"' in source
    assert "value = _jasmin_money_value(value)" in source


def test_jasmin_document_totals_read_real_amount_fields():
    source = read("app/reconciliation_service.py")
    assert "def _jasmin_document_totals" in source
    assert '"grossValueAmount"' in source
    assert '"taxExclusiveAmountAmount"' in source
    assert '"taxTotalAmount"' in source
    assert '"payableAmountAmount"' in source
    assert '"payableAmount"' in source


def test_jasmin_line_prices_read_nested_and_scalar_fields():
    source = read("app/reconciliation_service.py")
    assert '"unitPriceAmount"' in source
    assert '"unitPrice"' in source
    assert '"lineExtensionAmountAmount"' in source
    assert '"lineExtensionAmount"' in source
    assert '"grossValueAmount"' in source


def test_backfill_script_accepts_money_objects_from_detail_fetch():
    source = read("scripts/backfill_jasmin_opportunity_details.py")
    assert "def _money_value" in source
    assert "value = _money_value(value)" in source
