-
Notifications
You must be signed in to change notification settings - Fork 501
fix(hubspot): simplify integration to only create contacts #7147
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -145,14 +145,6 @@ def test_track_hubspot_lead_v2__new_user_added_to_org__creates_associations( | |
| "organisations.models.track_hubspot_lead_v2" | ||
| ) | ||
|
|
||
| mock_client_existing_contact.get_company_by_domain.return_value = { | ||
| "id": HUBSPOT_COMPANY_ID, | ||
| "properties": {"name": domain}, | ||
| } | ||
| mock_client_existing_contact.update_company.return_value = { | ||
| "id": HUBSPOT_COMPANY_ID, | ||
| "properties": {"name": organisation.name}, | ||
| } | ||
| assert getattr(organisation, "hubspot_organisation", None) is None | ||
| # When | ||
| user.add_organisation(organisation, role=OrganisationRole.ADMIN) | ||
|
|
@@ -165,16 +157,10 @@ def test_track_hubspot_lead_v2__new_user_added_to_org__creates_associations( | |
|
|
||
| # Triggering it manually to void the delay | ||
| track_hubspot_lead_v2(user.id, organisation.id) | ||
| organisation.refresh_from_db() | ||
| assert organisation.hubspot_organisation is not None | ||
| assert organisation.hubspot_organisation.hubspot_id == HUBSPOT_COMPANY_ID | ||
|
|
||
| # create_lead only creates the contact, not the company association | ||
| mock_client_existing_contact.create_company.assert_not_called() | ||
|
|
||
| mock_client_existing_contact.associate_contact_to_company.assert_called_once_with( | ||
| contact_id=HUBSPOT_USER_ID, | ||
| company_id=HUBSPOT_COMPANY_ID, | ||
| ) | ||
| mock_client_existing_contact.associate_contact_to_company.assert_not_called() | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test name should reflect that associations are not created. (Atm:
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, |
||
| mock_client_existing_contact.create_lead_form.assert_not_called() | ||
| mock_client_existing_contact.get_contact.assert_called_once_with(user) | ||
|
|
||
|
|
@@ -253,100 +239,7 @@ def test_create_lead__existing_hubspot_org__creates_contact_and_associates( | |
| mock_client.create_lead_form.assert_called_once_with( | ||
| user=user, form_id=HUBSPOT_FORM_ID_SAAS | ||
| ) | ||
| mock_client.associate_contact_to_company.assert_called_once_with( | ||
| contact_id=HUBSPOT_USER_ID, | ||
| company_id=HUBSPOT_COMPANY_ID, | ||
| ) | ||
|
|
||
|
|
||
| def test_create_lead__filtered_domain__skips_company_creation( | ||
| organisation: Organisation, | ||
| settings: SettingsWrapper, | ||
| mock_client_existing_contact: MagicMock, | ||
| enable_hubspot: None, | ||
| mocker: MockerFixture, | ||
| ) -> None: | ||
| # Given | ||
| settings.HUBSPOT_IGNORE_ORGANISATION_DOMAINS = ["example.com"] | ||
|
|
||
| user = FFAdminUser.objects.create( | ||
| email="new.user@example.com", | ||
| first_name="Frank", | ||
| last_name="Louis", | ||
| marketing_consent_given=True, | ||
| ) | ||
|
|
||
| # When | ||
| tracker = HubspotLeadTracker() | ||
| tracker.create_lead(user=user, organisation=organisation) | ||
|
|
||
| # Then | ||
| assert HubspotLead.objects.filter(user=user, hubspot_id=HUBSPOT_USER_ID).exists() | ||
| mock_client_existing_contact.get_contact.assert_called_once_with(user) | ||
| mock_client_existing_contact.create_company.assert_not_called() | ||
| mock_client_existing_contact.associate_contact_to_company.assert_not_called() | ||
|
|
||
|
|
||
| def test_update_company_active_subscription__valid_subscription__calls_update_company( | ||
| db: None, mocker: MockerFixture | ||
| ) -> None: | ||
| # Given | ||
| mock_client = mocker.MagicMock() | ||
| mock_response = {"id": "123"} | ||
| mock_client.update_company.return_value = mock_response | ||
|
|
||
| tracker = HubspotLeadTracker() | ||
| tracker.client = mock_client | ||
|
|
||
| mock_org = mocker.MagicMock() | ||
| mock_org.hubspot_organisation.hubspot_id = "hubspot-org-1" | ||
|
|
||
| mock_subscription = mocker.MagicMock() | ||
| mock_subscription.plan = "scaleup" | ||
| mock_subscription.organisation = mock_org | ||
|
|
||
| # When | ||
| result = tracker.update_company_active_subscription(subscription=mock_subscription) | ||
|
|
||
| # Then | ||
| assert result == mock_response | ||
| mock_client.update_company.assert_called_once_with( | ||
| active_subscription="scaleup", | ||
| hubspot_company_id="hubspot-org-1", | ||
| ) | ||
|
|
||
|
|
||
| def test_update_company_active_subscription__no_hubspot_org__returns_none( | ||
| mocker: MockerFixture, | ||
| ) -> None: | ||
| # Given | ||
| subscription = mocker.MagicMock() | ||
| subscription.plan = "pro" | ||
| subscription.organisation = mocker.MagicMock() | ||
| subscription.organisation.hubspot_organisation = None | ||
|
|
||
| # When | ||
| tracker = HubspotLeadTracker() | ||
| result = tracker.update_company_active_subscription(subscription) | ||
|
|
||
| # Then | ||
| assert result is None | ||
|
|
||
|
|
||
| def test_update_company_active_subscription__no_plan__returns_none( | ||
| mocker: MockerFixture, | ||
| ) -> None: | ||
| # Given | ||
| subscription = mocker.MagicMock() | ||
| subscription.plan = None | ||
| subscription.organisation = mocker.MagicMock() | ||
|
|
||
| # When | ||
| tracker = HubspotLeadTracker() | ||
| result = tracker.update_company_active_subscription(subscription) | ||
|
|
||
| # Then | ||
| assert result is None | ||
| mock_client.associate_contact_to_company.assert_not_called() | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
|
|
@@ -390,38 +283,6 @@ def test_create_user_hubspot_contact__get_contact_retries__returns_expected_id( | |
| assert mock_client.get_contact.call_count == expected_call_count | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| "hubspot_contact_id, hubspot_org_id", | ||
| [ | ||
| (None, "org_123"), | ||
| ("contact_123", None), | ||
| ], | ||
| ) | ||
| def test_create_lead__missing_contact_or_org_id__skips_association( | ||
| mocker: MockerFixture, | ||
| hubspot_contact_id: str | None, | ||
| hubspot_org_id: str | None, | ||
| staff_user: FFAdminUser, | ||
| organisation: Organisation, | ||
| ) -> None: | ||
| # Given | ||
| mock_client = mocker.MagicMock() | ||
| tracker = HubspotLeadTracker() | ||
|
|
||
| mocker.patch.object( | ||
| tracker, "_get_or_create_user_hubspot_id", return_value=hubspot_contact_id | ||
| ) | ||
| mocker.patch.object( | ||
| tracker, "_get_organisation_hubspot_id", return_value=hubspot_org_id | ||
| ) | ||
|
|
||
| # When | ||
| tracker.create_lead(staff_user, organisation) | ||
|
|
||
| # Then | ||
| mock_client.associate_contact_to_company.assert_not_called() | ||
|
|
||
|
|
||
| def test_register_hubspot_tracker_and_track_user__no_explicit_user__falls_back_to_request_user( | ||
| mocker: MockerFixture, staff_user: FFAdminUser, settings: SettingsWrapper | ||
| ) -> None: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's clean those
HUBSPOT_XXXfrom the settings please