-
Notifications
You must be signed in to change notification settings - Fork 57
test: updated setup for identity tests #1105
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 17 commits
0b41099
600d90a
46d2c3b
c0fb30e
6e80ee6
a4c5c44
f691539
b245b05
1eb173b
4e4de0b
b2ab345
71302f9
301d5f9
f537ab7
00fad32
c738b43
01a78d8
62aef29
45b9892
2b49b0a
cf63920
ea95636
e0032c7
565cec7
32e35f3
1dec717
1dc590e
fa332dd
2c02bcd
9c90192
705e462
7eb53bc
088aa6c
6dea100
acfaa82
e4ee4e5
11bf973
9952a4d
c6fdceb
3ad0a46
13c3454
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -593,7 +593,7 @@ var pluses = /\+/g, | |
| }, | ||
| waitForCondition = function async( | ||
| conditionFn, | ||
| timeout = 200, | ||
| timeout = 2000, | ||
|
||
| interval = 10 | ||
| ) { | ||
| return new Promise((resolve, reject) => { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -53,11 +53,14 @@ const BAD_USER_ATTRIBUTE_KEY_AS_ARRAY = ([ | |
|
|
||
| const BAD_USER_ATTRIBUTE_LIST_VALUE = (1234 as unknown) as UserAttributesValue[]; | ||
|
|
||
| describe('identities and attributes', function() { | ||
| describe.only('identities and attributes', function() { | ||
| let beforeEachCallbackCalled = false; | ||
| let hasBeforeEachCallbackReturned; | ||
|
|
||
| beforeEach(function() { | ||
| mParticle._resetForTests(MPConfig); | ||
| fetchMock.config.overwriteRoutes = true; | ||
|
|
||
| fetchMockSuccess(urls.identify, { | ||
| mpid: testMPID, is_logged_in: false | ||
| }); | ||
|
|
@@ -82,7 +85,6 @@ describe('identities and attributes', function() { | |
| }); | ||
|
|
||
| it('should set user attribute', async () => { | ||
| mParticle._resetForTests(MPConfig); | ||
| const mockForwarder = new MockForwarder(); | ||
|
|
||
| mockForwarder.register(window.mParticle.config); | ||
|
|
@@ -104,7 +106,6 @@ describe('identities and attributes', function() { | |
| }); | ||
|
|
||
| it('should set user attribute be case insensitive', async () => { | ||
| mParticle._resetForTests(MPConfig); | ||
| const mockForwarder = new MockForwarder(); | ||
|
|
||
| mockForwarder.register(window.mParticle.config); | ||
|
|
@@ -140,7 +141,6 @@ describe('identities and attributes', function() { | |
| }); | ||
|
|
||
| it('should set multiple user attributes with setUserAttributes', async () => { | ||
| mParticle._resetForTests(MPConfig); | ||
| const mockForwarder = new MockForwarder(); | ||
|
|
||
| mockForwarder.register(window.mParticle.config); | ||
|
|
@@ -165,7 +165,6 @@ describe('identities and attributes', function() { | |
| }); | ||
|
|
||
| it('should remove user attribute', async () => { | ||
| mParticle._resetForTests(MPConfig); | ||
| const mockForwarder = new MockForwarder(); | ||
|
|
||
| mockForwarder.register(window.mParticle.config); | ||
|
|
@@ -183,7 +182,6 @@ describe('identities and attributes', function() { | |
| }); | ||
|
|
||
| it('should remove user attribute case insensitive', async () => { | ||
| mParticle._resetForTests(MPConfig); | ||
| const mockForwarder = new MockForwarder(); | ||
|
|
||
| mockForwarder.register(window.mParticle.config); | ||
|
|
@@ -383,8 +381,6 @@ describe('identities and attributes', function() { | |
| }); | ||
|
|
||
| it('should set user attribute list', async () => { | ||
| mParticle._resetForTests(MPConfig); | ||
|
|
||
| mParticle.init(apiKey, window.mParticle.config); | ||
| await waitForCondition(hasIdentifyReturned); | ||
| mParticle.Identity.getCurrentUser().setUserAttributeList('numbers', [ | ||
|
|
@@ -409,8 +405,6 @@ describe('identities and attributes', function() { | |
| }); | ||
|
|
||
| it('should set user attribute list case insensitive', async () => { | ||
| mParticle._resetForTests(MPConfig); | ||
|
|
||
| mParticle.init(apiKey, window.mParticle.config); | ||
| await waitForCondition(hasIdentifyReturned); | ||
| mParticle.Identity.getCurrentUser().setUserAttributeList('numbers', [ | ||
|
|
@@ -463,8 +457,6 @@ describe('identities and attributes', function() { | |
| it('should make a copy of user attribute list', async () => { | ||
| const list = [1, 2, 3, 4, 5]; | ||
|
|
||
| mParticle._resetForTests(MPConfig); | ||
|
|
||
| mParticle.init(apiKey, window.mParticle.config); | ||
|
|
||
| await waitForCondition(hasIdentifyReturned); | ||
|
|
@@ -489,8 +481,6 @@ describe('identities and attributes', function() { | |
| }); | ||
|
|
||
| it('should remove all user attributes', async () => { | ||
| mParticle._resetForTests(MPConfig); | ||
|
|
||
| mParticle.init(apiKey, window.mParticle.config); | ||
| await waitForCondition(hasIdentifyReturned); | ||
| mParticle.Identity.getCurrentUser().setUserAttributeList('numbers', [ | ||
|
|
@@ -513,7 +503,6 @@ describe('identities and attributes', function() { | |
| }); | ||
|
|
||
| it('should get user attribute lists', async () => { | ||
| mParticle._resetForTests(MPConfig); | ||
|
|
||
| mParticle.init(apiKey, window.mParticle.config); | ||
|
|
||
|
|
@@ -535,7 +524,6 @@ describe('identities and attributes', function() { | |
| }); | ||
|
|
||
| it('should copy when calling get user attribute lists', async () => { | ||
| mParticle._resetForTests(MPConfig); | ||
| mParticle.init(apiKey, window.mParticle.config); | ||
|
|
||
| await waitForCondition(hasIdentifyReturned); | ||
|
|
@@ -557,7 +545,6 @@ describe('identities and attributes', function() { | |
| }); | ||
|
|
||
| it('should copy when calling get user attributes', async () => { | ||
| mParticle._resetForTests(MPConfig); | ||
| mParticle.init(apiKey, window.mParticle.config); | ||
| await waitForCondition(hasIdentifyReturned); | ||
| mParticle.Identity.getCurrentUser().setUserAttribute('gender', 'male'); | ||
|
|
@@ -581,8 +568,6 @@ describe('identities and attributes', function() { | |
| }); | ||
|
|
||
| it('should get all user attributes', async () => { | ||
| mParticle._resetForTests(MPConfig); | ||
|
|
||
| mParticle.init(apiKey, window.mParticle.config); | ||
| await waitForCondition(hasIdentifyReturned); | ||
| mParticle.Identity.getCurrentUser().setUserAttribute('test', '123'); | ||
|
|
@@ -598,7 +583,6 @@ describe('identities and attributes', function() { | |
| }); | ||
|
|
||
| it('should not set user attribute list if value is not array', async () => { | ||
| mParticle._resetForTests(MPConfig); | ||
| mParticle.init(apiKey, window.mParticle.config); | ||
| await waitForCondition(hasIdentifyReturned); | ||
| mParticle.Identity.getCurrentUser().setUserAttributeList( | ||
|
|
@@ -709,8 +693,6 @@ describe('identities and attributes', function() { | |
| }); | ||
|
|
||
| it('should send user attribute change requests when setting new attributes', async () => { | ||
| mParticle._resetForTests(MPConfig); | ||
|
|
||
| mParticle.init(apiKey, window.mParticle.config); | ||
| await waitForCondition(hasIdentifyReturned); | ||
| // set a new attribute, age | ||
|
|
@@ -823,8 +805,6 @@ describe('identities and attributes', function() { | |
| }); | ||
|
|
||
| it('should send user attribute change requests for the MPID it is being set on', async () => { | ||
| mParticle._resetForTests(MPConfig); | ||
|
|
||
| mParticle.init(apiKey, window.mParticle.config); | ||
| await waitForCondition(hasIdentifyReturned); | ||
|
|
||
|
|
@@ -917,9 +897,8 @@ describe('identities and attributes', function() { | |
| delete window.mParticle.config.flags; | ||
| }); | ||
|
|
||
| // https://go/j-SDKE-420 - Intermittently fails in Firefox due to timing | ||
| it('should send user identity change requests when setting new identities on new users', async () => { | ||
| mParticle._resetForTests(MPConfig); | ||
|
|
||
| fetchMock.resetHistory(); | ||
|
|
||
| window.mParticle.config.identifyRequest = { | ||
|
|
@@ -1004,11 +983,11 @@ describe('identities and attributes', function() { | |
| }); | ||
|
|
||
| mParticle.Identity.modify(modifyUser); | ||
| await waitForCondition(() => { | ||
| return ( | ||
| mParticle.getInstance()._Store.identityCallInFlight === false | ||
| ); | ||
| }); | ||
| await waitForCondition(() => { | ||
| return ( | ||
| mParticle.getInstance()._Store.identityCallInFlight === false | ||
| ); | ||
| }); | ||
| const body2 = JSON.parse(`${fetchMock.lastOptions().body}`); | ||
| expect(body2.mpid).to.equal('anotherMPID'); | ||
| expect(body2.user_identities).to.have.property( | ||
|
|
@@ -1074,6 +1053,7 @@ describe('identities and attributes', function() { | |
| }); | ||
|
|
||
| mParticle.Identity.logout(logoutUser); | ||
| await waitForCondition(hasIdentityCallInflightReturned); | ||
| await waitForCondition(() => { | ||
|
||
| return ( | ||
| mParticle.Identity.getCurrentUser()?.getMPID() === 'mpid2' | ||
|
|
@@ -1169,7 +1149,6 @@ describe('identities and attributes', function() { | |
| }); | ||
|
|
||
| it('should order user identity change events before logging any events that are in the ready queue', async () => { | ||
|
|
||
| mParticle._resetForTests(MPConfig); | ||
| fetchMock.resetHistory(); | ||
|
|
||
|
|
@@ -1235,8 +1214,6 @@ describe('identities and attributes', function() { | |
| }); | ||
|
|
||
| it('should send historical UIs on batches when MPID changes', async () => { | ||
| mParticle._resetForTests(MPConfig); | ||
|
|
||
| window.mParticle.config.identifyRequest = { | ||
| userIdentities: { | ||
| email: 'initial@gmail.com', | ||
|
|
@@ -1268,6 +1245,15 @@ describe('identities and attributes', function() { | |
| mParticle.getInstance()._Store.identityCallInFlight === false | ||
| ); | ||
| }); | ||
|
|
||
| await waitForCondition(() => { | ||
| const currentUser = mParticle.Identity.getCurrentUser(); | ||
| const userIdentities = currentUser?.getUserIdentities()?.userIdentities; | ||
| return userIdentities && | ||
| userIdentities.customerid === 'customerid1' && | ||
| userIdentities.email === 'initial@gmail.com'; | ||
| }); | ||
|
||
|
|
||
| let batch = JSON.parse(`${fetchMock.lastOptions().body}`); | ||
| expect(batch.mpid).to.equal(testMPID); | ||
| expect(batch.user_identities).to.have.property( | ||
|
|
@@ -1290,6 +1276,7 @@ describe('identities and attributes', function() { | |
| }); | ||
|
|
||
| mParticle.Identity.logout(logoutUser); | ||
| await waitForCondition(hasIdentityCallInflightReturned); | ||
|
|
||
| await waitForCondition(() => { | ||
| return ( | ||
|
|
@@ -1316,7 +1303,6 @@ describe('identities and attributes', function() { | |
| mParticle.getInstance()._Store.identityCallInFlight === false | ||
| ); | ||
| }); | ||
| // switching back to logged in user should not result in any UIC events | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's keep this comment |
||
| expect(fetchMock.calls().length).to.equal(1); | ||
|
|
||
| const data = getIdentityEvent(fetchMock.calls(), 'login'); | ||
|
|
@@ -1336,8 +1322,6 @@ describe('identities and attributes', function() { | |
| ); | ||
| }); | ||
| it('should not send user attribute change requests when user attribute already set with same value with false values', async () => { | ||
| mParticle._resetForTests(MPConfig); | ||
|
|
||
| window.mParticle.config.flags = { | ||
| EventBatchingIntervalMillis: 0, | ||
| }; | ||
|
|
@@ -1433,8 +1417,6 @@ describe('identities and attributes', function() { | |
| }); | ||
|
|
||
| it('should send user attribute change event when setting different falsey values', async () => { | ||
| mParticle._resetForTests(MPConfig); | ||
|
|
||
| window.mParticle.config.flags = { | ||
| EventBatchingIntervalMillis: 0, | ||
| }; | ||
|
|
||

There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Strange, still seeing a 2000 ms issue here for firefox
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nevermind, may be the comment i left above actually in the utils.js file for waitForCondition instead