-
Notifications
You must be signed in to change notification settings - Fork 429
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add domain to Hubspot company (#3648)
- Loading branch information
Showing
4 changed files
with
138 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,8 +19,102 @@ def test_hubspot_with_new_contact_and_new_organisation( | |
) -> None: | ||
# Given | ||
settings.ENABLE_HUBSPOT_LEAD_TRACKING = True | ||
domain = "example.com" | ||
user = FFAdminUser.objects.create( | ||
email="[email protected]", | ||
email=f"new.user@{domain}", | ||
first_name="Frank", | ||
last_name="Louis", | ||
marketing_consent_given=True, | ||
) | ||
|
||
future_hubspot_id = "10280696017" | ||
mock_create_company = mocker.patch( | ||
"integrations.lead_tracking.hubspot.client.HubspotClient.create_company", | ||
return_value={ | ||
"id": future_hubspot_id, | ||
"properties": { | ||
"createdate": "2024-02-26T19:41:57.959Z", | ||
"hs_lastmodifieddate": "2024-02-26T19:41:57.959Z", | ||
"hs_object_id": future_hubspot_id, | ||
"hs_object_source": "INTEGRATION", | ||
"hs_object_source_id": "2902325", | ||
"hs_object_source_label": "INTEGRATION", | ||
"name": organisation.name, | ||
}, | ||
"properties_with_history": None, | ||
"created_at": datetime.datetime(2024, 2, 26, 19, 41, 57, 959000), | ||
"updated_at": datetime.datetime(2024, 2, 26, 19, 41, 57, 959000), | ||
"archived": False, | ||
"archived_at": None, | ||
}, | ||
) | ||
|
||
mock_get_contact = mocker.patch( | ||
"integrations.lead_tracking.hubspot.client.HubspotClient.get_contact", | ||
return_value=None, | ||
) | ||
|
||
mock_create_contact = mocker.patch( | ||
"integrations.lead_tracking.hubspot.client.HubspotClient.create_contact", | ||
return_value={ | ||
"archived": False, | ||
"archived_at": None, | ||
"created_at": datetime.datetime(2024, 2, 26, 20, 2, 50, 69000), | ||
"id": "1000551", | ||
"properties": { | ||
"createdate": "2024-02-26T20:02:50.069Z", | ||
"email": user.email, | ||
"firstname": user.first_name, | ||
"hs_all_contact_vids": "1000551", | ||
"hs_email_domain": "example.com", | ||
"hs_is_contact": "true", | ||
"hs_is_unworked": "true", | ||
"hs_marketable_status": user.marketing_consent_given, | ||
"hs_object_id": "1000551", | ||
"hs_object_source": "INTEGRATION", | ||
"hs_object_source_id": "2902325", | ||
"hs_object_source_label": "INTEGRATION", | ||
"hs_pipeline": "contacts-lifecycle-pipeline", | ||
"lastmodifieddate": "2024-02-26T20:02:50.069Z", | ||
"lastname": user.last_name, | ||
}, | ||
"properties_with_history": None, | ||
"updated_at": datetime.datetime(2024, 2, 26, 20, 2, 50, 69000), | ||
}, | ||
) | ||
|
||
assert getattr(organisation, "hubspot_organisation", None) is None | ||
# When | ||
user.add_organisation(organisation, role=OrganisationRole.ADMIN) | ||
|
||
# Then | ||
organisation.refresh_from_db() | ||
assert organisation.hubspot_organisation.hubspot_id == future_hubspot_id | ||
|
||
mock_create_company.assert_called_once_with( | ||
name=organisation.name, | ||
domain=domain, | ||
active_subscription="free", | ||
organisation_id=organisation.id, | ||
) | ||
mock_create_contact.assert_called_once_with(user, future_hubspot_id) | ||
mock_get_contact.assert_called_once_with(user) | ||
|
||
|
||
def test_hubspot_with_filtered_email_domain_contact_and_new_organisation( | ||
organisation: Organisation, | ||
settings: SettingsWrapper, | ||
mocker: MockerFixture, | ||
) -> None: | ||
# Given | ||
settings.ENABLE_HUBSPOT_LEAD_TRACKING = True | ||
domain = "example.com" | ||
|
||
# Setting that will filter out the domain for the user. | ||
settings.HUBSPOT_IGNORE_ORGANISATION_DOMAINS = [domain] | ||
|
||
user = FFAdminUser.objects.create( | ||
email=f"new.user@{domain}", | ||
first_name="Frank", | ||
last_name="Louis", | ||
marketing_consent_given=True, | ||
|
@@ -89,8 +183,10 @@ def test_hubspot_with_new_contact_and_new_organisation( | |
# Then | ||
organisation.refresh_from_db() | ||
assert organisation.hubspot_organisation.hubspot_id == future_hubspot_id | ||
# Domain is `None` since it was filtered out. | ||
mock_create_company.assert_called_once_with( | ||
name=organisation.name, | ||
domain=None, | ||
active_subscription="free", | ||
organisation_id=organisation.id, | ||
) | ||
|