import json import unittest from pathlib import Path REPO_ROOT = Path(__file__).resolve().parents[1] PACK_ROOT = REPO_ROOT / "packs" / "PingCAP-HubSpot-Companion" PROFILE_OWNER = "hubspot-crm-connector" PROFILE_NAME = "hubspot-crm-deal-company-write" def load_json(path: Path): with path.open(encoding="utf-8") as handle: return json.load(handle) class HubSpotDealCompanyAuthorityTest(unittest.TestCase): def test_company_and_deal_contracts_share_explicit_authority(self): account = load_json( PACK_ROOT / "connector_push_contracts" / "account_company_outbound.json" ) opportunity = load_json( PACK_ROOT / "connector_push_contracts" / "opportunity_deal_outbound.json" ) for contract in (account, opportunity): self.assertEqual(contract["profileOwnerPack"], PROFILE_OWNER) self.assertEqual(contract["profileName"], PROFILE_NAME) self.assertEqual(account["targetObject"], "companies") self.assertEqual( (account["createPathTemplate"], account["updatePathTemplate"]), ( "/crm/v3/objects/companies", "/crm/v3/objects/companies/{remoteId}", ), ) self.assertEqual(opportunity["targetObject"], "deals") self.assertEqual( (opportunity["createPathTemplate"], opportunity["updatePathTemplate"]), ( "/crm/v3/objects/deals", "/crm/v3/objects/deals/{remoteId}", ), ) self.assertEqual( opportunity["associations"], [ { "sourceLookupField": "AccountId", "sourceObject": "Account", "remoteIdField": "HubSpot_Id__c", "targetActionSlotId": "hubspot-company", "targetDestinationSlotId": "hubspot-company", "targetObject": "companies", "payloadField": "associations", "payloadMergeMode": "append", "inlinePhases": ["create"], "payloadTemplate": { "to": {"id": "{toId}"}, "types": [ { "associationCategory": "HUBSPOT_DEFINED", "associationTypeId": 5, } ], }, "associationPath": "/crm/v3/objects/deals/{fromId}/associations/companies/{toId}/5", "associationMethod": "PUT", "calloutPhases": ["update"], } ], ) def test_flow_literals_match_contract_authority(self): for filename in ( "HubSpot_Account_Company_Outbound_Update.flow.json", "HubSpot_Opportunity_Deal_Outbound_Update.flow.json", ): flow = load_json(PACK_ROOT / "flows" / filename) action = flow["actionCalls"][0] inputs = { item["name"]: item["value"]["stringValue"] for item in action["inputParameters"] if "stringValue" in item["value"] } self.assertEqual(inputs["profileOwnerPack"], PROFILE_OWNER) self.assertEqual(inputs["profileName"], PROFILE_NAME) if __name__ == "__main__": unittest.main()