diff --git a/posthog/api/test/test_hog_function.py b/posthog/api/test/test_hog_function.py index 23b33ff5f91a4..50c4244c8cbfb 100644 --- a/posthog/api/test/test_hog_function.py +++ b/posthog/api/test/test_hog_function.py @@ -1,5 +1,5 @@ import json -from typing import Optional +from typing import Any, Optional from unittest.mock import ANY, patch from rest_framework import status @@ -552,3 +552,62 @@ def test_patches_status_on_enabled_update(self, *args): f"http://localhost:6738/api/projects/{self.team.id}/hog_functions/{response.json()['id']}/status", json={"state": 2}, ) + + @patch("posthog.permissions.posthoganalytics.feature_enabled", return_value=True) + def test_list_with_filters_filter(self, *args): + action1 = Action.objects.create( + team=self.team, + name="test action", + steps_json=[{"event": "$pageview", "url": "docs", "url_matching": "contains"}], + ) + + action2 = Action.objects.create( + team=self.team, + name="test action", + steps_json=[{"event": "$pageview", "url": "docs", "url_matching": "contains"}], + ) + + self.team.test_account_filters = [ + { + "key": "email", + "value": "@posthog.com", + "operator": "not_icontains", + "type": "person", + } + ] + self.team.save() + response = self.client.post( + f"/api/projects/{self.team.id}/hog_functions/", + data={ + **EXAMPLE_FULL, + "filters": { + "events": [{"id": "$pageview", "name": "$pageview", "type": "events", "order": 0}], + "actions": [ + {"id": f"{action1.id}", "name": "Test Action", "type": "actions", "order": 1}, + {"id": f"{action2.id}", "name": "Test Action", "type": "actions", "order": 1}, + ], + "filter_test_accounts": True, + }, + }, + ) + assert response.status_code == status.HTTP_201_CREATED, response.json() + + filters: Any = {"filter_test_accounts": True} + response = self.client.get(f"/api/projects/{self.team.id}/hog_functions/?filters={json.dumps(filters)}") + assert len(response.json()["results"]) == 1 + + filters = {"filter_test_accounts": False} + response = self.client.get(f"/api/projects/{self.team.id}/hog_functions/?filters={json.dumps(filters)}") + assert len(response.json()["results"]) == 0 + + filters = {"actions": [{"id": f"other"}]} + response = self.client.get(f"/api/projects/{self.team.id}/hog_functions/?filters={json.dumps(filters)}") + assert len(response.json()["results"]) == 0 + + filters = {"actions": [{"id": f"{action1.id}"}]} + response = self.client.get(f"/api/projects/{self.team.id}/hog_functions/?filters={json.dumps(filters)}") + assert len(response.json()["results"]) == 1 + + filters = {"actions": [{"id": f"{action2.id}"}]} + response = self.client.get(f"/api/projects/{self.team.id}/hog_functions/?filters={json.dumps(filters)}") + assert len(response.json()["results"]) == 1