import json from pathlib import Path ROOT = Path(__file__).resolve().parents[1] MAPPING_PATHS = ( ROOT / "packs/Salesforce-PingCAP-L2/field_mappings/standard_field_mappings.json", ROOT / "packs/NOT-EDIT-final-merged-packs/field_mappings/standard_field_mappings.json", ) def _lead_opportunity_detail_mapping(path: Path) -> dict: groups = json.loads(path.read_text()) groups = [ group for group in groups if group.get("sourceObject") == "Lead" and group.get("targetObject") == "Opportunity" and group.get("actionType") == "convert" ] assert len(groups) == 1, f"{path}: expected one Lead -> Opportunity convert mapping" mappings = [ mapping for mapping in groups[0].get("mappings", []) if mapping.get("sourceField") == "Lead_Source_Details__c" and mapping.get("targetField") == "Lead_Source_Detail__c" ] assert len(mappings) == 1, f"{path}: expected one lead-source-detail mapping" return mappings[0] def test_lead_convert_value_mapping_survives_final_pack_assembly() -> None: expected = { "sourceField": "Lead_Source_Details__c", "targetField": "Lead_Source_Detail__c", "valueMap": {"LinkedIn - Display": "Linkedin - Display"}, "onUnmappedValue": "passthrough", } for path in MAPPING_PATHS: assert _lead_opportunity_detail_mapping(path) == expected