-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Add warning and conversion for number distinct_id (#993)
* Add warning and conversion for number distinct_id * Move test to unit test
- Loading branch information
Showing
3 changed files
with
56 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { v4 } from 'uuid' | ||
import { createPosthogInstance } from '../../functional_tests/posthog-instance' | ||
import { logger } from '../utils/logger' | ||
jest.mock('../utils/logger') | ||
|
||
describe('identify', () => { | ||
// Note that there are other tests for identify in posthog-core.identify.js | ||
// These are in the old style of tests, if you are feeling helpful you could | ||
// convert them to the new style in this file. | ||
|
||
it('should persist the distinct_id', async () => { | ||
// arrange | ||
const token = v4() | ||
const posthog = await createPosthogInstance(token) | ||
const distinctId = '123' | ||
|
||
// act | ||
posthog.identify(distinctId) | ||
|
||
// assert | ||
expect(posthog.persistence!.properties()['$user_id']).toEqual(distinctId) | ||
expect(jest.mocked(logger).error).toBeCalledTimes(0) | ||
}) | ||
|
||
it('should convert a numeric distinct_id to a string', async () => { | ||
// arrange | ||
const token = v4() | ||
const posthog = await createPosthogInstance(token) | ||
const distinctIdNum = 123 | ||
const distinctIdString = '123' | ||
|
||
// act | ||
posthog.identify(distinctIdNum as any) | ||
|
||
// assert | ||
expect(posthog.persistence!.properties()['$user_id']).toEqual(distinctIdString) | ||
expect(jest.mocked(logger).error).toBeCalledTimes(1) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters