import base64 import json import unittest from pathlib import Path ROOT = Path(__file__).resolve().parents[1] STANDARD_OBJECTS = ( ROOT / "salesforce-crm-standard" / "objects" / "standard_objects_spec.json" ) V66_OBJECTS = ROOT / "salesforce-crm-standard-v66" / "objects" RELEASE_PACKAGE = ( ROOT / "releases" / "io.nexuscrm.sfcrm" / "0.31.0" / "app-package.json" ) EXPECTED_ROW_READ = { "kind": "targetRecordRead", "targetAssociations": [ { "targetObjectField": "WhatId_type", "targetRecordField": "WhatId", }, { "targetObjectField": "WhoId_type", "targetRecordField": "WhoId", }, ], "includeSourceVisibility": True, } class ActivityRowReadContractsTest(unittest.TestCase): def test_task_inherits_related_record_visibility_without_losing_source_visibility(self): objects = json.loads(STANDARD_OBJECTS.read_text()) task = next(obj for obj in objects if obj["apiName"] == "Task") self.assertEqual( task.get("accessPolicy", {}).get("rowRead"), EXPECTED_ROW_READ, ) def test_v66_activity_specs_carry_the_same_row_read_contract(self): for api_name in ("Task", "Event"): with self.subTest(api_name=api_name): spec = json.loads((V66_OBJECTS / api_name / "spec.json").read_text())[0] self.assertEqual( spec.get("accessPolicy", {}).get("rowRead"), EXPECTED_ROW_READ, ) def test_immutable_release_carries_task_row_read_contract(self): package = json.loads(RELEASE_PACKAGE.read_text()) component = next( component for component in package["canonical_metadata_bundle"]["components"] if component["component_kind"] == "metadata.pack.object-spec.v1" and component["business_key"] == "standard_objects_spec:crm" ) blob = next( blob for blob in package["component_blobs"] if blob["component_id"] == component["component_id"] ) objects = json.loads(base64.b64decode(blob["canonical_behavior"])) task = next(obj for obj in objects if obj["apiName"] == "Task") self.assertEqual( task.get("accessPolicy", {}).get("rowRead"), EXPECTED_ROW_READ, ) if __name__ == "__main__": unittest.main()