Skip to content
Closed
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
13 changes: 12 additions & 1 deletion posthog/api/test/test_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -1686,9 +1686,18 @@ def test_modifiers_customBotDefinitions_validation(
else:
assert response.status_code == status.HTTP_400_BAD_REQUEST, response.json()

@parameterized.expand([("approved", True, True), ("opted_out", False, False), ("unset", None, False)])
@patch("posthog.event_usage.report_user_action")
@time_machine.travel("2024-01-01T00:00:00Z", tick=False)
def test_can_add_product_intent(self, mock_report_user_action: MagicMock) -> None:
def test_can_add_product_intent(
self,
_name: str,
organization_consent: bool | None,
reported_consent: bool,
mock_report_user_action: MagicMock,
) -> None:
self.organization.is_ai_data_processing_approved = organization_consent
self.organization.save(update_fields=["is_ai_data_processing_approved"])
response = self.client.patch(
f"/api/environments/{self.team.id}/add_product_intent/",
{"product_type": "product_analytics", "intent_context": "onboarding product selected - primary"},
Expand All @@ -1710,6 +1719,7 @@ def test_can_add_product_intent(self, mock_report_user_action: MagicMock) -> Non
"is_first_intent_for_product": True,
"intent_created_at": datetime(2024, 1, 1, 0, 0, 0, tzinfo=UTC),
"intent_updated_at": datetime(2024, 1, 1, 0, 0, 0, tzinfo=UTC),
"is_ai_data_processing_approved": reported_consent,
"realm": get_instance_realm(),
},
team=self.team,
Expand Down Expand Up @@ -1756,6 +1766,7 @@ def test_can_update_product_intent_if_already_exists(
"is_first_intent_for_product": False,
"intent_created_at": datetime(2024, 1, 1, 0, 0, 0, tzinfo=UTC),
"intent_updated_at": datetime(2024, 1, 2, 0, 0, 0, tzinfo=UTC),
"is_ai_data_processing_approved": True,
"realm": get_instance_realm(),
},
team=self.team,
Expand Down
1 change: 1 addition & 0 deletions posthog/models/product_intent/product_intent.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ def register(
"is_first_intent_for_product": created,
"intent_created_at": product_intent.created_at,
"intent_updated_at": product_intent.updated_at,
"is_ai_data_processing_approved": team.organization.is_ai_data_processing_approved is True,
"realm": get_instance_realm(),
},
team=team,
Expand Down
4 changes: 4 additions & 0 deletions posthog/models/test/test_product_intent.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ def test_register_reports_correct_user_action_for_onboarding(self, mock_report_u
"is_first_intent_for_product": True,
"intent_created_at": datetime(2024, 1, 1, 12, 0, 0, tzinfo=UTC),
"intent_updated_at": datetime(2024, 1, 1, 12, 0, 0, tzinfo=UTC),
"is_ai_data_processing_approved": True,
"realm": get_instance_realm(),
},
team=self.team,
Expand Down Expand Up @@ -387,6 +388,7 @@ def test_register_reports_correct_user_action_for_non_onboarding(self, mock_repo
"is_first_intent_for_product": True,
"intent_created_at": datetime(2024, 1, 1, 12, 0, 0, tzinfo=UTC),
"intent_updated_at": datetime(2024, 1, 1, 12, 0, 0, tzinfo=UTC),
"is_ai_data_processing_approved": True,
"realm": get_instance_realm(),
},
team=self.team,
Expand Down Expand Up @@ -421,6 +423,7 @@ def test_register_managed_warehouse_intent(self, mock_report_user_action):
"is_first_intent_for_product": True,
"intent_created_at": datetime(2024, 1, 1, 12, 0, 0, tzinfo=UTC),
"intent_updated_at": datetime(2024, 1, 1, 12, 0, 0, tzinfo=UTC),
"is_ai_data_processing_approved": True,
"realm": get_instance_realm(),
},
team=self.team,
Expand Down Expand Up @@ -572,6 +575,7 @@ def test_register_tracks_intent_even_when_already_activated(self, mock_report_us
"is_first_intent_for_product": False,
"intent_created_at": intent.created_at,
"intent_updated_at": intent.updated_at,
"is_ai_data_processing_approved": True,
"realm": get_instance_realm(),
},
team=self.team,
Expand Down
Loading