Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion api/integrations/heap/heap.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
class HeapWrapper(AbstractBaseIdentityIntegrationWrapper): # type: ignore[type-arg]
def __init__(self, config: HeapConfiguration):
self.api_key = config.api_key
self.url = f"{config.base_url or DEFAULT_HEAP_API_URL}/api/track"
base_url = (config.base_url or DEFAULT_HEAP_API_URL).rstrip("/")
self.url = f"{base_url}/api/track"

def _identify_user(self, user_data: dict) -> None: # type: ignore[type-arg]
response = requests.post(self.url, json=user_data)
Expand Down
38 changes: 38 additions & 0 deletions api/tests/unit/integrations/heap/test_unit_heap.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
from features.models import FeatureState
from integrations.heap.heap import HeapWrapper
from integrations.heap.models import HeapConfiguration
from integrations.integration import identify_integrations

if typing.TYPE_CHECKING:
from pytest_mock import MockerFixture


@pytest.mark.django_db
Expand Down Expand Up @@ -58,3 +62,37 @@ def test_heap_wrapper__eu_base_url__uses_eu_url() -> None:

# Then
assert heap_wrapper.url == "https://eu.heapanalytics.com/api/track"


@pytest.mark.django_db
@pytest.mark.parametrize(
"base_url, expected_url",
[
(None, "https://heapanalytics.com/api/track"),
("", "https://heapanalytics.com/api/track"),
("https://eu.heapanalytics.com", "https://eu.heapanalytics.com/api/track"),
("https://eu.heapanalytics.com/", "https://eu.heapanalytics.com/api/track"),
],
)
def test_identify_integrations__heap_configured__posts_to_expected_url(
mocker: "MockerFixture",
environment: Environment,
identity: Identity,
base_url: str | None,
expected_url: str,
) -> None:
# Given
api_key = "abc-123"
HeapConfiguration.objects.create(
environment=environment,
api_key=api_key,
base_url=base_url,
)
mocked_post = mocker.patch("integrations.heap.heap.requests.post")

# When
identify_integrations(identity, identity.get_all_feature_states()) # type: ignore[no-untyped-call]

# Then
assert mocked_post.call_args.args[0] == expected_url
assert mocked_post.call_args.kwargs["json"]["app_id"] == api_key
Loading