-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(cdp): Working customer.io destination (#24134)
- Loading branch information
1 parent
cdd4d73
commit d920015
Showing
6 changed files
with
212 additions
and
79 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
118 changes: 87 additions & 31 deletions
118
posthog/cdp/templates/customerio/test_template_customerio.py
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,42 +1,98 @@ | ||
from inline_snapshot import snapshot | ||
from posthog.cdp.templates.helpers import BaseHogFunctionTemplateTest | ||
from posthog.cdp.templates.customerio.template_customerio import template as template_customerio | ||
|
||
|
||
def create_inputs(**kwargs): | ||
inputs = { | ||
"site_id": "SITE_ID", | ||
"token": "TOKEN", | ||
"host": "track.customer.io", | ||
"action": "automatic", | ||
"include_all_properties": False, | ||
"identifiers": {"email": "[email protected]"}, | ||
"attributes": {"name": "example"}, | ||
} | ||
inputs.update(kwargs) | ||
|
||
return inputs | ||
|
||
|
||
class TestTemplateCustomerio(BaseHogFunctionTemplateTest): | ||
template = template_customerio | ||
|
||
def _inputs(self, **kwargs): | ||
inputs = { | ||
"site_id": "SITE_ID", | ||
"token": "TOKEN", | ||
"identifier": "[email protected]", | ||
"host": "track.customer.io", | ||
"properties": {"name": "example"}, | ||
} | ||
inputs.update(kwargs) | ||
return inputs | ||
|
||
def test_function_works(self): | ||
res = self.run_function(inputs=self._inputs()) | ||
|
||
assert res.result is None | ||
|
||
assert self.get_mock_fetch_calls()[0] == ( | ||
"https://track.customer.io/api/v2/entity", | ||
{ | ||
"method": "POST", | ||
"headers": { | ||
"User-Agent": "PostHog Customer.io App", | ||
"Authorization": "Basic U0lURV9JRDpUT0tFTg==", | ||
"Content-Type": "application/json", | ||
}, | ||
"body": { | ||
"type": "person", | ||
"identifiers": {"id": "[email protected]"}, | ||
"action": "identify", | ||
"attributes": { | ||
"name": "example", | ||
self.run_function( | ||
inputs=create_inputs(), | ||
globals={ | ||
"event": {"name": "$pageview", "properties": {"url": "https://example.com"}}, | ||
}, | ||
) | ||
|
||
assert self.get_mock_fetch_calls()[0] == snapshot( | ||
( | ||
"https://track.customer.io/api/v2/entity", | ||
{ | ||
"method": "POST", | ||
"headers": { | ||
"User-Agent": "PostHog Customer.io App", | ||
"Authorization": "Basic U0lURV9JRDpUT0tFTg==", | ||
"Content-Type": "application/json", | ||
}, | ||
"body": { | ||
"type": "person", | ||
"action": "page", | ||
"name": None, | ||
"identifiers": {"email": "[email protected]"}, | ||
"attributes": {"name": "example"}, | ||
"timestamp": 1704067200, | ||
}, | ||
}, | ||
}, | ||
) | ||
) | ||
|
||
def test_body_includes_all_properties_if_set(self): | ||
self.run_function(inputs=create_inputs(include_all_properties=False)) | ||
|
||
assert self.get_mock_fetch_calls()[0][1]["body"]["attributes"] == snapshot({"name": "example"}) | ||
|
||
self.run_function(inputs=create_inputs(include_all_properties=True)) | ||
|
||
assert self.get_mock_fetch_calls()[0][1]["body"]["attributes"] == snapshot( | ||
{"$current_url": "https://example.com", "name": "example"} | ||
) | ||
|
||
def test_automatic_action_mapping(self): | ||
for event_name, expected_action in [ | ||
("$identify", "identify"), | ||
("$pageview", "page"), | ||
("$screen", "screen"), | ||
("$autocapture", "event"), | ||
("custom", "event"), | ||
]: | ||
self.run_function( | ||
inputs=create_inputs(), | ||
globals={ | ||
"event": {"name": event_name, "properties": {"url": "https://example.com"}}, | ||
}, | ||
) | ||
|
||
assert self.get_mock_fetch_calls()[0][1]["body"]["action"] == expected_action | ||
|
||
def test_enforced_action(self): | ||
for event_name in [ | ||
"$identify", | ||
"$pageview", | ||
"$screen", | ||
"$autocapture", | ||
"custom", | ||
]: | ||
self.run_function( | ||
inputs=create_inputs(action="event"), | ||
globals={ | ||
"event": {"name": event_name, "properties": {"url": "https://example.com"}}, | ||
}, | ||
) | ||
|
||
assert self.get_mock_fetch_calls()[0][1]["body"]["action"] == "event" | ||
assert self.get_mock_fetch_calls()[0][1]["body"]["name"] == event_name |
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