from app.external_reconciliation_sync import _external_customer_key, _jasmin_amount


def test_jasmin_customer_key_prefers_party_code_over_document_natural_key():
    record = {
        "naturalKey": "ORC.ORC2026.136",
        "buyerCustomerParty": "0569",
        "accountingParty": "0569",
    }

    assert _external_customer_key(record, source_system="jasmin") == "0569"


def test_jasmin_customer_key_does_not_use_document_natural_key():
    record = {"naturalKey": "ORC.ORC2026.136", "id": "document-uuid"}

    assert _external_customer_key(record, source_system="jasmin") == ""


def test_jasmin_amount_reads_flattened_payable_total():
    record = {
        "payableAmountAmount": 441.57,
        "grossValueAmount": 359.00,
    }

    assert _jasmin_amount(record) == "441.57"


def test_jasmin_amount_reads_nested_money_object():
    record = {
        "payableAmount": {
            "amount": 441.57,
            "baseAmount": 441.57,
            "reportingAmount": 441.57,
        }
    }

    assert _jasmin_amount(record) == "441.57"
