From 78d20b3e2fcf7273511491c0414d571ffe0b7aa1 Mon Sep 17 00:00:00 2001 From: wadii Date: Tue, 25 Aug 2026 14:12:21 +0200 Subject: [PATCH 1/2] fix: identify user before sending warehouse test event --- .../__tests__/sendWarehouseTestEvent.test.ts | 8 ++++++-- .../tabs/warehouse-tab/sendWarehouseTestEvent.ts | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/frontend/web/components/pages/environment-settings/tabs/warehouse-tab/__tests__/sendWarehouseTestEvent.test.ts b/frontend/web/components/pages/environment-settings/tabs/warehouse-tab/__tests__/sendWarehouseTestEvent.test.ts index 0bd6b728a355..17de50bbdd4f 100644 --- a/frontend/web/components/pages/environment-settings/tabs/warehouse-tab/__tests__/sendWarehouseTestEvent.test.ts +++ b/frontend/web/components/pages/environment-settings/tabs/warehouse-tab/__tests__/sendWarehouseTestEvent.test.ts @@ -1,11 +1,12 @@ import sendWarehouseTestEvent from 'components/pages/environment-settings/tabs/warehouse-tab/sendWarehouseTestEvent' const init = jest.fn().mockResolvedValue(undefined) +const identify = jest.fn().mockResolvedValue(undefined) const trackEvent = jest.fn() const flushEvents = jest.fn().mockResolvedValue(undefined) jest.mock('@flagsmith/flagsmith/isomorphic', () => ({ - createFlagsmithInstance: () => ({ flushEvents, init, trackEvent }), + createFlagsmithInstance: () => ({ flushEvents, identify, init, trackEvent }), })) jest.mock('common/project', () => ({ @@ -16,6 +17,7 @@ jest.mock('common/project', () => ({ describe('sendWarehouseTestEvent', () => { beforeEach(() => { init.mockClear() + identify.mockClear() trackEvent.mockClear() flushEvents.mockClear() }) @@ -33,11 +35,13 @@ describe('sendWarehouseTestEvent', () => { ) }) - it('tracks the test_custom_event after init', async () => { + it('identifies a test user and tracks the test_custom_event after init', async () => { await sendWarehouseTestEvent('env-key-123') + expect(identify).toHaveBeenCalledWith('test_warehouse_user') expect(trackEvent).toHaveBeenCalledWith('test_custom_event') expect(init).toHaveBeenCalledTimes(1) + expect(identify).toHaveBeenCalledTimes(1) expect(trackEvent).toHaveBeenCalledTimes(1) }) diff --git a/frontend/web/components/pages/environment-settings/tabs/warehouse-tab/sendWarehouseTestEvent.ts b/frontend/web/components/pages/environment-settings/tabs/warehouse-tab/sendWarehouseTestEvent.ts index 2d670b117f3c..921538fa00f3 100644 --- a/frontend/web/components/pages/environment-settings/tabs/warehouse-tab/sendWarehouseTestEvent.ts +++ b/frontend/web/components/pages/environment-settings/tabs/warehouse-tab/sendWarehouseTestEvent.ts @@ -27,6 +27,7 @@ const sendWarehouseTestEvent = async (environmentId: string): Promise => { }, }), }) + await instance.identify('test_warehouse_user') instance.trackEvent('test_custom_event') await instance.flushEvents() } From cf7c963ef67a57294cfdbc28cfb6242e65191375 Mon Sep 17 00:00:00 2001 From: wadii Date: Tue, 25 Aug 2026 15:09:29 +0200 Subject: [PATCH 2/2] fix: use identity init option instead of separate identify call --- .../__tests__/sendWarehouseTestEvent.test.ts | 9 +++------ .../tabs/warehouse-tab/sendWarehouseTestEvent.ts | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/frontend/web/components/pages/environment-settings/tabs/warehouse-tab/__tests__/sendWarehouseTestEvent.test.ts b/frontend/web/components/pages/environment-settings/tabs/warehouse-tab/__tests__/sendWarehouseTestEvent.test.ts index 17de50bbdd4f..f515d2fd56af 100644 --- a/frontend/web/components/pages/environment-settings/tabs/warehouse-tab/__tests__/sendWarehouseTestEvent.test.ts +++ b/frontend/web/components/pages/environment-settings/tabs/warehouse-tab/__tests__/sendWarehouseTestEvent.test.ts @@ -1,12 +1,11 @@ import sendWarehouseTestEvent from 'components/pages/environment-settings/tabs/warehouse-tab/sendWarehouseTestEvent' const init = jest.fn().mockResolvedValue(undefined) -const identify = jest.fn().mockResolvedValue(undefined) const trackEvent = jest.fn() const flushEvents = jest.fn().mockResolvedValue(undefined) jest.mock('@flagsmith/flagsmith/isomorphic', () => ({ - createFlagsmithInstance: () => ({ flushEvents, identify, init, trackEvent }), + createFlagsmithInstance: () => ({ flushEvents, init, trackEvent }), })) jest.mock('common/project', () => ({ @@ -17,7 +16,6 @@ jest.mock('common/project', () => ({ describe('sendWarehouseTestEvent', () => { beforeEach(() => { init.mockClear() - identify.mockClear() trackEvent.mockClear() flushEvents.mockClear() }) @@ -30,18 +28,17 @@ describe('sendWarehouseTestEvent', () => { defaultFlags: {}, enableEvents: true, environmentID: 'env-key-123', + identity: 'test_warehouse_user', preventFetch: true, }), ) }) - it('identifies a test user and tracks the test_custom_event after init', async () => { + it('tracks the test_custom_event after init', async () => { await sendWarehouseTestEvent('env-key-123') - expect(identify).toHaveBeenCalledWith('test_warehouse_user') expect(trackEvent).toHaveBeenCalledWith('test_custom_event') expect(init).toHaveBeenCalledTimes(1) - expect(identify).toHaveBeenCalledTimes(1) expect(trackEvent).toHaveBeenCalledTimes(1) }) diff --git a/frontend/web/components/pages/environment-settings/tabs/warehouse-tab/sendWarehouseTestEvent.ts b/frontend/web/components/pages/environment-settings/tabs/warehouse-tab/sendWarehouseTestEvent.ts index 921538fa00f3..17d1db5c8d6e 100644 --- a/frontend/web/components/pages/environment-settings/tabs/warehouse-tab/sendWarehouseTestEvent.ts +++ b/frontend/web/components/pages/environment-settings/tabs/warehouse-tab/sendWarehouseTestEvent.ts @@ -20,6 +20,7 @@ const sendWarehouseTestEvent = async (environmentId: string): Promise => { enableEvents: true, environmentID: environmentId, fetch: globalThis.fetch.bind(globalThis), + identity: 'test_warehouse_user', preventFetch: true, ...(Project.flagsmithClientEventsAPI && { eventProcessorConfig: { @@ -27,7 +28,6 @@ const sendWarehouseTestEvent = async (environmentId: string): Promise => { }, }), }) - await instance.identify('test_warehouse_user') instance.trackEvent('test_custom_event') await instance.flushEvents() }