-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: push user id and device id changes to analytics connector (#342)
* fix: push user id and device id changes to analytics connector * test: add tests for analytics-connector --------- Co-authored-by: Kevin Pagtakhan <kevinp@amplitude.com>
- Loading branch information
1 parent
cbcbf1b
commit 3214b08
Showing
6 changed files
with
91 additions
and
27 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
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
67 changes: 67 additions & 0 deletions
67
packages/analytics-client-common/test/analytics-connector.test.ts
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,67 @@ | ||
import { AnalyticsConnector } from '@amplitude/analytics-connector'; | ||
import { getAnalyticsConnector, setConnectorDeviceId, setConnectorUserId } from '../src/analytics-connector'; | ||
|
||
describe('analytics-connector', () => { | ||
describe('getAnalyticsConnector', () => { | ||
test('should return connector instance', () => { | ||
const instance = new AnalyticsConnector(); | ||
const getInstance = jest.spyOn(AnalyticsConnector, 'getInstance').mockReturnValueOnce(instance); | ||
expect(getAnalyticsConnector()).toBe(instance); | ||
expect(getInstance).toHaveBeenCalledTimes(1); | ||
}); | ||
}); | ||
|
||
describe('setConnectorUserId', () => { | ||
test('should return connector instance', () => { | ||
const commit = jest.fn(); | ||
const identityEditor = { | ||
setUserId: function () { | ||
return this; | ||
}, | ||
setDeviceId: function () { | ||
return this; | ||
}, | ||
setUserProperties: function () { | ||
return this; | ||
}, | ||
updateUserProperties: function () { | ||
return this; | ||
}, | ||
commit, | ||
}; | ||
const instance = new AnalyticsConnector(); | ||
jest.spyOn(instance.identityStore, 'editIdentity').mockReturnValueOnce(identityEditor); | ||
const getInstance = jest.spyOn(AnalyticsConnector, 'getInstance').mockReturnValueOnce(instance); | ||
expect(setConnectorUserId('123')).toBe(undefined); | ||
expect(getInstance).toHaveBeenCalledTimes(1); | ||
expect(commit).toHaveBeenCalledTimes(1); | ||
}); | ||
}); | ||
|
||
describe('setConnectorDeviceId', () => { | ||
test('should return connector instance', () => { | ||
const commit = jest.fn(); | ||
const identityEditor = { | ||
setUserId: function () { | ||
return this; | ||
}, | ||
setDeviceId: function () { | ||
return this; | ||
}, | ||
setUserProperties: function () { | ||
return this; | ||
}, | ||
updateUserProperties: function () { | ||
return this; | ||
}, | ||
commit, | ||
}; | ||
const instance = new AnalyticsConnector(); | ||
jest.spyOn(instance.identityStore, 'editIdentity').mockReturnValueOnce(identityEditor); | ||
const getInstance = jest.spyOn(AnalyticsConnector, 'getInstance').mockReturnValueOnce(instance); | ||
expect(setConnectorDeviceId('123')).toBe(undefined); | ||
expect(getInstance).toHaveBeenCalledTimes(1); | ||
expect(commit).toHaveBeenCalledTimes(1); | ||
}); | ||
}); | ||
}); |
13 changes: 0 additions & 13 deletions
13
packages/analytics-client-common/test/analytics-connector.ts
This file was deleted.
Oops, something went wrong.
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