import json import unittest from pathlib import Path REPO_ROOT = Path(__file__).resolve().parents[1] CRM_PACK = REPO_ROOT / "salesforce-crm-standard" def load_json(path: Path): with path.open(encoding="utf-8") as handle: return json.load(handle) def object_spec(api_name: str): specs = load_json(CRM_PACK / "objects" / "standard_objects_spec.json") for spec in specs: if spec.get("apiName") == api_name: return spec raise AssertionError(f"{api_name} object spec missing") def field_spec(spec: dict, api_name: str): for field in spec.get("fields", []): if field.get("apiName") == api_name: return field raise AssertionError(f"{spec.get('apiName')}.{api_name} field spec missing") class CRMStandardContractNameTest(unittest.TestCase): def test_contract_name_is_required_compound_from_contract_number(self): # Transitional CRM-pack shape: the v66 describe snapshot models # ContractNumber as the Contract name field and omits Contract.Name. # The current hand-curated pack keeps Contract.Name to match existing # layouts and lookup-display consumers, but makes it read-only in # practice by deriving it from ContractNumber through compound metadata. contract = object_spec("Contract") name = field_spec(contract, "Name") self.assertEqual(name.get("label"), "Contract Name") self.assertEqual(name.get("type"), "string") self.assertTrue(name.get("required")) self.assertTrue(name.get("isNameField")) self.assertTrue(name.get("isCompound")) self.assertEqual(name.get("composedFrom"), ["ContractNumber"]) if __name__ == "__main__": unittest.main()