Skip to content

Commit

Permalink
add test for already-activated intent
Browse files Browse the repository at this point in the history
  • Loading branch information
raquelmsmith committed Oct 30, 2024
1 parent cc4113f commit 0e9da19
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
3 changes: 2 additions & 1 deletion posthog/api/team.py
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,8 @@ def add_product_intent(self, request: request.Request, *args, **kwargs):

product_intent, created = ProductIntent.objects.get_or_create(team=team, product_type=product_type)
if not created:
product_intent.check_and_update_activation()
if not product_intent.activated_at:
product_intent.check_and_update_activation()
product_intent.updated_at = datetime.now(tz=UTC)
product_intent.save()

Expand Down
25 changes: 25 additions & 0 deletions posthog/api/test/test_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -1096,6 +1096,31 @@ def test_can_update_product_intent_if_already_exists(
team=self.team,
)

@patch("posthog.api.team.calculate_product_activation.delay", MagicMock())
@patch("posthog.models.product_intent.ProductIntent.check_and_update_activation")
@patch("posthog.api.project.report_user_action")
@patch("posthog.api.team.report_user_action")
@freeze_time("2024-01-05T00:00:00Z")
def test_doesnt_send_event_for_already_activated_intent(
self,
mock_report_user_action: MagicMock,
mock_report_user_action_legacy_endpoint: MagicMock,
mock_check_and_update_activation: MagicMock,
) -> None:
ProductIntent.objects.create(
team=self.team, product_type="product_analytics", activated_at=datetime(2024, 1, 1, 0, 0, 0, tzinfo=UTC)
)
if self.client_class is EnvironmentToProjectRewriteClient:
mock_report_user_action = mock_report_user_action_legacy_endpoint
response = self.client.patch(
f"/api/environments/{self.team.id}/add_product_intent/",
{"product_type": "product_analytics"},
headers={"Referer": "https://posthogtest.com/my-url", "X-Posthog-Session-Id": "test_session_id"},
)
assert response.status_code == status.HTTP_201_CREATED
mock_check_and_update_activation.assert_not_called()
mock_report_user_action.assert_not_called()

@patch("posthog.api.project.report_user_action")
@patch("posthog.api.team.report_user_action")
def test_can_complete_product_onboarding(
Expand Down

0 comments on commit 0e9da19

Please sign in to comment.