diff --git a/posthog/session_recordings/test/__snapshots__/test_session_recordings.ambr b/posthog/session_recordings/test/__snapshots__/test_session_recordings.ambr index fad3c08168d0b..d5a3675a2c2ca 100644 --- a/posthog/session_recordings/test/__snapshots__/test_session_recordings.ambr +++ b/posthog/session_recordings/test/__snapshots__/test_session_recordings.ambr @@ -778,7 +778,31 @@ FROM "posthog_persondistinctid" INNER JOIN "posthog_person" ON ("posthog_persondistinctid"."person_id" = "posthog_person"."id") WHERE ("posthog_persondistinctid"."distinct_id" IN ('user2', - 'user_one_2') + 'user_one_0') + AND "posthog_persondistinctid"."team_id" = 2) /*controller='project_session_recordings-list',route='api/projects/%28%3FP%3Cparent_lookup_team_id%3E%5B%5E/.%5D%2B%29/session_recordings/%3F%24'*/ + ''' +# --- +# name: TestSessionRecordings.test_get_session_recordings.36 + ''' + SELECT "posthog_persondistinctid"."id", + "posthog_persondistinctid"."team_id", + "posthog_persondistinctid"."person_id", + "posthog_persondistinctid"."distinct_id", + "posthog_persondistinctid"."version", + "posthog_person"."id", + "posthog_person"."created_at", + "posthog_person"."properties_last_updated_at", + "posthog_person"."properties_last_operation", + "posthog_person"."team_id", + "posthog_person"."properties", + "posthog_person"."is_user_id", + "posthog_person"."is_identified", + "posthog_person"."uuid", + "posthog_person"."version" + FROM "posthog_persondistinctid" + INNER JOIN "posthog_person" ON ("posthog_persondistinctid"."person_id" = "posthog_person"."id") + WHERE ("posthog_persondistinctid"."distinct_id" IN ('user2', + 'user_one_0') AND "posthog_persondistinctid"."team_id" = 2) /*controller='project_session_recordings-list',route='api/projects/%28%3FP%3Cparent_lookup_team_id%3E%5B%5E/.%5D%2B%29/session_recordings/%3F%24'*/ ''' # --- diff --git a/posthog/session_recordings/test/test_session_recordings.py b/posthog/session_recordings/test/test_session_recordings.py index a28d1ef4538ba..1eb5f2f466ff0 100644 --- a/posthog/session_recordings/test/test_session_recordings.py +++ b/posthog/session_recordings/test/test_session_recordings.py @@ -61,6 +61,9 @@ def create_snapshot( ) @snapshot_postgres_queries + # we can't take snapshots of the CH queries + # because we use `now()` in the CH queries which don't know about any frozen time + # @snapshot_clickhouse_queries def test_get_session_recordings(self): twelve_distinct_ids: List[str] = [f"user_one_{i}" for i in range(12)] @@ -78,8 +81,8 @@ def test_get_session_recordings(self): base_time = (now() - relativedelta(days=1)).replace(microsecond=0) session_id_one = f"test_get_session_recordings-1" self.create_snapshot("user_one_0", session_id_one, base_time) - self.create_snapshot("user_one_1", session_id_one, base_time + relativedelta(seconds=10)) - self.create_snapshot("user_one_2", session_id_one, base_time + relativedelta(seconds=30)) + self.create_snapshot("user_one_0", session_id_one, base_time + relativedelta(seconds=10)) + self.create_snapshot("user_one_0", session_id_one, base_time + relativedelta(seconds=30)) session_id_two = f"test_get_session_recordings-2" self.create_snapshot("user2", session_id_two, base_time + relativedelta(seconds=20)) @@ -125,6 +128,44 @@ def test_get_session_recordings(self): assert results_[0]["distinct_id"] == "user2" assert results_[1]["distinct_id"] in twelve_distinct_ids + def test_can_list_recordings_even_when_the_person_has_multiple_distinct_ids(self): + # almost duplicate of test_get_session_recordings above + # but if we have multiple distinct ids on a recording the snapshot + # varies which makes the snapshot useless + twelve_distinct_ids: List[str] = [f"user_one_{i}" for i in range(12)] + + Person.objects.create( + team=self.team, + distinct_ids=twelve_distinct_ids, # that's too many! we should limit them + properties={"$some_prop": "something", "email": "bob@bob.com"}, + ) + Person.objects.create( + team=self.team, + distinct_ids=["user2"], + properties={"$some_prop": "something", "email": "bob@bob.com"}, + ) + + base_time = (now() - relativedelta(days=1)).replace(microsecond=0) + session_id_one = f"test_get_session_recordings-1" + self.create_snapshot("user_one_0", session_id_one, base_time) + self.create_snapshot("user_one_1", session_id_one, base_time + relativedelta(seconds=10)) + self.create_snapshot("user_one_2", session_id_one, base_time + relativedelta(seconds=30)) + session_id_two = f"test_get_session_recordings-2" + self.create_snapshot("user2", session_id_two, base_time + relativedelta(seconds=20)) + + response = self.client.get(f"/api/projects/{self.team.id}/session_recordings") + self.assertEqual(response.status_code, status.HTTP_200_OK) + response_data = response.json() + + results_ = response_data["results"] + assert results_ is not None + # detailed assertion is in the other test + assert len(results_) == 2 + + # user distinct id varies because we're adding more than one + assert results_[0]["distinct_id"] == "user2" + assert results_[1]["distinct_id"] in twelve_distinct_ids + @patch("posthog.session_recordings.session_recording_api.SessionRecordingListFromReplaySummary") def test_console_log_filters_are_correctly_passed_to_listing(self, mock_summary_lister): mock_summary_lister.return_value.run.return_value = ([], False)