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() as fh: return json.load(fh) class ContentDistributionHrefFieldsContractsTest(unittest.TestCase): def test_manifest_declares_locked_href_rewrite_fields_component(self): manifest = load_json(CRM_PACK / "pack.json") components = { (component["kind"], component["businessKey"]): component for component in manifest["components"] } component = components[("href_rewrite_fields", "content_distribution_href_fields")] self.assertEqual(component["manageability"], "locked") self.assertEqual(component["path"], "ux/content_distribution_href_fields.json") self.assertEqual( component["dependsOn"], [{"kind": "object_spec", "businessKey": "standard_objects_spec:crm"}], ) def test_payload_declares_content_distribution_record_view_source_matcher(self): payload = load_json(CRM_PACK / "ux" / "content_distribution_href_fields.json") self.assertEqual( payload, { "resolvers": [ { "resolverId": "content_distribution", "kind": "record-attachment-by-source-record/v2", "sourceObjectApiName": "ContentDistribution", "sourceFileReferenceFieldApiName": "ContentVersionId", "sourceDeletedFieldApiName": "IsDeleted", "sourceRecordMatcher": { "kind": "record-identifier-segment/v2", "startOffsetBytes": 3, "lengthBytes": 12, }, } ], "fields": [ { "parentApiName": "Contract", "fieldApiName": "LegacyLink__c", "resolverId": "content_distribution", } ] }, ) def test_source_object_schema_closes_the_record_view_resolver(self): specs = { spec["apiName"]: spec for spec in load_json(CRM_PACK / "objects" / "standard_objects_spec.json") } source = specs["ContentDistribution"] self.assertEqual(source["keyPrefix"], "05D") self.assertEqual(source["sharingModel"], "Private") self.assertEqual( source["fields"], [ { "apiName": "ContentVersionId", "label": "Content Version ID", "type": "string", "required": True, } ], ) self.assertNotIn( "IsDeleted", {field["apiName"] for field in source["fields"]}, "L0 injects IsDeleted; L1 must not redeclare the system field", )