From 04d783d801111978cdf95f45048d888dfb5891ee Mon Sep 17 00:00:00 2001 From: Robbie Coomber Date: Tue, 26 Nov 2024 21:36:32 +0000 Subject: [PATCH] Add tests for initial person info --- src/__tests__/posthog-persistence.test.ts | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/__tests__/posthog-persistence.test.ts b/src/__tests__/posthog-persistence.test.ts index 086246e24..dbd0158d3 100644 --- a/src/__tests__/posthog-persistence.test.ts +++ b/src/__tests__/posthog-persistence.test.ts @@ -1,6 +1,6 @@ /// import { PostHogPersistence } from '../posthog-persistence' -import { SESSION_ID, USER_STATE } from '../constants' +import { INITIAL_PERSON_INFO, SESSION_ID, USER_STATE } from '../constants' import { PostHogConfig } from '../types' import Mock = jest.Mock import { PostHog } from '../posthog-core' @@ -160,6 +160,15 @@ describe('persistence', () => { })}` ) + lib.register({ [INITIAL_PERSON_INFO]: { u: 'https://www.example.com', r: 'https://www.referrer.com' } }) + expect(document.cookie).toContain( + `ph__posthog=${encode({ + distinct_id: 'test', + $sesid: [1000, 'sid', 2000], + $initial_person_info: { u: 'https://www.example.com', r: 'https://www.referrer.com' }, + })}` + ) + // Clear localstorage to simulate being on a different domain localStorage.clear() @@ -168,6 +177,7 @@ describe('persistence', () => { expect(newLib.props).toEqual({ distinct_id: 'test', $sesid: [1000, 'sid', 2000], + $initial_person_info: { u: 'https://www.example.com', r: 'https://www.referrer.com' }, }) })