-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cdp): template migrations (#24940)
- Loading branch information
1 parent
51b77c5
commit 134833a
Showing
7 changed files
with
260 additions
and
38 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
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 |
---|---|---|
@@ -1,5 +1,9 @@ | ||
from inline_snapshot import snapshot | ||
|
||
from posthog.cdp.templates.helpers import BaseHogFunctionTemplateTest | ||
from posthog.cdp.templates.hubspot.template_hubspot import template as template_hubspot | ||
from posthog.cdp.templates.hubspot.template_hubspot import template as template_hubspot, TemplateHubspotMigrator | ||
from posthog.models import PluginConfig | ||
from posthog.test.base import BaseTest | ||
|
||
|
||
class TestTemplateHubspot(BaseHogFunctionTemplateTest): | ||
|
@@ -82,3 +86,47 @@ def mock_fetch(*args): | |
"body": {"properties": {"company": "PostHog", "email": "[email protected]"}}, | ||
}, | ||
) | ||
|
||
|
||
class TestTemplateMigration(BaseTest): | ||
def get_plugin_config(self, config: dict): | ||
_config = { | ||
"hubspotAccessToken": "toky", | ||
"triggeringEvents": "$identify,$set", | ||
"additionalPropertyMappings": "a:b", | ||
"ignoredEmails": "gmail.com", | ||
} | ||
_config.update(config) | ||
return PluginConfig(enabled=True, order=0, config=_config) | ||
|
||
def test_default_config(self): | ||
obj = self.get_plugin_config({}) | ||
template = TemplateHubspotMigrator.migrate(obj) | ||
assert template["inputs"] == snapshot( | ||
{ | ||
"access_token": {"value": "toky"}, | ||
"email": {"value": "{person.properties.email}"}, | ||
"properties": { | ||
"value": { | ||
"firstname": "{person.properties.firstname ?? person.properties.firstName ?? person.properties.first_name}", | ||
"lastname": "{person.properties.lastname ?? person.properties.lastName ?? person.properties.last_name}", | ||
"company": "{person.properties.company ?? person.properties.companyName ?? person.properties.company_name}", | ||
"phone": "{person.properties.phone ?? person.properties.phoneNumber ?? person.properties.phone_number}", | ||
"website": "{person.properties.website ?? person.properties.companyWebsite ?? person.properties.company_website}", | ||
"b": "{person.properties.a}", | ||
} | ||
}, | ||
} | ||
) | ||
assert template["filters"] == { | ||
"properties": [{"key": "email", "value": "gmail.com", "operator": "not_icontains", "type": "person"}], | ||
"events": [ | ||
{"id": "$identify", "name": "$identify", "type": "events", "properties": []}, | ||
{"id": "$set", "name": "$set", "type": "events", "properties": []}, | ||
], | ||
} | ||
assert template["inputs_schema"][0]["key"] == "access_token" | ||
assert template["inputs_schema"][0]["type"] == "string" | ||
assert template["inputs_schema"][0]["secret"] | ||
assert "inputs.oauth.access_token" not in template["hog"] | ||
assert "inputs.access_token" in template["hog"] |
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
Oops, something went wrong.