From d4c9173c6c371546f581f2c81572fa2c7395dd17 Mon Sep 17 00:00:00 2001 From: Matthew Elwell Date: Mon, 29 Apr 2024 11:12:30 +0100 Subject: [PATCH] fix(hubspot): create hubspot company with domain (#3844) --- api/integrations/lead_tracking/hubspot/lead_tracker.py | 5 ++++- .../lead_tracking/hubspot/test_unit_hubspot_tasks.py | 7 ++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/api/integrations/lead_tracking/hubspot/lead_tracker.py b/api/integrations/lead_tracking/hubspot/lead_tracker.py index 54c45e2f416f..aaa8c6caa5ee 100644 --- a/api/integrations/lead_tracking/hubspot/lead_tracker.py +++ b/api/integrations/lead_tracking/hubspot/lead_tracker.py @@ -119,7 +119,10 @@ def update_company_active_subscription( def _get_or_create_company_by_domain(self, domain: str) -> dict: company = self.client.get_company_by_domain(domain) if not company: - company = self.client.create_company(name=domain) + # Since we don't know the company's name, we pass the domain as + # both the name and the domain. This can then be manually + # updated in Hubspot if needed. + company = self.client.create_company(name=domain, domain=domain) return company diff --git a/api/tests/unit/integrations/lead_tracking/hubspot/test_unit_hubspot_tasks.py b/api/tests/unit/integrations/lead_tracking/hubspot/test_unit_hubspot_tasks.py index 627d93eb24cb..5e4a833a1e5f 100644 --- a/api/tests/unit/integrations/lead_tracking/hubspot/test_unit_hubspot_tasks.py +++ b/api/tests/unit/integrations/lead_tracking/hubspot/test_unit_hubspot_tasks.py @@ -36,10 +36,12 @@ def test_track_hubspot_lead_without_organisation( # Given hubspot_company_id = "company-id" hubspot_contact_id = "contact-id" + domain = "example.com" + email = f"test@{domain}" settings.ENABLE_HUBSPOT_LEAD_TRACKING = True - user = FFAdminUser.objects.create(email="test@example.com") + user = FFAdminUser.objects.create(email=email) mock_hubspot_client = mocker.MagicMock(spec=HubspotClient) mocker.patch( @@ -56,5 +58,8 @@ def test_track_hubspot_lead_without_organisation( track_hubspot_lead_without_organisation(user_id=user.id) # Then + mock_hubspot_client.create_company.assert_called_once_with( + name=domain, domain=domain + ) mock_hubspot_client.create_contact.assert_called_once_with(user, hubspot_company_id) assert HubspotLead.objects.filter(user=user).exists()