Skip to content

Commit

Permalink
adding tests for the capture
Browse files Browse the repository at this point in the history
  • Loading branch information
surbhi-posthog committed Dec 4, 2024
1 parent b6a9cd4 commit 49116f1
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions posthog/api/test/test_organization_domain.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import datetime
from unittest.mock import patch
from unittest.mock import ANY, patch
from zoneinfo import ZoneInfo

import dns.resolver
Expand Down Expand Up @@ -84,7 +84,8 @@ def test_cannot_list_or_retrieve_domains_for_other_org(self):

# Create domains

def test_create_domain(self):
@patch("posthoganalytics.capture")
def test_create_domain(self, mock_capture):
self.organization_membership.level = OrganizationMembership.Level.ADMIN
self.organization.available_product_features = [
{"key": "automatic_provisioning", "name": "automatic_provisioning"}
Expand Down Expand Up @@ -116,6 +117,18 @@ def test_create_domain(self):
self.assertEqual(instance.last_verification_retry, None)
self.assertEqual(instance.sso_enforcement, "")

# Verify the domain creation capture event was called
mock_capture.assert_any_call(
self.user.distinct_id,
"organization domain created",
properties={
"domain": "the.posthog.com",
"jit_provisioning_enabled": False,
"sso_enforcement": None,
},
groups={"instance": ANY, "organization": str(self.organization.id)},
)

def test_cant_create_domain_without_feature(self):
self.organization_membership.level = OrganizationMembership.Level.ADMIN
self.organization_membership.save()
Expand Down

0 comments on commit 49116f1

Please sign in to comment.