Skip to content

Commit 78d20b3

Browse files
committed
fix: identify user before sending warehouse test event
1 parent 763938b commit 78d20b3

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

frontend/web/components/pages/environment-settings/tabs/warehouse-tab/__tests__/sendWarehouseTestEvent.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
import sendWarehouseTestEvent from 'components/pages/environment-settings/tabs/warehouse-tab/sendWarehouseTestEvent'
22

33
const init = jest.fn().mockResolvedValue(undefined)
4+
const identify = jest.fn().mockResolvedValue(undefined)
45
const trackEvent = jest.fn()
56
const flushEvents = jest.fn().mockResolvedValue(undefined)
67

78
jest.mock('@flagsmith/flagsmith/isomorphic', () => ({
8-
createFlagsmithInstance: () => ({ flushEvents, init, trackEvent }),
9+
createFlagsmithInstance: () => ({ flushEvents, identify, init, trackEvent }),
910
}))
1011

1112
jest.mock('common/project', () => ({
@@ -16,6 +17,7 @@ jest.mock('common/project', () => ({
1617
describe('sendWarehouseTestEvent', () => {
1718
beforeEach(() => {
1819
init.mockClear()
20+
identify.mockClear()
1921
trackEvent.mockClear()
2022
flushEvents.mockClear()
2123
})
@@ -33,11 +35,13 @@ describe('sendWarehouseTestEvent', () => {
3335
)
3436
})
3537

36-
it('tracks the test_custom_event after init', async () => {
38+
it('identifies a test user and tracks the test_custom_event after init', async () => {
3739
await sendWarehouseTestEvent('env-key-123')
3840

41+
expect(identify).toHaveBeenCalledWith('test_warehouse_user')
3942
expect(trackEvent).toHaveBeenCalledWith('test_custom_event')
4043
expect(init).toHaveBeenCalledTimes(1)
44+
expect(identify).toHaveBeenCalledTimes(1)
4145
expect(trackEvent).toHaveBeenCalledTimes(1)
4246
})
4347

frontend/web/components/pages/environment-settings/tabs/warehouse-tab/sendWarehouseTestEvent.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ const sendWarehouseTestEvent = async (environmentId: string): Promise<void> => {
2727
},
2828
}),
2929
})
30+
await instance.identify('test_warehouse_user')
3031
instance.trackEvent('test_custom_event')
3132
await instance.flushEvents()
3233
}

0 commit comments

Comments
 (0)