Skip to content

Commit 017dab2

Browse files
author
Array
committed
chore(paths): add regression tests for pathReplacements default behavior
Add tests verifying that: - pathReplacements=None (omitted) applies team path cleaning filters - pathReplacements=False skips team path cleaning filters
1 parent e1ec04d commit 017dab2

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed

posthog/hogql_queries/insights/test/test_paths_query_runner.py

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -991,3 +991,79 @@ def test_paths_in_window(self):
991991
self.assertEqual(response[0].source, "1_/")
992992
self.assertEqual(response[0].target, "2_/about")
993993
self.assertEqual(response[0].value, 2)
994+
995+
@freeze_time("2012-01-15T03:21:34.000Z")
996+
def test_path_replacements_default_applies_team_cleaning(self):
997+
"""pathReplacements=None (omitted) should apply team path cleaning filters by default."""
998+
_create_person(team_id=self.team.pk, distinct_ids=["person_1"])
999+
_create_event(
1000+
properties={"$current_url": "/merchant/123/dashboard"},
1001+
distinct_id="person_1",
1002+
event="$pageview",
1003+
team=self.team,
1004+
timestamp="2012-01-14 03:21:34",
1005+
)
1006+
_create_event(
1007+
properties={"$current_url": "/merchant/456/dashboard"},
1008+
distinct_id="person_1",
1009+
event="$pageview",
1010+
team=self.team,
1011+
timestamp="2012-01-14 03:22:34",
1012+
)
1013+
1014+
self.team.path_cleaning_filters = [
1015+
{"alias": "/merchant/:id/dashboard", "regex": "/merchant/\\d+/dashboard"}
1016+
]
1017+
self.team.save()
1018+
1019+
# pathReplacements omitted (None) — team cleaning should apply
1020+
result = PathsQueryRunner(
1021+
query={
1022+
"kind": "PathsQuery",
1023+
"pathsFilter": {},
1024+
},
1025+
team=self.team,
1026+
).run()
1027+
assert isinstance(result, CachedPathsQueryResponse)
1028+
# Both URLs should be cleaned to the same path, so there's only one node
1029+
for r in result.results:
1030+
assert "123" not in r.source and "123" not in r.target
1031+
assert "456" not in r.source and "456" not in r.target
1032+
1033+
@freeze_time("2012-01-15T03:21:34.000Z")
1034+
def test_path_replacements_false_skips_team_cleaning(self):
1035+
"""pathReplacements=False should not apply team path cleaning filters."""
1036+
_create_person(team_id=self.team.pk, distinct_ids=["person_1"])
1037+
_create_event(
1038+
properties={"$current_url": "/merchant/123/dashboard"},
1039+
distinct_id="person_1",
1040+
event="$pageview",
1041+
team=self.team,
1042+
timestamp="2012-01-14 03:21:34",
1043+
)
1044+
_create_event(
1045+
properties={"$current_url": "/merchant/456/dashboard"},
1046+
distinct_id="person_1",
1047+
event="$pageview",
1048+
team=self.team,
1049+
timestamp="2012-01-14 03:22:34",
1050+
)
1051+
1052+
self.team.path_cleaning_filters = [
1053+
{"alias": "/merchant/:id/dashboard", "regex": "/merchant/\\d+/dashboard"}
1054+
]
1055+
self.team.save()
1056+
1057+
# pathReplacements explicitly False — team cleaning should NOT apply
1058+
result = PathsQueryRunner(
1059+
query={
1060+
"kind": "PathsQuery",
1061+
"pathsFilter": {"pathReplacements": False},
1062+
},
1063+
team=self.team,
1064+
).run()
1065+
assert isinstance(result, CachedPathsQueryResponse)
1066+
# URLs should remain uncleaned — distinct merchant IDs visible
1067+
sources_and_targets = [r.source + r.target for r in result.results]
1068+
combined = " ".join(sources_and_targets)
1069+
assert "123" in combined or "456" in combined

0 commit comments

Comments
 (0)