From 0b41099165eb07174fe20ef756e606ac0910630d Mon Sep 17 00:00:00 2001 From: Jaissica Date: Mon, 20 Oct 2025 10:49:30 -0400 Subject: [PATCH 01/40] test: updated setup for identity tests --- test/src/tests-identities-attributes.ts | 89 ++++--- test/src/tests-identity.ts | 318 ++++++++++++++++-------- test/src/tests-identityApiClient.ts | 4 +- 3 files changed, 262 insertions(+), 149 deletions(-) diff --git a/test/src/tests-identities-attributes.ts b/test/src/tests-identities-attributes.ts index 256d91847..99b49fcda 100644 --- a/test/src/tests-identities-attributes.ts +++ b/test/src/tests-identities-attributes.ts @@ -58,6 +58,9 @@ describe('identities and attributes', function() { let hasBeforeEachCallbackReturned; beforeEach(function() { + mParticle._resetForTests(MPConfig); + fetchMock.config.overwriteRoutes = true; + fetchMockSuccess(urls.identify, { mpid: testMPID, is_logged_in: false }); @@ -82,13 +85,13 @@ describe('identities and attributes', function() { }); it('should set user attribute', async () => { - mParticle._resetForTests(MPConfig); const mockForwarder = new MockForwarder(); mockForwarder.register(window.mParticle.config); mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned); + await Promise.resolve(); mParticle.Identity.getCurrentUser().setUserAttribute('gender', 'male'); @@ -104,13 +107,13 @@ 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); mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned); + await Promise.resolve(); mParticle.Identity.getCurrentUser().setUserAttribute('Gender', 'male'); mParticle.Identity.getCurrentUser().setUserAttribute( 'gender', @@ -140,12 +143,12 @@ 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); mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned); + await Promise.resolve(); mParticle.Identity.getCurrentUser().setUserAttributes({ gender: 'male', age: 21, @@ -165,12 +168,12 @@ describe('identities and attributes', function() { }); it('should remove user attribute', async () => { - mParticle._resetForTests(MPConfig); const mockForwarder = new MockForwarder(); mockForwarder.register(window.mParticle.config); mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned); + await Promise.resolve(); mParticle.Identity.getCurrentUser().setUserAttribute('gender', 'male'); mParticle.Identity.getCurrentUser().removeUserAttribute('gender'); @@ -183,12 +186,12 @@ 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); mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned); + await Promise.resolve(); mParticle.Identity.getCurrentUser().setUserAttribute('Gender', 'male'); mParticle.Identity.getCurrentUser().removeUserAttribute('gender'); @@ -204,6 +207,7 @@ describe('identities and attributes', function() { it('should set session attribute', async () => { await waitForCondition(hasIdentifyReturned); + await Promise.resolve(); mParticle.setSessionAttribute('name', 'test'); @@ -227,6 +231,7 @@ describe('identities and attributes', function() { it('should set session attribute case insensitive', async () => { await waitForCondition(hasIdentifyReturned); + await Promise.resolve(); mParticle.setSessionAttribute('name', 'test'); mParticle.setSessionAttribute('Name', 'test1'); @@ -249,6 +254,7 @@ describe('identities and attributes', function() { it("should not set a session attribute's key as an object or array)", async () => { await waitForCondition(hasIdentifyReturned); + await Promise.resolve(); mParticle.setSessionAttribute( BAD_SESSION_ATTRIBUTE_KEY_AS_OBJECT, @@ -282,6 +288,7 @@ describe('identities and attributes', function() { it('should remove session attributes when session ends', async () => { await waitForCondition(hasIdentifyReturned); + await Promise.resolve(); mParticle.startNewSession(); mParticle.setSessionAttribute('name', 'test'); @@ -303,6 +310,7 @@ describe('identities and attributes', function() { it('should set and log position', async () => { await waitForCondition(hasIdentifyReturned); + await Promise.resolve(); mParticle.setPosition(34.134103, -118.321694); mParticle.logEvent('Test Event'); @@ -316,6 +324,7 @@ describe('identities and attributes', function() { it('should set user tag', async () => { await waitForCondition(hasIdentifyReturned); + await Promise.resolve(); mParticle.Identity.getCurrentUser().setUserTag('test'); @@ -332,6 +341,7 @@ describe('identities and attributes', function() { it('should set user tag case insensitive', async () => { await waitForCondition(hasIdentifyReturned); + await Promise.resolve(); mParticle.Identity.getCurrentUser().setUserTag('Test'); mParticle.Identity.getCurrentUser().setUserTag('test'); @@ -350,6 +360,7 @@ describe('identities and attributes', function() { it('should remove user tag', async () => { await waitForCondition(hasIdentifyReturned); + await Promise.resolve(); mParticle.Identity.getCurrentUser().setUserTag('test'); mParticle.Identity.getCurrentUser().removeUserTag('test'); @@ -367,6 +378,7 @@ describe('identities and attributes', function() { it('should remove user tag case insensitive', async () => { await waitForCondition(hasIdentifyReturned); + await Promise.resolve(); mParticle.Identity.getCurrentUser().setUserTag('Test'); mParticle.Identity.getCurrentUser().removeUserTag('test'); @@ -383,10 +395,9 @@ describe('identities and attributes', function() { }); it('should set user attribute list', async () => { - mParticle._resetForTests(MPConfig); - mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned); + await Promise.resolve(); mParticle.Identity.getCurrentUser().setUserAttributeList('numbers', [ 1, 2, @@ -409,10 +420,9 @@ 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); + await Promise.resolve(); mParticle.Identity.getCurrentUser().setUserAttributeList('numbers', [ 1, 2, @@ -463,11 +473,10 @@ 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); + await Promise.resolve(); mParticle.Identity.getCurrentUser().setUserAttributeList( 'numbers', list @@ -489,10 +498,9 @@ describe('identities and attributes', function() { }); it('should remove all user attributes', async () => { - mParticle._resetForTests(MPConfig); - mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned); + await Promise.resolve(); mParticle.Identity.getCurrentUser().setUserAttributeList('numbers', [ 1, 2, @@ -513,11 +521,11 @@ describe('identities and attributes', function() { }); it('should get user attribute lists', async () => { - mParticle._resetForTests(MPConfig); mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned); + await Promise.resolve(); mParticle.Identity.getCurrentUser().setUserAttribute('gender', 'male'); mParticle.Identity.getCurrentUser().setUserAttributeList('numbers', [ @@ -535,10 +543,10 @@ 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); + await Promise.resolve(); mParticle.Identity.getCurrentUser().setUserAttribute('gender', 'male'); mParticle.Identity.getCurrentUser().setUserAttributeList('numbers', [ 1, @@ -557,9 +565,9 @@ 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); + await Promise.resolve(); mParticle.Identity.getCurrentUser().setUserAttribute('gender', 'male'); mParticle.Identity.getCurrentUser().setUserAttributeList('numbers', [ 1, @@ -581,10 +589,9 @@ describe('identities and attributes', function() { }); it('should get all user attributes', async () => { - mParticle._resetForTests(MPConfig); - mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned); + await Promise.resolve(); mParticle.Identity.getCurrentUser().setUserAttribute('test', '123'); mParticle.Identity.getCurrentUser().setUserAttribute( 'another test', @@ -598,9 +605,9 @@ 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); + await Promise.resolve(); mParticle.Identity.getCurrentUser().setUserAttributeList( 'mykey', BAD_USER_ATTRIBUTE_LIST_VALUE @@ -613,6 +620,7 @@ describe('identities and attributes', function() { it('should not set bad session attribute value', async () => { await waitForCondition(hasIdentifyReturned); + await Promise.resolve(); mParticle.setSessionAttribute( 'name', BAD_SESSION_ATTRIBUTE_VALUE_AS_OBJECT @@ -632,6 +640,7 @@ describe('identities and attributes', function() { it('should not set a bad user attribute key or value', async () => { await waitForCondition(hasIdentifyReturned); + await Promise.resolve(); mParticle.Identity.getCurrentUser().setUserAttribute('gender', { bad: 'bad', }); @@ -709,10 +718,9 @@ 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); + await Promise.resolve(); // set a new attribute, age fetchMock.resetHistory(); mParticle.Identity.getCurrentUser().setUserAttribute('age', '25'); @@ -823,10 +831,9 @@ 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); + await Promise.resolve(); mParticle.Identity.getCurrentUser().setUserAttribute('age', '25'); const testMPID = mParticle.Identity.getCurrentUser().getMPID(); @@ -860,6 +867,7 @@ describe('identities and attributes', function() { mParticle.Identity.getCurrentUser()?.getMPID() === 'anotherMPID' ); }); + await Promise.resolve(); const users = mParticle.Identity.getUsers(); expect(users.length).to.equal(2); @@ -918,8 +926,6 @@ describe('identities and attributes', function() { }); it('should send user identity change requests when setting new identities on new users', async () => { - mParticle._resetForTests(MPConfig); - fetchMock.resetHistory(); window.mParticle.config.identifyRequest = { @@ -930,6 +936,7 @@ describe('identities and attributes', function() { mParticle.config.flags.eventBatchingIntervalMillis = 5000 mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned); + await Promise.resolve(); mParticle.upload(); expect( JSON.parse(`${fetchMock.lastOptions().body}`).user_identities @@ -960,6 +967,7 @@ describe('identities and attributes', function() { mParticle.Identity.getCurrentUser()?.getMPID() === 'anotherMPID' ); }); + await Promise.resolve(); let body = JSON.parse(`${fetchMock.lastOptions().body}`); // should be the new MPID @@ -1004,11 +1012,12 @@ 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 + ); + }); + await Promise.resolve(); const body2 = JSON.parse(`${fetchMock.lastOptions().body}`); expect(body2.mpid).to.equal('anotherMPID'); expect(body2.user_identities).to.have.property( @@ -1045,6 +1054,7 @@ describe('identities and attributes', function() { mParticle.getInstance()._Store.identityCallInFlight === false ); }); + await Promise.resolve(); const body3 = JSON.parse(`${fetchMock.lastOptions().body}`); expect(body3.mpid).to.equal('anotherMPID'); @@ -1079,6 +1089,7 @@ describe('identities and attributes', function() { mParticle.Identity.getCurrentUser()?.getMPID() === 'mpid2' ); }); + await Promise.resolve(); // Calls are for logout and UIC expect(fetchMock.calls().length).to.equal(2); const body4 = JSON.parse(`${fetchMock.lastOptions().body}`); @@ -1111,6 +1122,7 @@ describe('identities and attributes', function() { // Clear out before each init call await waitForCondition(hasBeforeEachCallbackReturned); + await Promise.resolve(); window.mParticle.config.identifyRequest = { userIdentities: { @@ -1121,6 +1133,7 @@ describe('identities and attributes', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentityCallInflightReturned); + await Promise.resolve(); mParticle.logEvent('Test Event 1'); mParticle.logEvent('Test Event 2'); @@ -1169,12 +1182,12 @@ 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(); // Clear out before each init call await waitForCondition(hasBeforeEachCallbackReturned); + await Promise.resolve(); window.mParticle.config.identifyRequest = { userIdentities: { @@ -1191,6 +1204,7 @@ describe('identities and attributes', function() { expect(mParticle.getInstance()._preInit.readyQueue.length).to.equal(3); await waitForCondition(hasIdentityCallInflightReturned); + await Promise.resolve(); expect(fetchMock.calls().length).to.equal(7); @@ -1235,8 +1249,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', @@ -1251,6 +1263,7 @@ describe('identities and attributes', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned); + await Promise.resolve(); fetchMockSuccess(urls.login, { mpid: 'testMPID', is_logged_in: true }); @@ -1268,6 +1281,7 @@ describe('identities and attributes', function() { mParticle.getInstance()._Store.identityCallInFlight === false ); }); + await Promise.resolve(); let batch = JSON.parse(`${fetchMock.lastOptions().body}`); expect(batch.mpid).to.equal(testMPID); expect(batch.user_identities).to.have.property( @@ -1296,6 +1310,7 @@ describe('identities and attributes', function() { mParticle.Identity.getCurrentUser()?.getMPID() === 'mpid2' ); }); + await Promise.resolve(); batch = JSON.parse(`${fetchMock.lastOptions().body}`); expect(batch.mpid).to.equal('mpid2'); expect(batch.user_identities).to.have.property('other', 'other1'); @@ -1316,7 +1331,7 @@ describe('identities and attributes', function() { mParticle.getInstance()._Store.identityCallInFlight === false ); }); - // switching back to logged in user should not result in any UIC events + await Promise.resolve(); expect(fetchMock.calls().length).to.equal(1); const data = getIdentityEvent(fetchMock.calls(), 'login'); @@ -1336,8 +1351,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, }; @@ -1345,6 +1358,7 @@ describe('identities and attributes', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned); + await Promise.resolve(); // set a new attribute, age fetchMock.resetHistory(); mParticle.Identity.getCurrentUser().setUserAttribute('age', '25'); @@ -1433,8 +1447,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, }; @@ -1442,6 +1454,7 @@ describe('identities and attributes', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned); + await Promise.resolve(); // set initial test attribute with 'falsey' value to 0 fetchMock.resetHistory(); mParticle.Identity.getCurrentUser().setUserAttribute('testFalsey', 0); diff --git a/test/src/tests-identity.ts b/test/src/tests-identity.ts index 5aeb627d0..5f0bfbc5b 100644 --- a/test/src/tests-identity.ts +++ b/test/src/tests-identity.ts @@ -99,7 +99,9 @@ describe('identity', function() { let hasBeforeEachCallbackReturned beforeEach(function() { + mParticle._resetForTests(MPConfig); delete mParticle.config.useCookieStorage; + fetchMock.config.overwriteRoutes = true; fetchMockSuccess(urls.events); fetchMockSuccess(urls.identify, { context: null, @@ -150,7 +152,6 @@ describe('identity', function() { afterEach(function () { fetchMock.restore(); beforeEachCallbackCalled = false; - mParticle._resetForTests(MPConfig); if (clock && clock) { clock.runAll(); // ensures all timers are complete from previous tests } @@ -175,6 +176,7 @@ describe('identity', function() { }); await waitForCondition(hasIdentifyReturned) + await Promise.resolve(); // Calls should be expected // 1. Identify @@ -217,6 +219,7 @@ describe('identity', function() { }); await waitForCondition(hasIdentifyReturned) + await Promise.resolve(); mParticle.Identity.logout(); @@ -251,6 +254,7 @@ describe('identity', function() { it('should contain login request', async () => { await waitForCondition(hasIdentifyReturned) + await Promise.resolve(); fetchMockSuccess(urls.login, { mpid: testMPID, @@ -269,6 +273,7 @@ describe('identity', function() { }); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); // Calls that should be expected: // 1. Identify @@ -317,6 +322,7 @@ describe('identity', function() { }); await waitForCondition(hasIdentifyReturned) + await Promise.resolve(); mParticle.Identity.modify({ userIdentities: { email: 'test@email.com', @@ -369,6 +375,7 @@ describe('identity', function() { let data: IIdentityAPIRequestData; await waitForCondition(hasIdentifyReturned) + await Promise.resolve(); mParticle.Identity.identify({ userIdentities: { @@ -377,6 +384,7 @@ describe('identity', function() { }); await waitForCondition(hasIdentifyReturned) + await Promise.resolve(); // 4 Calls should be expected // 1. Identify @@ -411,6 +419,7 @@ describe('identity', function() { it('should strip falsey values from identify request', async () => { await waitForCondition(hasIdentifyReturned) + await Promise.resolve(); const identityApiData = { userIdentities: { @@ -428,6 +437,7 @@ describe('identity', function() { mParticle.Identity.identify(identityApiData as unknown as IdentityApiData); await waitForCondition(hasIdentifyReturned) + await Promise.resolve(); const firstCall = fetchMock.calls()[0]; expect(firstCall[0].split('/')[4]).to.equal('identify'); @@ -469,6 +479,7 @@ describe('identity', function() { it('should strip falsey values from login request', async () => { await waitForCondition(hasIdentifyReturned) + await Promise.resolve(); const identityApiData = { userIdentities: { @@ -496,6 +507,7 @@ describe('identity', function() { mParticle.Identity.login(identityApiData as unknown as IdentityApiData); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); const firstCall = fetchMock.calls()[0]; expect(firstCall[0].split('/')[4]).to.equal('login'); @@ -527,6 +539,7 @@ describe('identity', function() { it('should strip falsey values from logout request', async () => { await waitForCondition(hasIdentifyReturned) + await Promise.resolve(); const identityApiData = { userIdentities: { @@ -554,6 +567,7 @@ describe('identity', function() { mParticle.Identity.logout(identityApiData as unknown as IdentityApiData); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); const firstCall = fetchMock.calls()[0]; expect(firstCall[0].split('/')[4]).to.equal('logout'); @@ -585,6 +599,7 @@ describe('identity', function() { it('should strip falsey values from modify request', async () => { await waitForCondition(hasIdentifyReturned) + await Promise.resolve(); const identityApiData = { userIdentities: { @@ -611,9 +626,9 @@ describe('identity', function() { mParticle.Identity.modify(identityApiData as unknown as IdentityApiData); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); const firstCall = fetchMock.calls()[0]; - debugger expect(firstCall[0].split('/')[5]).to.equal('modify'); const data = JSON.parse(firstCall[1].body as unknown as string) as IIdentityAPIModifyRequestData; @@ -643,7 +658,6 @@ describe('identity', function() { describe('privacy flags', function() { beforeEach(function() { - mParticle._resetForTests(MPConfig); mParticle.config.flags.cacheIdentity = 'True'; localStorage.clear(); }); @@ -652,6 +666,7 @@ describe('identity', function() { it('should save id cache to local storage when noFunctional is false by default', async () => { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned); + await Promise.resolve(); expect(localStorage.getItem('mprtcl-v4_abcdef-id-cache')).to.be.ok; }); @@ -659,6 +674,7 @@ describe('identity', function() { mParticle.config.launcherOptions = { noFunctional: true }; mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned); + await Promise.resolve(); expect(localStorage.getItem('mprtcl-v4_abcdef-id-cache')).not.to.be.ok; }); @@ -666,6 +682,7 @@ describe('identity', function() { mParticle.config.launcherOptions = { noFunctional: false }; mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned); + await Promise.resolve(); expect(localStorage.getItem('mprtcl-v4_abcdef-id-cache')).to.be.ok; }); }); @@ -673,8 +690,7 @@ describe('identity', function() { // https://go.mparticle.com/work/SQDSDKS-6849 // This test passes with no issue when it is run on its own, but fails when tests-forwarders.js are also ran. - it('should respect consent rules on consent-change', async () => { - mParticle._resetForTests(MPConfig); + it('should respect consent rules on consent-change', async () => { mParticle.config.isDevelopmentMode = false; const mockForwarder = new MockForwarder('MockForwarder1'); mockForwarder.register(window.mParticle.config); @@ -719,6 +735,7 @@ describe('identity', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition( () => mParticle.Identity.getCurrentUser()?.getMPID() === 'MPID1') + await Promise.resolve(); let activeForwarders = mParticle.getInstance()._getActiveForwarders(); expect(activeForwarders.length).to.equal(0); @@ -742,6 +759,7 @@ describe('identity', function() { mParticle.Identity.login(); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); activeForwarders = mParticle.getInstance()._getActiveForwarders(); expect(activeForwarders.length).to.equal(0); @@ -761,6 +779,7 @@ describe('identity', function() { describe('cookies', function () { it('should store all MPIDs associated with a sessionId, then clear MPIDs from currentSessionMPIDs when a new session starts', async () => { await waitForCondition(hasIdentifyReturned) + await Promise.resolve(); fetchMockSuccess(urls.login, { mpid: 'logged-in-user', @@ -775,6 +794,7 @@ describe('identity', function() { mParticle.Identity.login(userIdentities1); await waitForCondition(hasLoginReturned) + await Promise.resolve(); const localStorageDataBeforeSessionEnd = mParticle .getInstance() @@ -792,6 +812,7 @@ describe('identity', function() { mParticle.Identity.login(userIdentities1); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); const localStorageAfterLoggingEvent = mParticle .getInstance() @@ -800,7 +821,6 @@ describe('identity', function() { }); it('localStorage - should switch user cookies to new mpid details from cookies when a new mpid is provided', async () => { - mParticle._resetForTests(MPConfig); window.mParticle.config.useCookieStorage = false; setLocalStorage(); @@ -824,6 +844,7 @@ describe('identity', function() { mParticle.Identity.login(userIdentities1); await waitForCondition(hasLoginReturned) + await Promise.resolve(); const cookiesAfterMPIDChange = mParticle .getInstance() ._Persistence.getLocalStorage(); @@ -862,7 +883,6 @@ describe('identity', function() { }); it('cookies - should switch user cookies to new mpid details from cookies when a new mpid is provided', async () => { - mParticle._resetForTests(MPConfig); mParticle.config.useCookieStorage = true; setLocalStorage(); @@ -870,6 +890,7 @@ describe('identity', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned) + await Promise.resolve(); const cookiesAfterInit = findCookie(); cookiesAfterInit.should.have.properties('gs', 'cu', testMPID); @@ -905,6 +926,7 @@ describe('identity', function() { mParticle.Identity.login(userIdentities1); await waitForCondition(hasLoginReturned) + await Promise.resolve(); const cookiesAfterMPIDChange = findCookie(); cookiesAfterMPIDChange.should.have.properties([ @@ -1368,7 +1390,8 @@ describe('identity', function() { mParticle.Identity.login(identityAPIRequest); await waitForCondition(hasIdentityCallInflightReturned) - expect(fetchMock.calls().length).to.equal(0); + await Promise.resolve(); + expect(fetchMock.calls().length).to.equal(0); }); it('should not make a request when an invalid request is sent as an array', async () => { @@ -1376,7 +1399,8 @@ describe('identity', function() { mParticle.Identity.login(identityAPIRequest); await waitForCondition(hasIdentityCallInflightReturned) - expect(fetchMock.calls().length).to.equal(0); + await Promise.resolve(); + expect(fetchMock.calls().length).to.equal(0); }); it('should not make a request when an invalid request is sent as a null', async () => { @@ -1384,7 +1408,8 @@ describe('identity', function() { mParticle.Identity.login(identityAPIRequest); await waitForCondition(hasIdentityCallInflightReturned) - expect(fetchMock.calls().length).to.equal(0); + await Promise.resolve(); + expect(fetchMock.calls().length).to.equal(0); }); it('should not make a request when an invalid request is sent as undefined', async () => { @@ -1392,7 +1417,8 @@ describe('identity', function() { mParticle.Identity.login(identityAPIRequest); await waitForCondition(hasIdentityCallInflightReturned) - expect(fetchMock.calls().length).to.equal(0); + await Promise.resolve(); + expect(fetchMock.calls().length).to.equal(0); }); it('should not make a request when an invalid request is sent as a boolean', async () => { @@ -1400,7 +1426,8 @@ describe('identity', function() { mParticle.Identity.login(identityAPIRequest); await waitForCondition(hasIdentityCallInflightReturned) - expect(fetchMock.calls().length).to.equal(0); + await Promise.resolve(); + expect(fetchMock.calls().length).to.equal(0); }); it('should not make a request when an invalid callback is set', async () => { @@ -1414,7 +1441,8 @@ describe('identity', function() { mParticle.Identity.login(identityRequest, badCallback); await waitForCondition(hasIdentityCallInflightReturned) - expect(fetchMock.calls().length).to.equal(0); + await Promise.resolve(); + expect(fetchMock.calls().length).to.equal(0); }); }); @@ -1429,7 +1457,8 @@ describe('identity', function() { mParticle.Identity.logout(identityAPIRequest); await waitForCondition(hasIdentityCallInflightReturned) - expect(fetchMock.calls().length).to.equal(0); + await Promise.resolve(); + expect(fetchMock.calls().length).to.equal(0); }); it('should not make a request when an invalid request is sent as array', async () => { @@ -1437,7 +1466,8 @@ describe('identity', function() { mParticle.Identity.logout(identityAPIRequest); await waitForCondition(hasIdentityCallInflightReturned) - expect(fetchMock.calls().length).to.equal(0); + await Promise.resolve(); + expect(fetchMock.calls().length).to.equal(0); }); it('should not make a request when an invalid request is sent as a null', async () => { @@ -1445,7 +1475,8 @@ describe('identity', function() { mParticle.Identity.logout(identityAPIRequest); await waitForCondition(hasIdentityCallInflightReturned) - expect(fetchMock.calls().length).to.equal(0); + await Promise.resolve(); + expect(fetchMock.calls().length).to.equal(0); }); it('should not make a request when an invalid request is sent as undefined', async () => { @@ -1453,7 +1484,8 @@ describe('identity', function() { mParticle.Identity.logout(identityAPIRequest); await waitForCondition(hasIdentityCallInflightReturned) - expect(fetchMock.calls().length).to.equal(0); + await Promise.resolve(); + expect(fetchMock.calls().length).to.equal(0); }); it('should not make a request when an invalid request is sent as boolean', async () => { @@ -1461,7 +1493,8 @@ describe('identity', function() { mParticle.Identity.logout(identityAPIRequest); await waitForCondition(hasIdentityCallInflightReturned) - expect(fetchMock.calls().length).to.equal(0); + await Promise.resolve(); + expect(fetchMock.calls().length).to.equal(0); }); it('should not make a request when an invalid callback is sent', async () => { @@ -1475,7 +1508,8 @@ describe('identity', function() { mParticle.Identity.logout(identityRequest, badCallback); await waitForCondition(hasIdentityCallInflightReturned) - expect(fetchMock.calls().length).to.equal(0); + await Promise.resolve(); + expect(fetchMock.calls().length).to.equal(0); }); }); @@ -1491,7 +1525,8 @@ describe('identity', function() { mParticle.Identity.modify(identityAPIRequest); await waitForCondition(hasIdentityCallInflightReturned) - expect(fetchMock.calls().length).to.equal(0); + await Promise.resolve(); + expect(fetchMock.calls().length).to.equal(0); }); it('should not make a request when an invalid request is sent as an array', async () => { @@ -1499,7 +1534,8 @@ describe('identity', function() { mParticle.Identity.modify(identityAPIRequest); await waitForCondition(hasIdentityCallInflightReturned) - expect(fetchMock.calls().length).to.equal(0); + await Promise.resolve(); + expect(fetchMock.calls().length).to.equal(0); }); it('should not make a request when an invalid request is sent as a null', async () => { @@ -1507,15 +1543,17 @@ describe('identity', function() { mParticle.Identity.modify(identityAPIRequest); await waitForCondition(hasIdentityCallInflightReturned) - expect(fetchMock.calls().length).to.equal(0); + await Promise.resolve(); + expect(fetchMock.calls().length).to.equal(0); }); it('should not make a request when an invalid request is sent as a undefined', async () => { const identityAPIRequest = BAD_USER_IDENTITIES_AS_UNDEFINED; mParticle.Identity.modify(identityAPIRequest); - await waitForCondition(hasIdentityCallInflightReturned) - expect(fetchMock.calls().length).to.equal(0); +await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); + expect(fetchMock.calls().length).to.equal(0); }); it('should not make a request when an invalid request is sent as a boolean', async () => { @@ -1523,7 +1561,8 @@ describe('identity', function() { mParticle.Identity.modify(identityAPIRequest); await waitForCondition(hasIdentityCallInflightReturned) - expect(fetchMock.calls().length).to.equal(0); + await Promise.resolve(); + expect(fetchMock.calls().length).to.equal(0); }); it('should not make a request when an invalid callback is set', async () => { @@ -1537,7 +1576,8 @@ describe('identity', function() { mParticle.Identity.modify(identityRequest, badCallback); await waitForCondition(hasIdentityCallInflightReturned) - expect(fetchMock.calls().length).to.equal(0); + await Promise.resolve(); + expect(fetchMock.calls().length).to.equal(0); }); }); @@ -1552,7 +1592,8 @@ describe('identity', function() { mParticle.Identity.identify(identityAPIRequest); await waitForCondition(hasIdentityCallInflightReturned) - expect(fetchMock.calls().length).to.equal(0); + await Promise.resolve(); + expect(fetchMock.calls().length).to.equal(0); }); it('should not make a request when an invalid request is sent as an array', async () => { @@ -1560,7 +1601,8 @@ describe('identity', function() { mParticle.Identity.identify(identityAPIRequest); await waitForCondition(hasIdentityCallInflightReturned) - expect(fetchMock.calls().length).to.equal(0); + await Promise.resolve(); + expect(fetchMock.calls().length).to.equal(0); }); it('should not make a request when an invalid request is sent as a null', async () => { @@ -1568,7 +1610,8 @@ describe('identity', function() { mParticle.Identity.identify(identityAPIRequest); await waitForCondition(hasIdentityCallInflightReturned) - expect(fetchMock.calls().length).to.equal(0); + await Promise.resolve(); + expect(fetchMock.calls().length).to.equal(0); }); it('should not make a request when an invalid request is sent as a undefined', async () => { @@ -1576,7 +1619,8 @@ describe('identity', function() { mParticle.Identity.identify(identityAPIRequest); await waitForCondition(hasIdentityCallInflightReturned) - expect(fetchMock.calls().length).to.equal(0); + await Promise.resolve(); + expect(fetchMock.calls().length).to.equal(0); }); it('should not make a request when an invalid request is sent as a boolean', async () => { @@ -1584,7 +1628,8 @@ describe('identity', function() { mParticle.Identity.identify(identityAPIRequest); await waitForCondition(hasIdentityCallInflightReturned) - expect(fetchMock.calls().length).to.equal(0); + await Promise.resolve(); + expect(fetchMock.calls().length).to.equal(0); }); it('should not make a request when an invalid callback is set', async () => { @@ -1598,7 +1643,8 @@ describe('identity', function() { mParticle.Identity.identify(identityRequest, badCallback); await waitForCondition(hasIdentityCallInflightReturned) - expect(fetchMock.calls().length).to.equal(0); + await Promise.resolve(); + expect(fetchMock.calls().length).to.equal(0); }); }); @@ -1693,6 +1739,7 @@ describe('identity', function() { // https://go.mparticle.com/work/SQDSDKS-6568 it('should create a proper send request when passing identities to modify', async () => { await waitForCondition(hasIdentifyReturned) + await Promise.resolve(); const identityAPIData: IdentityApiData = { userIdentities: { email: 'rob@gmail.com', @@ -1710,31 +1757,32 @@ describe('identity', function() { }); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); fetchMock.resetHistory(); mParticle.Identity.modify(identityAPIData); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); // 1st call is modify, 2nd call is the UIC event - console.log('fetchMock.calls()', fetchMock.calls()); - expect(fetchMock.calls().length).to.equal(2); + expect(fetchMock.calls().length).to.equal(2); - const modifyCall = fetchMock.calls()[0]; - expect(modifyCall[0].split('/')[5]).to.equal('modify'); + const modifyCall = fetchMock.calls()[0]; + expect(modifyCall[0].split('/')[5]).to.equal('modify'); - const data: IIdentityAPIModifyRequestData = JSON.parse(modifyCall[1].body as unknown as string); + const data: IIdentityAPIModifyRequestData = JSON.parse(modifyCall[1].body as unknown as string); - expect(data.identity_changes.length).to.equal(1); - expect(data.identity_changes[0]).to.have.keys( - 'old_value', - 'new_value', - 'identity_type' - ); - expect(data.identity_changes[0]).to.have.keys( - 'old_value', - 'new_value', - 'identity_type' - ); + expect(data.identity_changes.length).to.equal(1); + expect(data.identity_changes[0]).to.have.keys( + 'old_value', + 'new_value', + 'identity_type' + ); + expect(data.identity_changes[0]).to.have.keys( + 'old_value', + 'new_value', + 'identity_type' + ); }); it('ensure that automatic identify is not called more than once.', async () => { @@ -1742,6 +1790,7 @@ describe('identity', function() { const spy = sinon.spy(); await waitForCondition(hasIdentifyReturned) + await Promise.resolve(); mParticle.config.identityCallback = spy; fetchMockSuccess(urls.identify, { @@ -1754,15 +1803,16 @@ describe('identity', function() { await waitForCondition(() => { return mParticle.Identity.getCurrentUser()?.getMPID() === 'otherMPID'; }) + await Promise.resolve(); spy.calledOnce.should.be.ok(); mParticle.startNewSession(); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); spy.calledOnce.should.be.ok(); }); it('queue events when MPID is 0, and then flush events once MPID changes', async () => { - mParticle._resetForTests(MPConfig); fetchMock.resetHistory(); fetchMockSuccess( @@ -1776,6 +1826,7 @@ describe('identity', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); mParticle.logEvent('Test Event 1'); // There should be 3 calls here: @@ -1801,6 +1852,7 @@ describe('identity', function() { mParticle.Identity.login(); await waitForCondition(hasLoginReturned) + await Promise.resolve(); // server requests will now have the following events: // 1. Identify (from init) @@ -1841,8 +1893,6 @@ describe('identity', function() { }); it('getUsers should return all mpids available in local storage', async () => { - mParticle._resetForTests(MPConfig); - const userIdentities1: IdentityApiData = { userIdentities: { customerid: 'foo1', @@ -1864,6 +1914,7 @@ describe('identity', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); // get user 1 into cookies fetchMockSuccess(urls.login, { @@ -1874,6 +1925,7 @@ describe('identity', function() { mParticle.Identity.login(userIdentities1); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); // get user 2 into cookies fetchMockSuccess(urls.login, { @@ -1884,6 +1936,7 @@ describe('identity', function() { mParticle.Identity.login(userIdentities2); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); // get user 3 into cookies fetchMockSuccess(urls.login, { @@ -1894,6 +1947,7 @@ describe('identity', function() { mParticle.Identity.login(userIdentities3); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); // init again using user 1 fetchMockSuccess(urls.login, { @@ -1904,6 +1958,7 @@ describe('identity', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(() => mParticle.Identity?.getUsers().length === 4) + await Promise.resolve(); const users = mParticle.Identity.getUsers(); // This includes the original, starting user, in addition to the 3 added above expect(users.length).to.equal(4); @@ -1919,8 +1974,6 @@ describe('identity', function() { }); it('should update its own cookies, not any other mpids when initializing with a different set of credentials', async () => { - mParticle._resetForTests(MPConfig); - const user1 = { userIdentities: { customerid: 'customerid1', @@ -1945,6 +1998,7 @@ describe('identity', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); // get user 1 into cookies fetchMockSuccess(urls.login, { @@ -1955,6 +2009,7 @@ describe('identity', function() { mParticle.Identity.login(user1); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); mParticle.Identity.getCurrentUser().setUserAttribute('user', 'user1'); @@ -1967,6 +2022,7 @@ describe('identity', function() { mParticle.Identity.login(user2); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); mParticle.Identity.getCurrentUser().setUserAttribute('user', 'user2'); @@ -1979,6 +2035,7 @@ describe('identity', function() { mParticle.Identity.login(user3); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); mParticle.Identity.getCurrentUser().setUserAttribute('user', 'user3'); @@ -1991,6 +2048,7 @@ describe('identity', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); const localStorage = mParticle .getInstance() @@ -2047,7 +2105,6 @@ describe('identity', function() { }); it("should find the related MPID's cookies when given a UI with fewer IDs when passed to login, logout, and identify, and then log events with updated cookies", async () => { - mParticle._resetForTests(MPConfig); fetchMock.restore(); const user1: IdentityApiData = { userIdentities: { @@ -2086,6 +2143,7 @@ describe('identity', function() { }); await waitForCondition(hasIdentifyReturned) + await Promise.resolve(); mParticle.Identity.modify(user1modified); // Should contain the following calls: // 1 for the initial identify @@ -2093,6 +2151,7 @@ describe('identity', function() { // 1 for the modify // 1 for the UIC event await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); expect(fetchMock.calls().length).to.equal(6); // This will add a new UAC Event to the call @@ -2125,6 +2184,7 @@ describe('identity', function() { mParticle.Identity.logout(user2); await waitForCondition(hasLogOutReturned) + await Promise.resolve(); // This will add the following new calls: // 1 for the logout @@ -2151,6 +2211,7 @@ describe('identity', function() { await waitForCondition(() => { return mParticle.Identity.getCurrentUser().getMPID() === 'testMPID'; }) + await Promise.resolve(); // This will add the following new calls: // 1 for the login @@ -2168,8 +2229,6 @@ describe('identity', function() { }); it('should add new MPIDs to cookie structure when initializing new identity requests, returning an existing mpid when reinitializing with a previous identity', async () => { - mParticle._resetForTests(MPConfig); - const user1 = { userIdentities: { customerid: '1', @@ -2199,6 +2258,7 @@ describe('identity', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); const user1UIs = mParticle.Identity.getCurrentUser().getUserIdentities(); @@ -2212,6 +2272,7 @@ describe('identity', function() { mParticle.Identity.login(user2); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); const user2UIs = mParticle.Identity.getCurrentUser().getUserIdentities(); user2UIs.userIdentities.customerid.should.equal('2'); @@ -2224,6 +2285,7 @@ describe('identity', function() { mParticle.Identity.login(user3); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); const user3UIs = mParticle.Identity.getCurrentUser().getUserIdentities(); user3UIs.userIdentities.customerid.should.equal('3'); @@ -2236,6 +2298,7 @@ describe('identity', function() { mParticle.Identity.login(user4); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); const user4UIs = mParticle.Identity.getCurrentUser().getUserIdentities(); user4UIs.userIdentities.customerid.should.equal('4'); @@ -2248,6 +2311,7 @@ describe('identity', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); const user5 = mParticle.Identity.getCurrentUser(); user5.getUserIdentities().userIdentities.customerid.should.equal('1'); @@ -2266,6 +2330,7 @@ describe('identity', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); fetchMock.resetHistory(); @@ -2367,6 +2432,7 @@ describe('identity', function() { ); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); expect(result, identityMethod).to.be.ok; expect( result.httpCode, @@ -2387,6 +2453,7 @@ describe('identity', function() { mParticle.Identity.modify(goodIdentities, callback); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); expect(result, identityMethod).to.be.ok; @@ -2433,10 +2500,12 @@ describe('identity', function() { }); await waitForCondition(hasIdentifyReturned) + await Promise.resolve(); mParticle.Identity.login(user); await waitForCondition(hasLoginReturned) + await Promise.resolve(); const userIdentities1 = mParticle.Identity.getCurrentUser().getUserIdentities(); @@ -2445,6 +2514,7 @@ describe('identity', function() { mParticle.Identity.logout(); await waitForCondition(hasLogOutReturned) + await Promise.resolve(); const userIdentities2 = mParticle.Identity.getCurrentUser().getUserIdentities(); @@ -2483,14 +2553,17 @@ describe('identity', function() { ); await waitForCondition(hasIdentifyReturned) + await Promise.resolve(); mParticle.Identity.login(user); await waitForCondition(hasLoginReturned) + await Promise.resolve(); mParticle.Identity.modify(modifiedUser); await waitForCondition(() => { return mParticle.Identity.getCurrentUser()?.getUserIdentities().userIdentities['customerid'] === 'customerId2'; }) + await Promise.resolve(); const cookie = mParticle.getInstance()._Persistence.getLocalStorage(); cookie['logged-in-user'].ui[1].should.equal('customerId2'); @@ -2502,6 +2575,7 @@ describe('identity', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned); + await Promise.resolve(); const user1 = { userIdentities: { @@ -2529,6 +2603,7 @@ describe('identity', function() { mParticle.Identity.login(user1); await waitForCondition(hasIdentifyReturned); + await Promise.resolve(); fetchMockSuccess(urls.login, { mpid: 'otherMPID', @@ -2539,6 +2614,7 @@ describe('identity', function() { mParticle.Identity.login(user2); await waitForCondition(hasIdentityCallInflightReturned); + await Promise.resolve(); // This should have a call for the UIC that will occur because // we are logging in as two different users @@ -2550,6 +2626,7 @@ describe('identity', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned); + await Promise.resolve(); let hasBeenRun = false; const user1 = { @@ -2575,6 +2652,7 @@ describe('identity', function() { mParticle.Identity.login(user1); await waitForCondition(hasIdentityCallInflightReturned); + await Promise.resolve(); fetchMockSuccess(urls.login, { mpid: 'otherMPID', @@ -2584,6 +2662,7 @@ describe('identity', function() { mParticle.Identity.login(user2); await waitForCondition(hasIdentityCallInflightReturned); +await Promise.resolve(); expect(hasBeenRun).to.be.true; }); @@ -2592,6 +2671,7 @@ describe('identity', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned); + await Promise.resolve(); const user1 = { userIdentities: { @@ -2607,6 +2687,7 @@ describe('identity', function() { mParticle.Identity.login(user1); await waitForCondition(hasIdentityCallInflightReturned); + await Promise.resolve(); mParticle.Identity.getCurrentUser().setUserAttribute('gender', 'male'); mParticle.Identity.getCurrentUser().setUserAttribute('age', 27); @@ -2644,6 +2725,7 @@ describe('identity', function() { mParticle.Identity.login(user2); await waitForCondition(() => mParticle.Identity.getCurrentUser().getMPID() === 'otherMPID'); + await Promise.resolve(); const user1ObjectAttrs = user1Object.getAllUserAttributes(); user1ObjectAttrs.should.not.have.property('age'); @@ -2683,6 +2765,7 @@ describe('identity', function() { mParticle.Identity.login(user3); await waitForCondition(() => mParticle.Identity.getCurrentUser().getMPID() === 'otherMPID2'); + await Promise.resolve(); expect(user2AttributeListsBeforeRemoving.list.length).to.equal(5); @@ -2698,6 +2781,7 @@ describe('identity', function() { it('should return an empty array when no cart products exist', async () => { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned) + await Promise.resolve(); const user1 = { userIdentities: { customerid: 'customerId1', @@ -2712,6 +2796,7 @@ describe('identity', function() { mParticle.Identity.login(user1); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); const products = mParticle.Identity.getCurrentUser() .getCart() @@ -2724,6 +2809,7 @@ describe('identity', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned) + await Promise.resolve(); const identityAPIRequest1 = { userIdentities: { @@ -2743,6 +2829,7 @@ describe('identity', function() { mParticle.Identity.logout(identityAPIRequest1); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); // This should have a call for the logout and UIC expect(fetchMock.calls().length).to.equal(2); @@ -2763,6 +2850,7 @@ describe('identity', function() { mParticle.Identity.login(identityAPIRequest1); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); expect(fetchMock.calls().length).to.equal(1); @@ -2782,6 +2870,7 @@ describe('identity', function() { mParticle.Identity.modify(identityAPIRequest1); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); expect(fetchMock.calls().length).to.equal(1); @@ -2792,9 +2881,6 @@ describe('identity', function() { }); it('should trigger the identifyCallback when a successful identify call is sent', async () => { - // MP.sessionID does not exist yet because we perform an mParticle._resetForTests(MPConfig); - mParticle._resetForTests(MPConfig); - let mpid; fetchMockSuccess(urls.identify, { @@ -2810,6 +2896,7 @@ describe('identity', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); expect(mpid).to.equal('MPID1'); }); @@ -2818,6 +2905,7 @@ describe('identity', function() { mParticle._resetForTests(MPConfig); await waitForCondition(hasBeforeEachCallbackReturned) + await Promise.resolve(); fetchMock.resetHistory(); @@ -2845,6 +2933,7 @@ describe('identity', function() { expect(identifyCall[0].split('/')[4]).to.equal('identify'); await waitForCondition(() => callbackCalled) + await Promise.resolve(); // Force an upload so we can verify the correct events have fired mParticle.upload(); @@ -2873,7 +2962,6 @@ describe('identity', function() { }); it('should still trigger the identifyCallback when no identify request is sent because there are already cookies', async () => { - mParticle._resetForTests(MPConfig); const les = new Date().getTime(); const cookies = "{'gs':{'ie':1|'dt':'test_key'|'cgid':'886e874b-862b-4822-a24a-1146cd057101'|'das':'62c91b8d-fef6-44ea-b2cc-b55714b0d827'|'csm':'WyJ0ZXN0TVBJRCJd'|'sid':'2535f9ed-ab19-4a7c-9eeb-ce4e41e0cb06'|'les': " + @@ -2890,6 +2978,7 @@ describe('identity', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned) + await Promise.resolve(); // Should contain: // 1 for the Identify Request // 1 for the AST @@ -2907,6 +2996,7 @@ describe('identity', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); // the server request is the AST, there is no request to Identity fetchMock.calls().length.should.equal(1); @@ -2943,8 +3033,6 @@ describe('identity', function() { it('identifyCallback response should have a getUser function on the result object', async () => { let result; - mParticle._resetForTests(MPConfig); - fetchMockSuccess(urls.identify, { mpid: 'MPID1', is_logged_in: false, @@ -2958,6 +3046,7 @@ describe('identity', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); result.should.have.property('getUser'); @@ -2970,8 +3059,6 @@ describe('identity', function() { it('should have a getUser function on identify result object', async () => { let result; - mParticle._resetForTests(MPConfig); - mParticle.config.identityCallback = function(resp) { resp.getUser().setUserAttribute('attr', 'value'); result = resp; @@ -2988,6 +3075,7 @@ describe('identity', function() { await waitForCondition(() => { return mParticle.Identity.getCurrentUser()?.getMPID() === 'MPID1'; }) + await Promise.resolve(); result.should.have.properties('body', 'httpCode', 'getUser'); result.httpCode.should.equal(200); @@ -3007,8 +3095,6 @@ describe('identity', function() { let result let loginResult; - mParticle._resetForTests(MPConfig); - mParticle.config.identityCallback = function(resp) { resp.getUser().setUserAttribute('attr', 'value'); result = resp; @@ -3029,6 +3115,7 @@ describe('identity', function() { await waitForCondition(() => { return mParticle.Identity.getCurrentUser()?.getMPID() === 'MPID1'; }) + await Promise.resolve(); const identityRequest = { userIdentities: { customerid: 'test123' } }; function loginCallback(result) { @@ -3038,6 +3125,7 @@ describe('identity', function() { mParticle.Identity.login(identityRequest, loginCallback); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); loginResult .getUser() @@ -3052,9 +3140,7 @@ describe('identity', function() { it('should have a getUser function on logout result object', async () => { let result; - let logoutResult; - - mParticle._resetForTests(MPConfig); + let logoutResult; mParticle.config.identityCallback = function(resp) { resp.getUser().setUserAttribute('attr', 'value'); @@ -3076,6 +3162,7 @@ describe('identity', function() { await waitForCondition(() => { return mParticle.Identity.getCurrentUser()?.getMPID() === 'MPID1'; }) + await Promise.resolve(); const identityRequest = { userIdentities: { customerid: 'test123' } }; function logoutCallback(result) { @@ -3085,6 +3172,7 @@ describe('identity', function() { mParticle.Identity.logout(identityRequest, logoutCallback); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); logoutResult .getUser() @@ -3101,8 +3189,6 @@ describe('identity', function() { let result let modifyResult; - mParticle._resetForTests(MPConfig); - mParticle.config.identityCallback = function(resp) { resp.getUser().setUserAttribute('attr', 'value'); result = resp; @@ -3123,6 +3209,7 @@ describe('identity', function() { await waitForCondition(() => { return mParticle.Identity.getCurrentUser()?.getMPID() === 'MPID1'; }) + await Promise.resolve(); const identityRequest = { userIdentities: { customerid: 'test123' } }; function modifyCallback(result) { @@ -3132,6 +3219,7 @@ describe('identity', function() { mParticle.Identity.modify(identityRequest, modifyCallback); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); modifyResult .getUser() @@ -3151,6 +3239,7 @@ describe('identity', function() { mParticle._resetForTests(MPConfig); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); fetchMockSuccess(urls.identify, { mpid: 'MPID1', @@ -3168,6 +3257,7 @@ describe('identity', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); let cookies = mParticle.getInstance()._Persistence.getPersistence(); cookies.should.have.property('gs'); @@ -3184,6 +3274,7 @@ describe('identity', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(() => mParticle.Identity.getCurrentUser()?.getMPID() === 'MPID1') + await Promise.resolve(); cookies = mParticle.getInstance()._Persistence.getPersistence(); cookies.should.have.property('gs'); @@ -3192,8 +3283,6 @@ describe('identity', function() { }); it('Users should have firstSeenTime and lastSeenTime', async () => { - mParticle._resetForTests(MPConfig); - fetchMockSuccess(urls.identify, { mpid: 'MPID1', is_logged_in: false, @@ -3204,6 +3293,7 @@ describe('identity', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); // NOTE: Use sinon to "lock" in the current time for testing purposes const now = new Date(); @@ -3225,8 +3315,6 @@ describe('identity', function() { }); it('firstSeenTime should stay the same for a user', async () => { - mParticle._resetForTests(MPConfig); - // We can't use sinon.useFakeTimers() because it will affect the async // nature of the tests, so we will just save a timestamp to compare for // later @@ -3242,6 +3330,7 @@ describe('identity', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); let currentUser = mParticle.Identity.getCurrentUser(); currentUser.should.not.equal(null); @@ -3265,6 +3354,7 @@ describe('identity', function() { mParticle.Identity.login(userIdentities1); await waitForCondition(() => mParticle.Identity.getCurrentUser().getMPID() === 'MPID1') + await Promise.resolve(); const nowAfterLogin = new Date(); @@ -3293,6 +3383,7 @@ describe('identity', function() { mParticle.Identity.login(); await waitForCondition(() => mParticle.Identity.getCurrentUser().getMPID() === testMPID) + await Promise.resolve(); currentUser = mParticle.Identity.getCurrentUser(); expect(currentUser.getMPID()).to.equal(testMPID); @@ -3301,8 +3392,6 @@ describe('identity', function() { }); it('list returned by Identity.getUsers() should be sorted by lastSeenTime, with nulls last', async () => { - mParticle._resetForTests(MPConfig); - const cookies = JSON.stringify({ gs: { sid: 'fst Test', @@ -3342,7 +3431,6 @@ describe('identity', function() { it('does not error when simultaneous identity calls are out', async () => { const errorMessages = []; - mParticle._resetForTests(MPConfig); mParticle.config.logger = { error: function(msg) { errorMessages.push(msg); @@ -3360,8 +3448,6 @@ describe('identity', function() { }); it('Startup identity callback should include getPreviousUser()', async () => { - mParticle._resetForTests(MPConfig); - const cookies = JSON.stringify({ gs: { sid: 'test', @@ -3388,6 +3474,7 @@ describe('identity', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); expect(identityResult.getUser().getMPID()).to.equal('testMPID'); expect(identityResult.getPreviousUser()).to.not.equal(null); @@ -3396,9 +3483,7 @@ describe('identity', function() { ); }); - it('Identity callback should include getPreviousUser()', async () => { - mParticle._resetForTests(MPConfig); - + it('Identity callback should include getPreviousUser()', async () => { const cookies = JSON.stringify({ testMPID: { lst: 200, @@ -3414,6 +3499,7 @@ describe('identity', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned) + await Promise.resolve(); fetchMockSuccess(urls.login, { mpid: testMPID, @@ -3436,10 +3522,10 @@ describe('identity', function() { }); it('should return the correct user for Previous User', async () => { - mParticle._resetForTests(MPConfig); let callbackCalled = false; await waitForCondition(hasBeforeEachCallbackReturned) + await Promise.resolve(); const cookies = JSON.stringify({ gs: { @@ -3476,6 +3562,7 @@ describe('identity', function() { let identityResult; await waitForCondition(() => mParticle.Identity.getCurrentUser()?.getMPID() === '1') + await Promise.resolve(); mParticle.Identity.identify(EmptyUserIdentities, function(result) { identityResult = result; @@ -3483,6 +3570,7 @@ describe('identity', function() { }); await waitForCondition(() => callbackCalled) + await Promise.resolve(); identityResult .getUser() .getMPID() @@ -3716,8 +3804,6 @@ describe('identity', function() { }); it('should properly create AliasRequest', async () => { - mParticle._resetForTests(MPConfig); - const cookies = JSON.stringify({ gs: { sid: 'fst Test', @@ -3735,6 +3821,7 @@ describe('identity', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); // Mock clock so we can use simple integers for time clock = sinon.useFakeTimers(); @@ -3755,8 +3842,6 @@ describe('identity', function() { }); it('should fill in missing fst and lst in createAliasRequest', async () => { - mParticle._resetForTests(MPConfig); - const cookies = JSON.stringify({ gs: { sid: 'fst Test', @@ -3774,6 +3859,7 @@ describe('identity', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); // Mock clock so we can use simple integers for time clock = sinon.useFakeTimers(); @@ -3797,8 +3883,6 @@ describe('identity', function() { }); it('should fix startTime when default is outside max window create AliasRequest', async () => { - mParticle._resetForTests(MPConfig); - const millisPerDay = 24 * 60 * 60 * 1000; const cookies = JSON.stringify({ gs: { @@ -3819,6 +3903,7 @@ describe('identity', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); clock = sinon.useFakeTimers(); clock.tick(millisPerDay * 2); @@ -3873,6 +3958,7 @@ describe('identity', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); // Mock clock so we can use simple integers for time clock = sinon.useFakeTimers(); @@ -3903,7 +3989,6 @@ describe('identity', function() { }); it("alias request should have environment 'development' when isDevelopmentMode is true", async () => { - mParticle._resetForTests(MPConfig); window.mParticle.config.isDevelopmentMode = true; fetchMock.post(urls.alias, HTTP_ACCEPTED); @@ -3928,11 +4013,10 @@ describe('identity', function() { }); it('should set isFirtRun to false after an app is initialized', async () => { - mParticle._resetForTests(MPConfig); - mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); mParticle.getInstance()._Store.isFirstRun.should.equal(false); @@ -3944,14 +4028,13 @@ describe('identity', function() { mParticle.Identity.login({ userIdentities: { customerid: 'abc' } }); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); const ls = mParticle.getInstance()._Persistence.getLocalStorage(); ls['testMPID'].lst.should.not.equal(null); }); it('should send back an httpCode of -1 when there is a no coverage (http code returns 0)', async () => { - mParticle._resetForTests(MPConfig); - let result; function identityCallback(response) { @@ -3970,6 +4053,7 @@ describe('identity', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); result.httpCode.should.equal(-1); @@ -3981,8 +4065,6 @@ describe('identity', function() { }); it('should use the custom device id in known_identities when passed via setDeviceId', async () => { - mParticle._resetForTests(MPConfig); - fetchMockSuccess(urls.identify, { body: null }); @@ -3990,6 +4072,7 @@ describe('identity', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); expect(fetchMock.calls().length).to.equal(1); const firstCall = fetchMock.calls()[0]; expect(firstCall[0].split('/')[4]).to.equal('identify'); @@ -4008,6 +4091,7 @@ describe('identity', function() { mParticle.Identity.login({ userIdentities: { customerid: 'test' } }); await waitForCondition(hasLoginReturned) + await Promise.resolve(); // Should include two more calls: Login and UIC expect(fetchMock.calls().length).to.equal(2); @@ -4019,8 +4103,6 @@ describe('identity', function() { }); it('should use the custom device id in known_identities when set via mParticle.config', async () => { - mParticle._resetForTests(MPConfig); - // Resets fetchMock so we can isolate calls for this tests fetchMock.restore(); @@ -4050,10 +4132,10 @@ describe('identity', function() { // Set the Max Age to be 1 second in the future for testing const X_MP_MAX_AGE = '1'; - mParticle._resetForTests(MPConfig); fetchMock.resetHistory(); await waitForCondition(hasIdentifyReturned) + await Promise.resolve(); fetchMockSuccess( urls.identify, { @@ -4083,6 +4165,7 @@ describe('identity', function() { ?.userIdentities?.email === 'test@gmail.com' ); }) + await Promise.resolve(); const now = new Date(); const idCache: IdentityCache = JSON.parse( localStorage.getItem('mprtcl-v4_abcdef-id-cache') @@ -4113,7 +4196,6 @@ describe('identity', function() { it('should not call identify if no identities have changed within the expiration time', async () => { const X_MP_MAX_AGE = '1'; - mParticle._resetForTests(MPConfig); fetchMockSuccess(urls.identify, { mpid: testMPID, @@ -4137,6 +4219,7 @@ describe('identity', function() { await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); // Just make sure calls were actually made expect(fetchMock.calls().length).to.greaterThanOrEqual(1); @@ -4149,6 +4232,7 @@ describe('identity', function() { mParticle.Identity.identify(identities, callback); await waitForCondition(hasIdentifyReturned) + await Promise.resolve(); expect(fetchMock.calls().length).to.equal(0); // callback still gets called even if the identity call is not made` @@ -4160,8 +4244,6 @@ describe('identity', function() { let callbackCalled = false; - mParticle._resetForTests(MPConfig); - fetchMockSuccess(urls.identify, { mpid: testMPID, is_logged_in: false, @@ -4183,6 +4265,7 @@ describe('identity', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); const initialIdentityCall = fetchMock.calls()[0]; expect(initialIdentityCall[0].split('/')[4]).to.equal('identify'); @@ -4202,6 +4285,7 @@ describe('identity', function() { clock.restore(); await waitForCondition(() => callbackCalled) + await Promise.resolve(); expect(fetchMock.calls().length).to.equal(1); const duplicateIdentityCall = fetchMock.calls()[0]; @@ -4215,8 +4299,6 @@ describe('identity', function() { let callbackCalled = false; - mParticle._resetForTests(MPConfig); - fetchMockSuccess(urls.identify, { mpid: testMPID, is_logged_in: true, @@ -4245,6 +4327,7 @@ describe('identity', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); fetchMock.resetHistory(); @@ -4255,6 +4338,7 @@ describe('identity', function() { mParticle.Identity.login(identities, callback); await waitForCondition(() => mParticle.Identity?.getCurrentUser()?.getMPID() === testMPID) + await Promise.resolve(); // Just make sure calls were actually made expect(fetchMock.calls().length).to.greaterThanOrEqual(1); @@ -4270,6 +4354,7 @@ describe('identity', function() { await waitForCondition(() => { return callbackCalled; }) + await Promise.resolve(); expect(fetchMock.calls().length).to.equal(0); @@ -4282,8 +4367,6 @@ describe('identity', function() { let callbackCalled = false; - mParticle._resetForTests(MPConfig); - fetchMockSuccess(urls.identify, { mpid: testMPID, is_logged_in: true, @@ -4313,6 +4396,7 @@ describe('identity', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); const initialIdentityCall = fetchMock.calls()[0]; expect(initialIdentityCall[0].split('/')[4]).to.equal('identify'); @@ -4326,6 +4410,7 @@ describe('identity', function() { mParticle.Identity.login(identities, callback); await waitForCondition(() => callbackCalled) + await Promise.resolve(); // Just make sure calls were actually made expect(fetchMock.calls().length).to.greaterThanOrEqual(1); @@ -4345,6 +4430,7 @@ describe('identity', function() { clock.restore(); await waitForCondition(() => callbackCalled) + await Promise.resolve(); expect(fetchMock.calls().length).to.equal(1); const secondLoginCall = fetchMock.calls()[0]; @@ -4355,7 +4441,6 @@ describe('identity', function() { it('should clear cache when modify is called', async () => { const X_MP_MAX_AGE = '1'; - mParticle._resetForTests(MPConfig); fetchMockSuccess(urls.identify, { mpid: testMPID, @@ -4390,6 +4475,7 @@ describe('identity', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); const idCache = localStorage.getItem('mprtcl-v4_abcdef-id-cache'); expect(idCache).to.be.ok; @@ -4401,6 +4487,7 @@ describe('identity', function() { }); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); const secondIdCache = localStorage.getItem( 'mprtcl-v4_abcdef-id-cache' ); @@ -4410,7 +4497,6 @@ describe('identity', function() { it('should clear cache when logout is called', async () => { const X_MP_MAX_AGE = '1'; - mParticle._resetForTests(MPConfig); fetchMockSuccess(urls.identify, { mpid: testMPID, @@ -4441,6 +4527,7 @@ describe('identity', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); let idCache = localStorage.getItem('mprtcl-v4_abcdef-id-cache'); expect(idCache).to.be.ok; @@ -4448,6 +4535,7 @@ describe('identity', function() { mParticle.Identity.logout(); await waitForCondition(hasIdentityCallInflightReturned) + await Promise.resolve(); let secondIdCache = localStorage.getItem( 'mprtcl-v4_abcdef-id-cache' @@ -4463,7 +4551,6 @@ describe('identity', function() { const testRoktMPID = 'rokt-user'; beforeEach(function() { - mParticle._resetForTests(MPConfig); fetchMock.resetHistory(); roktConfig = { @@ -4493,6 +4580,7 @@ describe('identity', function() { mParticle.init(apiKey, { ...window.mParticle.config, kitConfigs: [roktConfig] }); await waitForCondition(() => hasIdentifyReturned(testRoktMPID)); + await Promise.resolve(); const mpInstance = mParticle.getInstance(); @@ -4505,6 +4593,7 @@ describe('identity', function() { }); await waitForCondition(() => hasIdentifyReturnedWithEmail(testRoktEmail)); + await Promise.resolve(); expect(mpInstance._RoktManager['currentUser']).to.not.be.null; expect(mpInstance._RoktManager['currentUser'].getUserIdentities().userIdentities.email).to.equal(testRoktEmail); @@ -4531,12 +4620,14 @@ describe('identity', function() { mParticle.init(apiKey, { ...window.mParticle.config, kitConfigs: [roktConfig] }); await waitForCondition(hasIdentityCallInflightReturned); + await Promise.resolve(); const mpInstance = mParticle.getInstance(); mpInstance._RoktManager.attachKit(roktKit); await waitForCondition(hasIdentityCallInflightReturned); + await Promise.resolve(); expect(mpInstance._RoktManager['currentUser']).be.null; }) @@ -4555,6 +4646,7 @@ describe('identity', function() { mParticle.init(apiKey, { ...window.mParticle.config, kitConfigs: [roktConfig] }); await waitForCondition(() => hasIdentifyReturned('testMPID')); + await Promise.resolve(); fetchMock.post(urls.identify, { status: HTTP_BAD_REQUEST, @@ -4584,6 +4676,7 @@ describe('identity', function() { }); await waitForCondition(hasIdentityCallInflightReturned); + await Promise.resolve(); // Current user will be the initial anonymous user from the initial identify call via mParticle.init // but should not have an email @@ -4601,6 +4694,7 @@ describe('identity', function() { mParticle.init(apiKey, window.mParticle.config); const bond = sinon.spy(mParticle.getInstance().Logger, 'warning'); await waitForCondition(hasIdentifyReturned) + await Promise.resolve(); mParticle .getInstance() .Identity.getCurrentUser() @@ -4620,6 +4714,7 @@ describe('identity', function() { const bond = sinon.spy(mParticle.getInstance().Logger, 'warning'); await waitForCondition(hasIdentifyReturned) + await Promise.resolve(); const product: SDKProduct = mParticle.eCommerce.createProduct( 'iPhone', @@ -4649,6 +4744,7 @@ describe('identity', function() { const bond = sinon.spy(mParticle.getInstance().Logger, 'warning'); await waitForCondition(hasIdentifyReturned) + await Promise.resolve(); const product: SDKProduct = mParticle.eCommerce.createProduct( 'iPhone', @@ -4677,6 +4773,7 @@ describe('identity', function() { mParticle.init(apiKey, window.mParticle.config); const bond = sinon.spy(mParticle.getInstance().Logger, 'warning'); await waitForCondition(hasIdentifyReturned) + await Promise.resolve(); mParticle .getInstance() .Identity.getCurrentUser() @@ -4700,6 +4797,7 @@ describe('identity', function() { const bond = sinon.spy(mParticle.getInstance().Logger, 'warning'); await waitForCondition(hasIdentifyReturned) + await Promise.resolve(); mParticle .getInstance() diff --git a/test/src/tests-identityApiClient.ts b/test/src/tests-identityApiClient.ts index 9b7247972..64e4e886c 100644 --- a/test/src/tests-identityApiClient.ts +++ b/test/src/tests-identityApiClient.ts @@ -690,13 +690,15 @@ describe('Identity Api Client', () => { const aliasUrl = 'https://jssdks.mparticle.com/v1/identity/test_key/Alias'; beforeEach(function() { + mParticle._resetForTests(MPConfig); + fetchMock.config.overwriteRoutes = true; fetchMockSuccess(urls.events); mParticle.init(apiKey, window.mParticle.config); }); afterEach(function() { fetchMock.restore(); - mParticle._resetForTests(MPConfig); + sinon.restore(); }); it('should have just an httpCode on the result passed to the callback on a 200', async () => { From 600d90ac36fe65dd52cf3759f19db1ff200f114a Mon Sep 17 00:00:00 2001 From: Jaissica Date: Wed, 22 Oct 2025 17:48:57 -0400 Subject: [PATCH 02/40] test: added .only to test files for targeted testing --- test/src/tests-identities-attributes.ts | 45 +-- test/src/tests-identity.ts | 453 ++++++++---------------- test/src/tests-identityApiClient.ts | 2 +- 3 files changed, 148 insertions(+), 352 deletions(-) diff --git a/test/src/tests-identities-attributes.ts b/test/src/tests-identities-attributes.ts index 99b49fcda..fd181c0bd 100644 --- a/test/src/tests-identities-attributes.ts +++ b/test/src/tests-identities-attributes.ts @@ -53,7 +53,7 @@ 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; @@ -91,7 +91,6 @@ describe('identities and attributes', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned); - await Promise.resolve(); mParticle.Identity.getCurrentUser().setUserAttribute('gender', 'male'); @@ -113,7 +112,6 @@ describe('identities and attributes', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned); - await Promise.resolve(); mParticle.Identity.getCurrentUser().setUserAttribute('Gender', 'male'); mParticle.Identity.getCurrentUser().setUserAttribute( 'gender', @@ -148,7 +146,6 @@ describe('identities and attributes', function() { mockForwarder.register(window.mParticle.config); mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned); - await Promise.resolve(); mParticle.Identity.getCurrentUser().setUserAttributes({ gender: 'male', age: 21, @@ -173,7 +170,6 @@ describe('identities and attributes', function() { mockForwarder.register(window.mParticle.config); mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned); - await Promise.resolve(); mParticle.Identity.getCurrentUser().setUserAttribute('gender', 'male'); mParticle.Identity.getCurrentUser().removeUserAttribute('gender'); @@ -191,7 +187,6 @@ describe('identities and attributes', function() { mockForwarder.register(window.mParticle.config); mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned); - await Promise.resolve(); mParticle.Identity.getCurrentUser().setUserAttribute('Gender', 'male'); mParticle.Identity.getCurrentUser().removeUserAttribute('gender'); @@ -207,7 +202,6 @@ describe('identities and attributes', function() { it('should set session attribute', async () => { await waitForCondition(hasIdentifyReturned); - await Promise.resolve(); mParticle.setSessionAttribute('name', 'test'); @@ -231,7 +225,6 @@ describe('identities and attributes', function() { it('should set session attribute case insensitive', async () => { await waitForCondition(hasIdentifyReturned); - await Promise.resolve(); mParticle.setSessionAttribute('name', 'test'); mParticle.setSessionAttribute('Name', 'test1'); @@ -254,7 +247,6 @@ describe('identities and attributes', function() { it("should not set a session attribute's key as an object or array)", async () => { await waitForCondition(hasIdentifyReturned); - await Promise.resolve(); mParticle.setSessionAttribute( BAD_SESSION_ATTRIBUTE_KEY_AS_OBJECT, @@ -288,7 +280,6 @@ describe('identities and attributes', function() { it('should remove session attributes when session ends', async () => { await waitForCondition(hasIdentifyReturned); - await Promise.resolve(); mParticle.startNewSession(); mParticle.setSessionAttribute('name', 'test'); @@ -310,7 +301,6 @@ describe('identities and attributes', function() { it('should set and log position', async () => { await waitForCondition(hasIdentifyReturned); - await Promise.resolve(); mParticle.setPosition(34.134103, -118.321694); mParticle.logEvent('Test Event'); @@ -324,7 +314,6 @@ describe('identities and attributes', function() { it('should set user tag', async () => { await waitForCondition(hasIdentifyReturned); - await Promise.resolve(); mParticle.Identity.getCurrentUser().setUserTag('test'); @@ -341,7 +330,6 @@ describe('identities and attributes', function() { it('should set user tag case insensitive', async () => { await waitForCondition(hasIdentifyReturned); - await Promise.resolve(); mParticle.Identity.getCurrentUser().setUserTag('Test'); mParticle.Identity.getCurrentUser().setUserTag('test'); @@ -360,7 +348,6 @@ describe('identities and attributes', function() { it('should remove user tag', async () => { await waitForCondition(hasIdentifyReturned); - await Promise.resolve(); mParticle.Identity.getCurrentUser().setUserTag('test'); mParticle.Identity.getCurrentUser().removeUserTag('test'); @@ -378,7 +365,6 @@ describe('identities and attributes', function() { it('should remove user tag case insensitive', async () => { await waitForCondition(hasIdentifyReturned); - await Promise.resolve(); mParticle.Identity.getCurrentUser().setUserTag('Test'); mParticle.Identity.getCurrentUser().removeUserTag('test'); @@ -397,7 +383,6 @@ describe('identities and attributes', function() { it('should set user attribute list', async () => { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned); - await Promise.resolve(); mParticle.Identity.getCurrentUser().setUserAttributeList('numbers', [ 1, 2, @@ -422,7 +407,6 @@ describe('identities and attributes', function() { it('should set user attribute list case insensitive', async () => { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned); - await Promise.resolve(); mParticle.Identity.getCurrentUser().setUserAttributeList('numbers', [ 1, 2, @@ -476,7 +460,6 @@ describe('identities and attributes', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned); - await Promise.resolve(); mParticle.Identity.getCurrentUser().setUserAttributeList( 'numbers', list @@ -500,7 +483,6 @@ describe('identities and attributes', function() { it('should remove all user attributes', async () => { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned); - await Promise.resolve(); mParticle.Identity.getCurrentUser().setUserAttributeList('numbers', [ 1, 2, @@ -525,7 +507,6 @@ describe('identities and attributes', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned); - await Promise.resolve(); mParticle.Identity.getCurrentUser().setUserAttribute('gender', 'male'); mParticle.Identity.getCurrentUser().setUserAttributeList('numbers', [ @@ -546,7 +527,6 @@ describe('identities and attributes', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned); - await Promise.resolve(); mParticle.Identity.getCurrentUser().setUserAttribute('gender', 'male'); mParticle.Identity.getCurrentUser().setUserAttributeList('numbers', [ 1, @@ -567,7 +547,6 @@ describe('identities and attributes', function() { it('should copy when calling get user attributes', async () => { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned); - await Promise.resolve(); mParticle.Identity.getCurrentUser().setUserAttribute('gender', 'male'); mParticle.Identity.getCurrentUser().setUserAttributeList('numbers', [ 1, @@ -591,7 +570,6 @@ describe('identities and attributes', function() { it('should get all user attributes', async () => { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned); - await Promise.resolve(); mParticle.Identity.getCurrentUser().setUserAttribute('test', '123'); mParticle.Identity.getCurrentUser().setUserAttribute( 'another test', @@ -607,7 +585,6 @@ describe('identities and attributes', function() { it('should not set user attribute list if value is not array', async () => { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned); - await Promise.resolve(); mParticle.Identity.getCurrentUser().setUserAttributeList( 'mykey', BAD_USER_ATTRIBUTE_LIST_VALUE @@ -620,7 +597,6 @@ describe('identities and attributes', function() { it('should not set bad session attribute value', async () => { await waitForCondition(hasIdentifyReturned); - await Promise.resolve(); mParticle.setSessionAttribute( 'name', BAD_SESSION_ATTRIBUTE_VALUE_AS_OBJECT @@ -640,7 +616,6 @@ describe('identities and attributes', function() { it('should not set a bad user attribute key or value', async () => { await waitForCondition(hasIdentifyReturned); - await Promise.resolve(); mParticle.Identity.getCurrentUser().setUserAttribute('gender', { bad: 'bad', }); @@ -720,7 +695,6 @@ describe('identities and attributes', function() { it('should send user attribute change requests when setting new attributes', async () => { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned); - await Promise.resolve(); // set a new attribute, age fetchMock.resetHistory(); mParticle.Identity.getCurrentUser().setUserAttribute('age', '25'); @@ -833,7 +807,6 @@ describe('identities and attributes', function() { it('should send user attribute change requests for the MPID it is being set on', async () => { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned); - await Promise.resolve(); mParticle.Identity.getCurrentUser().setUserAttribute('age', '25'); const testMPID = mParticle.Identity.getCurrentUser().getMPID(); @@ -867,7 +840,6 @@ describe('identities and attributes', function() { mParticle.Identity.getCurrentUser()?.getMPID() === 'anotherMPID' ); }); - await Promise.resolve(); const users = mParticle.Identity.getUsers(); expect(users.length).to.equal(2); @@ -936,7 +908,6 @@ describe('identities and attributes', function() { mParticle.config.flags.eventBatchingIntervalMillis = 5000 mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned); - await Promise.resolve(); mParticle.upload(); expect( JSON.parse(`${fetchMock.lastOptions().body}`).user_identities @@ -967,7 +938,6 @@ describe('identities and attributes', function() { mParticle.Identity.getCurrentUser()?.getMPID() === 'anotherMPID' ); }); - await Promise.resolve(); let body = JSON.parse(`${fetchMock.lastOptions().body}`); // should be the new MPID @@ -1017,7 +987,6 @@ describe('identities and attributes', function() { mParticle.getInstance()._Store.identityCallInFlight === false ); }); - await Promise.resolve(); const body2 = JSON.parse(`${fetchMock.lastOptions().body}`); expect(body2.mpid).to.equal('anotherMPID'); expect(body2.user_identities).to.have.property( @@ -1054,7 +1023,6 @@ describe('identities and attributes', function() { mParticle.getInstance()._Store.identityCallInFlight === false ); }); - await Promise.resolve(); const body3 = JSON.parse(`${fetchMock.lastOptions().body}`); expect(body3.mpid).to.equal('anotherMPID'); @@ -1089,7 +1057,6 @@ describe('identities and attributes', function() { mParticle.Identity.getCurrentUser()?.getMPID() === 'mpid2' ); }); - await Promise.resolve(); // Calls are for logout and UIC expect(fetchMock.calls().length).to.equal(2); const body4 = JSON.parse(`${fetchMock.lastOptions().body}`); @@ -1122,7 +1089,6 @@ describe('identities and attributes', function() { // Clear out before each init call await waitForCondition(hasBeforeEachCallbackReturned); - await Promise.resolve(); window.mParticle.config.identifyRequest = { userIdentities: { @@ -1133,7 +1099,6 @@ describe('identities and attributes', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentityCallInflightReturned); - await Promise.resolve(); mParticle.logEvent('Test Event 1'); mParticle.logEvent('Test Event 2'); @@ -1187,7 +1152,6 @@ describe('identities and attributes', function() { // Clear out before each init call await waitForCondition(hasBeforeEachCallbackReturned); - await Promise.resolve(); window.mParticle.config.identifyRequest = { userIdentities: { @@ -1204,7 +1168,6 @@ describe('identities and attributes', function() { expect(mParticle.getInstance()._preInit.readyQueue.length).to.equal(3); await waitForCondition(hasIdentityCallInflightReturned); - await Promise.resolve(); expect(fetchMock.calls().length).to.equal(7); @@ -1263,7 +1226,6 @@ describe('identities and attributes', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned); - await Promise.resolve(); fetchMockSuccess(urls.login, { mpid: 'testMPID', is_logged_in: true }); @@ -1281,7 +1243,6 @@ describe('identities and attributes', function() { mParticle.getInstance()._Store.identityCallInFlight === false ); }); - await Promise.resolve(); let batch = JSON.parse(`${fetchMock.lastOptions().body}`); expect(batch.mpid).to.equal(testMPID); expect(batch.user_identities).to.have.property( @@ -1310,7 +1271,6 @@ describe('identities and attributes', function() { mParticle.Identity.getCurrentUser()?.getMPID() === 'mpid2' ); }); - await Promise.resolve(); batch = JSON.parse(`${fetchMock.lastOptions().body}`); expect(batch.mpid).to.equal('mpid2'); expect(batch.user_identities).to.have.property('other', 'other1'); @@ -1331,7 +1291,6 @@ describe('identities and attributes', function() { mParticle.getInstance()._Store.identityCallInFlight === false ); }); - await Promise.resolve(); expect(fetchMock.calls().length).to.equal(1); const data = getIdentityEvent(fetchMock.calls(), 'login'); @@ -1358,7 +1317,6 @@ describe('identities and attributes', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned); - await Promise.resolve(); // set a new attribute, age fetchMock.resetHistory(); mParticle.Identity.getCurrentUser().setUserAttribute('age', '25'); @@ -1454,7 +1412,6 @@ describe('identities and attributes', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned); - await Promise.resolve(); // set initial test attribute with 'falsey' value to 0 fetchMock.resetHistory(); mParticle.Identity.getCurrentUser().setUserAttribute('testFalsey', 0); diff --git a/test/src/tests-identity.ts b/test/src/tests-identity.ts index 5f0bfbc5b..b68770328 100644 --- a/test/src/tests-identity.ts +++ b/test/src/tests-identity.ts @@ -89,7 +89,7 @@ const fetchMockSuccess = (url: string, body: any = {}, headers: any = {}) => { ); }; -describe('identity', function() { +describe.only('identity', function() { let clock; let hasIdentifyReturned; let hasIdentifyReturnedWithEmail; @@ -175,8 +175,7 @@ describe('identity', function() { }, }); - await waitForCondition(hasIdentifyReturned) - await Promise.resolve(); + await waitForCondition(hasIdentifyReturned); // Calls should be expected // 1. Identify @@ -218,8 +217,7 @@ describe('identity', function() { is_logged_in: false, }); - await waitForCondition(hasIdentifyReturned) - await Promise.resolve(); + await waitForCondition(hasIdentifyReturned); mParticle.Identity.logout(); @@ -253,8 +251,7 @@ describe('identity', function() { }); it('should contain login request', async () => { - await waitForCondition(hasIdentifyReturned) - await Promise.resolve(); + await waitForCondition(hasIdentifyReturned); fetchMockSuccess(urls.login, { mpid: testMPID, @@ -272,8 +269,7 @@ describe('identity', function() { }, }); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); // Calls that should be expected: // 1. Identify @@ -321,8 +317,7 @@ describe('identity', function() { ], }); - await waitForCondition(hasIdentifyReturned) - await Promise.resolve(); + await waitForCondition(hasIdentifyReturned); mParticle.Identity.modify({ userIdentities: { email: 'test@email.com', @@ -374,8 +369,7 @@ describe('identity', function() { let data: IIdentityAPIRequestData; - await waitForCondition(hasIdentifyReturned) - await Promise.resolve(); + await waitForCondition(hasIdentifyReturned); mParticle.Identity.identify({ userIdentities: { @@ -383,8 +377,7 @@ describe('identity', function() { }, }); - await waitForCondition(hasIdentifyReturned) - await Promise.resolve(); + await waitForCondition(hasIdentifyReturned); // 4 Calls should be expected // 1. Identify @@ -418,8 +411,7 @@ describe('identity', function() { }); it('should strip falsey values from identify request', async () => { - await waitForCondition(hasIdentifyReturned) - await Promise.resolve(); + await waitForCondition(hasIdentifyReturned); const identityApiData = { userIdentities: { @@ -436,8 +428,7 @@ describe('identity', function() { mParticle.Identity.identify(identityApiData as unknown as IdentityApiData); - await waitForCondition(hasIdentifyReturned) - await Promise.resolve(); + await waitForCondition(hasIdentifyReturned); const firstCall = fetchMock.calls()[0]; expect(firstCall[0].split('/')[4]).to.equal('identify'); @@ -478,8 +469,7 @@ describe('identity', function() { }); it('should strip falsey values from login request', async () => { - await waitForCondition(hasIdentifyReturned) - await Promise.resolve(); + await waitForCondition(hasIdentifyReturned); const identityApiData = { userIdentities: { @@ -506,8 +496,7 @@ describe('identity', function() { mParticle.Identity.login(identityApiData as unknown as IdentityApiData); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); const firstCall = fetchMock.calls()[0]; expect(firstCall[0].split('/')[4]).to.equal('login'); @@ -538,8 +527,7 @@ describe('identity', function() { }); it('should strip falsey values from logout request', async () => { - await waitForCondition(hasIdentifyReturned) - await Promise.resolve(); + await waitForCondition(hasIdentifyReturned); const identityApiData = { userIdentities: { @@ -566,8 +554,7 @@ describe('identity', function() { mParticle.Identity.logout(identityApiData as unknown as IdentityApiData); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); const firstCall = fetchMock.calls()[0]; expect(firstCall[0].split('/')[4]).to.equal('logout'); @@ -598,8 +585,7 @@ describe('identity', function() { }); it('should strip falsey values from modify request', async () => { - await waitForCondition(hasIdentifyReturned) - await Promise.resolve(); + await waitForCondition(hasIdentifyReturned); const identityApiData = { userIdentities: { @@ -625,8 +611,7 @@ describe('identity', function() { mParticle.Identity.modify(identityApiData as unknown as IdentityApiData); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); const firstCall = fetchMock.calls()[0]; expect(firstCall[0].split('/')[5]).to.equal('modify'); @@ -666,7 +651,6 @@ describe('identity', function() { it('should save id cache to local storage when noFunctional is false by default', async () => { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned); - await Promise.resolve(); expect(localStorage.getItem('mprtcl-v4_abcdef-id-cache')).to.be.ok; }); @@ -674,7 +658,6 @@ describe('identity', function() { mParticle.config.launcherOptions = { noFunctional: true }; mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned); - await Promise.resolve(); expect(localStorage.getItem('mprtcl-v4_abcdef-id-cache')).not.to.be.ok; }); @@ -682,7 +665,6 @@ describe('identity', function() { mParticle.config.launcherOptions = { noFunctional: false }; mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned); - await Promise.resolve(); expect(localStorage.getItem('mprtcl-v4_abcdef-id-cache')).to.be.ok; }); }); @@ -734,8 +716,7 @@ describe('identity', function() { mParticle.init(apiKey, window.mParticle.config); - await waitForCondition( () => mParticle.Identity.getCurrentUser()?.getMPID() === 'MPID1') - await Promise.resolve(); + await waitForCondition( () => mParticle.Identity.getCurrentUser()?.getMPID() === 'MPID1'); let activeForwarders = mParticle.getInstance()._getActiveForwarders(); expect(activeForwarders.length).to.equal(0); @@ -758,8 +739,7 @@ describe('identity', function() { mParticle.Identity.login(); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); activeForwarders = mParticle.getInstance()._getActiveForwarders(); expect(activeForwarders.length).to.equal(0); @@ -778,8 +758,7 @@ describe('identity', function() { describe('cookies', function () { it('should store all MPIDs associated with a sessionId, then clear MPIDs from currentSessionMPIDs when a new session starts', async () => { - await waitForCondition(hasIdentifyReturned) - await Promise.resolve(); + await waitForCondition(hasIdentifyReturned); fetchMockSuccess(urls.login, { mpid: 'logged-in-user', @@ -793,8 +772,7 @@ describe('identity', function() { }; mParticle.Identity.login(userIdentities1); - await waitForCondition(hasLoginReturned) - await Promise.resolve(); + await waitForCondition(hasLoginReturned); const localStorageDataBeforeSessionEnd = mParticle .getInstance() @@ -811,8 +789,7 @@ describe('identity', function() { mParticle.logEvent('hi'); mParticle.Identity.login(userIdentities1); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); const localStorageAfterLoggingEvent = mParticle .getInstance() @@ -843,8 +820,7 @@ describe('identity', function() { }; mParticle.Identity.login(userIdentities1); - await waitForCondition(hasLoginReturned) - await Promise.resolve(); + await waitForCondition(hasLoginReturned); const cookiesAfterMPIDChange = mParticle .getInstance() ._Persistence.getLocalStorage(); @@ -889,8 +865,7 @@ describe('identity', function() { mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentifyReturned) - await Promise.resolve(); + await waitForCondition(hasIdentifyReturned); const cookiesAfterInit = findCookie(); cookiesAfterInit.should.have.properties('gs', 'cu', testMPID); @@ -925,8 +900,7 @@ describe('identity', function() { mParticle.Identity.login(userIdentities1); - await waitForCondition(hasLoginReturned) - await Promise.resolve(); + await waitForCondition(hasLoginReturned); const cookiesAfterMPIDChange = findCookie(); cookiesAfterMPIDChange.should.have.properties([ @@ -1390,7 +1364,7 @@ describe('identity', function() { mParticle.Identity.login(identityAPIRequest); await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + expect(fetchMock.calls().length).to.equal(0); }); @@ -1398,8 +1372,7 @@ describe('identity', function() { const identityAPIRequest = BAD_USER_IDENTITIES_AS_ARRAY; mParticle.Identity.login(identityAPIRequest); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); expect(fetchMock.calls().length).to.equal(0); }); @@ -1407,8 +1380,7 @@ describe('identity', function() { const identityAPIRequest = BAD_USER_IDENTITIES_AS_NULL; mParticle.Identity.login(identityAPIRequest); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); expect(fetchMock.calls().length).to.equal(0); }); @@ -1416,8 +1388,7 @@ describe('identity', function() { const identityAPIRequest = BAD_USER_IDENTITIES_AS_UNDEFINED; mParticle.Identity.login(identityAPIRequest); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); expect(fetchMock.calls().length).to.equal(0); }); @@ -1425,8 +1396,7 @@ describe('identity', function() { const identityAPIRequest = BAD_USER_IDENTITIES_AS_BOOLEAN; mParticle.Identity.login(identityAPIRequest); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); expect(fetchMock.calls().length).to.equal(0); }); @@ -1440,8 +1410,7 @@ describe('identity', function() { mParticle.Identity.login(identityRequest, badCallback); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); expect(fetchMock.calls().length).to.equal(0); }); }); @@ -1456,8 +1425,7 @@ describe('identity', function() { const identityAPIRequest = BAD_USER_IDENTITIES_AS_STRING; mParticle.Identity.logout(identityAPIRequest); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); expect(fetchMock.calls().length).to.equal(0); }); @@ -1465,8 +1433,7 @@ describe('identity', function() { const identityAPIRequest = BAD_USER_IDENTITIES_AS_ARRAY; mParticle.Identity.logout(identityAPIRequest); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); expect(fetchMock.calls().length).to.equal(0); }); @@ -1474,8 +1441,7 @@ describe('identity', function() { const identityAPIRequest = BAD_USER_IDENTITIES_AS_NULL; mParticle.Identity.logout(identityAPIRequest); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); expect(fetchMock.calls().length).to.equal(0); }); @@ -1483,8 +1449,7 @@ describe('identity', function() { const identityAPIRequest = BAD_USER_IDENTITIES_AS_UNDEFINED; mParticle.Identity.logout(identityAPIRequest); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); expect(fetchMock.calls().length).to.equal(0); }); @@ -1492,8 +1457,7 @@ describe('identity', function() { const identityAPIRequest = BAD_USER_IDENTITIES_AS_BOOLEAN; mParticle.Identity.logout(identityAPIRequest); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); expect(fetchMock.calls().length).to.equal(0); }); @@ -1507,8 +1471,7 @@ describe('identity', function() { mParticle.Identity.logout(identityRequest, badCallback); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); expect(fetchMock.calls().length).to.equal(0); }); }); @@ -1524,8 +1487,7 @@ describe('identity', function() { debugger mParticle.Identity.modify(identityAPIRequest); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); expect(fetchMock.calls().length).to.equal(0); }); @@ -1533,8 +1495,7 @@ describe('identity', function() { const identityAPIRequest = BAD_USER_IDENTITIES_AS_ARRAY; mParticle.Identity.modify(identityAPIRequest); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); expect(fetchMock.calls().length).to.equal(0); }); @@ -1542,8 +1503,7 @@ describe('identity', function() { const identityAPIRequest = BAD_USER_IDENTITIES_AS_NULL; mParticle.Identity.modify(identityAPIRequest); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); expect(fetchMock.calls().length).to.equal(0); }); @@ -1551,8 +1511,7 @@ describe('identity', function() { const identityAPIRequest = BAD_USER_IDENTITIES_AS_UNDEFINED; mParticle.Identity.modify(identityAPIRequest); -await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); expect(fetchMock.calls().length).to.equal(0); }); @@ -1560,8 +1519,7 @@ await waitForCondition(hasIdentityCallInflightReturned) const identityAPIRequest = BAD_USER_IDENTITIES_AS_BOOLEAN; mParticle.Identity.modify(identityAPIRequest); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); expect(fetchMock.calls().length).to.equal(0); }); @@ -1575,8 +1533,7 @@ await waitForCondition(hasIdentityCallInflightReturned) mParticle.Identity.modify(identityRequest, badCallback); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); expect(fetchMock.calls().length).to.equal(0); }); }); @@ -1591,8 +1548,7 @@ await waitForCondition(hasIdentityCallInflightReturned) const identityAPIRequest = BAD_USER_IDENTITIES_AS_STRING; mParticle.Identity.identify(identityAPIRequest); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); expect(fetchMock.calls().length).to.equal(0); }); @@ -1600,8 +1556,7 @@ await waitForCondition(hasIdentityCallInflightReturned) const identityAPIRequest = BAD_USER_IDENTITIES_AS_ARRAY; mParticle.Identity.identify(identityAPIRequest); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); expect(fetchMock.calls().length).to.equal(0); }); @@ -1609,8 +1564,7 @@ await waitForCondition(hasIdentityCallInflightReturned) const identityAPIRequest = BAD_USER_IDENTITIES_AS_NULL; mParticle.Identity.identify(identityAPIRequest); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); expect(fetchMock.calls().length).to.equal(0); }); @@ -1618,8 +1572,7 @@ await waitForCondition(hasIdentityCallInflightReturned) const identityAPIRequest = BAD_USER_IDENTITIES_AS_UNDEFINED; mParticle.Identity.identify(identityAPIRequest); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); expect(fetchMock.calls().length).to.equal(0); }); @@ -1627,8 +1580,7 @@ await waitForCondition(hasIdentityCallInflightReturned) const identityAPIRequest = BAD_USER_IDENTITIES_AS_BOOLEAN; mParticle.Identity.identify(identityAPIRequest); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); expect(fetchMock.calls().length).to.equal(0); }); @@ -1642,8 +1594,7 @@ await waitForCondition(hasIdentityCallInflightReturned) mParticle.Identity.identify(identityRequest, badCallback); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); expect(fetchMock.calls().length).to.equal(0); }); }); @@ -1739,7 +1690,6 @@ await waitForCondition(hasIdentityCallInflightReturned) // https://go.mparticle.com/work/SQDSDKS-6568 it('should create a proper send request when passing identities to modify', async () => { await waitForCondition(hasIdentifyReturned) - await Promise.resolve(); const identityAPIData: IdentityApiData = { userIdentities: { email: 'rob@gmail.com', @@ -1756,14 +1706,12 @@ await waitForCondition(hasIdentityCallInflightReturned) ], }); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); fetchMock.resetHistory(); mParticle.Identity.modify(identityAPIData); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); // 1st call is modify, 2nd call is the UIC event expect(fetchMock.calls().length).to.equal(2); @@ -1789,8 +1737,7 @@ await waitForCondition(hasIdentityCallInflightReturned) mParticle._resetForTests(MPConfig); const spy = sinon.spy(); - await waitForCondition(hasIdentifyReturned) - await Promise.resolve(); + await waitForCondition(hasIdentifyReturned); mParticle.config.identityCallback = spy; fetchMockSuccess(urls.identify, { @@ -1802,13 +1749,11 @@ await waitForCondition(hasIdentityCallInflightReturned) await waitForCondition(() => { return mParticle.Identity.getCurrentUser()?.getMPID() === 'otherMPID'; - }) - await Promise.resolve(); + }); spy.calledOnce.should.be.ok(); mParticle.startNewSession(); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); spy.calledOnce.should.be.ok(); }); @@ -1825,8 +1770,7 @@ await waitForCondition(hasIdentityCallInflightReturned) mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); mParticle.logEvent('Test Event 1'); // There should be 3 calls here: @@ -1851,8 +1795,7 @@ await waitForCondition(hasIdentityCallInflightReturned) mParticle.logEvent('Test Event 2'); mParticle.Identity.login(); - await waitForCondition(hasLoginReturned) - await Promise.resolve(); + await waitForCondition(hasLoginReturned); // server requests will now have the following events: // 1. Identify (from init) @@ -1913,8 +1856,7 @@ await waitForCondition(hasIdentityCallInflightReturned) mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); // get user 1 into cookies fetchMockSuccess(urls.login, { @@ -1924,8 +1866,7 @@ await waitForCondition(hasIdentityCallInflightReturned) mParticle.Identity.login(userIdentities1); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); // get user 2 into cookies fetchMockSuccess(urls.login, { @@ -1935,8 +1876,7 @@ await waitForCondition(hasIdentityCallInflightReturned) mParticle.Identity.login(userIdentities2); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); // get user 3 into cookies fetchMockSuccess(urls.login, { @@ -1946,8 +1886,7 @@ await waitForCondition(hasIdentityCallInflightReturned) mParticle.Identity.login(userIdentities3); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); // init again using user 1 fetchMockSuccess(urls.login, { @@ -1957,8 +1896,7 @@ await waitForCondition(hasIdentityCallInflightReturned) mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(() => mParticle.Identity?.getUsers().length === 4) - await Promise.resolve(); + await waitForCondition(() => mParticle.Identity?.getUsers().length === 4); const users = mParticle.Identity.getUsers(); // This includes the original, starting user, in addition to the 3 added above expect(users.length).to.equal(4); @@ -1997,8 +1935,7 @@ await waitForCondition(hasIdentityCallInflightReturned) mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); // get user 1 into cookies fetchMockSuccess(urls.login, { @@ -2008,8 +1945,7 @@ await waitForCondition(hasIdentityCallInflightReturned) mParticle.Identity.login(user1); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); mParticle.Identity.getCurrentUser().setUserAttribute('user', 'user1'); @@ -2021,8 +1957,7 @@ await waitForCondition(hasIdentityCallInflightReturned) mParticle.Identity.login(user2); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); mParticle.Identity.getCurrentUser().setUserAttribute('user', 'user2'); @@ -2034,8 +1969,7 @@ await waitForCondition(hasIdentityCallInflightReturned) mParticle.Identity.login(user3); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); mParticle.Identity.getCurrentUser().setUserAttribute('user', 'user3'); @@ -2047,8 +1981,7 @@ await waitForCondition(hasIdentityCallInflightReturned) mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); const localStorage = mParticle .getInstance() @@ -2142,16 +2075,14 @@ await waitForCondition(hasIdentityCallInflightReturned) ], }); - await waitForCondition(hasIdentifyReturned) - await Promise.resolve(); + await waitForCondition(hasIdentifyReturned); mParticle.Identity.modify(user1modified); // Should contain the following calls: // 1 for the initial identify // 3 for the events (Session Start, UAT and UIC) // 1 for the modify // 1 for the UIC event - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); expect(fetchMock.calls().length).to.equal(6); // This will add a new UAC Event to the call @@ -2183,8 +2114,7 @@ await waitForCondition(hasIdentityCallInflightReturned) mParticle.Identity.logout(user2); - await waitForCondition(hasLogOutReturned) - await Promise.resolve(); + await waitForCondition(hasLogOutReturned); // This will add the following new calls: // 1 for the logout @@ -2210,8 +2140,7 @@ await waitForCondition(hasIdentityCallInflightReturned) mParticle.Identity.login(user1); await waitForCondition(() => { return mParticle.Identity.getCurrentUser().getMPID() === 'testMPID'; - }) - await Promise.resolve(); + }); // This will add the following new calls: // 1 for the login @@ -2257,8 +2186,7 @@ await waitForCondition(hasIdentityCallInflightReturned) mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); const user1UIs = mParticle.Identity.getCurrentUser().getUserIdentities(); @@ -2271,8 +2199,7 @@ await waitForCondition(hasIdentityCallInflightReturned) mParticle.Identity.login(user2); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); const user2UIs = mParticle.Identity.getCurrentUser().getUserIdentities(); user2UIs.userIdentities.customerid.should.equal('2'); @@ -2284,8 +2211,7 @@ await waitForCondition(hasIdentityCallInflightReturned) mParticle.Identity.login(user3); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); const user3UIs = mParticle.Identity.getCurrentUser().getUserIdentities(); user3UIs.userIdentities.customerid.should.equal('3'); @@ -2297,8 +2223,7 @@ await waitForCondition(hasIdentityCallInflightReturned) mParticle.Identity.login(user4); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); const user4UIs = mParticle.Identity.getCurrentUser().getUserIdentities(); user4UIs.userIdentities.customerid.should.equal('4'); @@ -2310,8 +2235,7 @@ await waitForCondition(hasIdentityCallInflightReturned) mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); const user5 = mParticle.Identity.getCurrentUser(); user5.getUserIdentities().userIdentities.customerid.should.equal('1'); @@ -2329,8 +2253,7 @@ await waitForCondition(hasIdentityCallInflightReturned) it('should not send requests to the server with invalid userIdentity values', async () => { mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); fetchMock.resetHistory(); @@ -2431,8 +2354,7 @@ await waitForCondition(hasIdentityCallInflightReturned) callback ); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); expect(result, identityMethod).to.be.ok; expect( result.httpCode, @@ -2452,8 +2374,7 @@ await waitForCondition(hasIdentityCallInflightReturned) validUserIdentities.forEach(async(goodIdentities) => { mParticle.Identity.modify(goodIdentities, callback); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); expect(result, identityMethod).to.be.ok; @@ -2499,13 +2420,11 @@ await waitForCondition(hasIdentityCallInflightReturned) is_logged_in: false, }); - await waitForCondition(hasIdentifyReturned) - await Promise.resolve(); + await waitForCondition(hasIdentifyReturned); mParticle.Identity.login(user); - await waitForCondition(hasLoginReturned) - await Promise.resolve(); + await waitForCondition(hasLoginReturned); const userIdentities1 = mParticle.Identity.getCurrentUser().getUserIdentities(); @@ -2513,8 +2432,7 @@ await waitForCondition(hasIdentityCallInflightReturned) mParticle.Identity.logout(); - await waitForCondition(hasLogOutReturned) - await Promise.resolve(); + await waitForCondition(hasLogOutReturned); const userIdentities2 = mParticle.Identity.getCurrentUser().getUserIdentities(); @@ -2552,18 +2470,15 @@ await waitForCondition(hasIdentityCallInflightReturned) } ); - await waitForCondition(hasIdentifyReturned) - await Promise.resolve(); + await waitForCondition(hasIdentifyReturned); mParticle.Identity.login(user); - await waitForCondition(hasLoginReturned) - await Promise.resolve(); + await waitForCondition(hasLoginReturned); mParticle.Identity.modify(modifiedUser); await waitForCondition(() => { return mParticle.Identity.getCurrentUser()?.getUserIdentities().userIdentities['customerid'] === 'customerId2'; - }) - await Promise.resolve(); + }); const cookie = mParticle.getInstance()._Persistence.getLocalStorage(); cookie['logged-in-user'].ui[1].should.equal('customerId2'); @@ -2575,7 +2490,6 @@ await waitForCondition(hasIdentityCallInflightReturned) mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned); - await Promise.resolve(); const user1 = { userIdentities: { @@ -2603,7 +2517,6 @@ await waitForCondition(hasIdentityCallInflightReturned) mParticle.Identity.login(user1); await waitForCondition(hasIdentifyReturned); - await Promise.resolve(); fetchMockSuccess(urls.login, { mpid: 'otherMPID', @@ -2614,7 +2527,6 @@ await waitForCondition(hasIdentityCallInflightReturned) mParticle.Identity.login(user2); await waitForCondition(hasIdentityCallInflightReturned); - await Promise.resolve(); // This should have a call for the UIC that will occur because // we are logging in as two different users @@ -2626,7 +2538,6 @@ await waitForCondition(hasIdentityCallInflightReturned) mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned); - await Promise.resolve(); let hasBeenRun = false; const user1 = { @@ -2652,7 +2563,6 @@ await waitForCondition(hasIdentityCallInflightReturned) mParticle.Identity.login(user1); await waitForCondition(hasIdentityCallInflightReturned); - await Promise.resolve(); fetchMockSuccess(urls.login, { mpid: 'otherMPID', @@ -2662,7 +2572,7 @@ await waitForCondition(hasIdentityCallInflightReturned) mParticle.Identity.login(user2); await waitForCondition(hasIdentityCallInflightReturned); -await Promise.resolve(); + expect(hasBeenRun).to.be.true; }); @@ -2671,7 +2581,6 @@ await Promise.resolve(); mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentifyReturned); - await Promise.resolve(); const user1 = { userIdentities: { @@ -2687,7 +2596,6 @@ await Promise.resolve(); mParticle.Identity.login(user1); await waitForCondition(hasIdentityCallInflightReturned); - await Promise.resolve(); mParticle.Identity.getCurrentUser().setUserAttribute('gender', 'male'); mParticle.Identity.getCurrentUser().setUserAttribute('age', 27); @@ -2725,7 +2633,6 @@ await Promise.resolve(); mParticle.Identity.login(user2); await waitForCondition(() => mParticle.Identity.getCurrentUser().getMPID() === 'otherMPID'); - await Promise.resolve(); const user1ObjectAttrs = user1Object.getAllUserAttributes(); user1ObjectAttrs.should.not.have.property('age'); @@ -2765,7 +2672,6 @@ await Promise.resolve(); mParticle.Identity.login(user3); await waitForCondition(() => mParticle.Identity.getCurrentUser().getMPID() === 'otherMPID2'); - await Promise.resolve(); expect(user2AttributeListsBeforeRemoving.list.length).to.equal(5); @@ -2780,8 +2686,7 @@ await Promise.resolve(); it('should return an empty array when no cart products exist', async () => { mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentifyReturned) - await Promise.resolve(); + await waitForCondition(hasIdentifyReturned); const user1 = { userIdentities: { customerid: 'customerId1', @@ -2795,8 +2700,7 @@ await Promise.resolve(); mParticle.Identity.login(user1); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); const products = mParticle.Identity.getCurrentUser() .getCart() @@ -2808,8 +2712,7 @@ await Promise.resolve(); it('should make a request when copyUserAttributes is included on the identity request', async () => { mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentifyReturned) - await Promise.resolve(); + await waitForCondition(hasIdentifyReturned); const identityAPIRequest1 = { userIdentities: { @@ -2828,8 +2731,7 @@ await Promise.resolve(); mParticle.Identity.logout(identityAPIRequest1); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); // This should have a call for the logout and UIC expect(fetchMock.calls().length).to.equal(2); @@ -2849,8 +2751,7 @@ await Promise.resolve(); mParticle.Identity.login(identityAPIRequest1); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); expect(fetchMock.calls().length).to.equal(1); @@ -2869,8 +2770,7 @@ await Promise.resolve(); mParticle.Identity.modify(identityAPIRequest1); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); expect(fetchMock.calls().length).to.equal(1); @@ -2895,8 +2795,7 @@ await Promise.resolve(); mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); expect(mpid).to.equal('MPID1'); }); @@ -2904,8 +2803,7 @@ await Promise.resolve(); it('should trigger the identityCallback before eventQueue is flushed', async () => { mParticle._resetForTests(MPConfig); - await waitForCondition(hasBeforeEachCallbackReturned) - await Promise.resolve(); + await waitForCondition(hasBeforeEachCallbackReturned); fetchMock.resetHistory(); @@ -2932,8 +2830,7 @@ await Promise.resolve(); const identifyCall = fetchMock.lastCall(); expect(identifyCall[0].split('/')[4]).to.equal('identify'); - await waitForCondition(() => callbackCalled) - await Promise.resolve(); + await waitForCondition(() => callbackCalled); // Force an upload so we can verify the correct events have fired mParticle.upload(); @@ -2977,8 +2874,7 @@ await Promise.resolve(); mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentifyReturned) - await Promise.resolve(); + await waitForCondition(hasIdentifyReturned); // Should contain: // 1 for the Identify Request // 1 for the AST @@ -2995,8 +2891,7 @@ await Promise.resolve(); mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); // the server request is the AST, there is no request to Identity fetchMock.calls().length.should.equal(1); @@ -3045,8 +2940,7 @@ await Promise.resolve(); mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); result.should.have.property('getUser'); @@ -3074,8 +2968,7 @@ await Promise.resolve(); await waitForCondition(() => { return mParticle.Identity.getCurrentUser()?.getMPID() === 'MPID1'; - }) - await Promise.resolve(); + }); result.should.have.properties('body', 'httpCode', 'getUser'); result.httpCode.should.equal(200); @@ -3114,8 +3007,7 @@ await Promise.resolve(); await waitForCondition(() => { return mParticle.Identity.getCurrentUser()?.getMPID() === 'MPID1'; - }) - await Promise.resolve(); + }); const identityRequest = { userIdentities: { customerid: 'test123' } }; function loginCallback(result) { @@ -3124,8 +3016,7 @@ await Promise.resolve(); mParticle.Identity.login(identityRequest, loginCallback); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); loginResult .getUser() @@ -3161,8 +3052,7 @@ await Promise.resolve(); await waitForCondition(() => { return mParticle.Identity.getCurrentUser()?.getMPID() === 'MPID1'; - }) - await Promise.resolve(); + }); const identityRequest = { userIdentities: { customerid: 'test123' } }; function logoutCallback(result) { @@ -3171,8 +3061,7 @@ await Promise.resolve(); mParticle.Identity.logout(identityRequest, logoutCallback); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); logoutResult .getUser() @@ -3208,8 +3097,7 @@ await Promise.resolve(); await waitForCondition(() => { return mParticle.Identity.getCurrentUser()?.getMPID() === 'MPID1'; - }) - await Promise.resolve(); + }); const identityRequest = { userIdentities: { customerid: 'test123' } }; function modifyCallback(result) { @@ -3218,8 +3106,7 @@ await Promise.resolve(); mParticle.Identity.modify(identityRequest, modifyCallback); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); modifyResult .getUser() @@ -3238,8 +3125,7 @@ await Promise.resolve(); // client had no programmatic handling of a failed identify request mParticle._resetForTests(MPConfig); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); fetchMockSuccess(urls.identify, { mpid: 'MPID1', @@ -3256,8 +3142,7 @@ await Promise.resolve(); fetchMock.resetHistory(); mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); let cookies = mParticle.getInstance()._Persistence.getPersistence(); cookies.should.have.property('gs'); @@ -3273,8 +3158,7 @@ await Promise.resolve(); fetchMock.resetHistory(); mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(() => mParticle.Identity.getCurrentUser()?.getMPID() === 'MPID1') - await Promise.resolve(); + await waitForCondition(() => mParticle.Identity.getCurrentUser()?.getMPID() === 'MPID1'); cookies = mParticle.getInstance()._Persistence.getPersistence(); cookies.should.have.property('gs'); @@ -3292,8 +3176,7 @@ await Promise.resolve(); mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); // NOTE: Use sinon to "lock" in the current time for testing purposes const now = new Date(); @@ -3329,8 +3212,7 @@ await Promise.resolve(); mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); let currentUser = mParticle.Identity.getCurrentUser(); currentUser.should.not.equal(null); @@ -3353,8 +3235,7 @@ await Promise.resolve(); mParticle.Identity.login(userIdentities1); - await waitForCondition(() => mParticle.Identity.getCurrentUser().getMPID() === 'MPID1') - await Promise.resolve(); + await waitForCondition(() => mParticle.Identity.getCurrentUser().getMPID() === 'MPID1'); const nowAfterLogin = new Date(); @@ -3382,8 +3263,7 @@ await Promise.resolve(); mParticle.Identity.login(); - await waitForCondition(() => mParticle.Identity.getCurrentUser().getMPID() === testMPID) - await Promise.resolve(); + await waitForCondition(() => mParticle.Identity.getCurrentUser().getMPID() === testMPID); currentUser = mParticle.Identity.getCurrentUser(); expect(currentUser.getMPID()).to.equal(testMPID); @@ -3473,8 +3353,7 @@ await Promise.resolve(); mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); expect(identityResult.getUser().getMPID()).to.equal('testMPID'); expect(identityResult.getPreviousUser()).to.not.equal(null); @@ -3498,8 +3377,7 @@ await Promise.resolve(); mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentifyReturned) - await Promise.resolve(); + await waitForCondition(hasIdentifyReturned); fetchMockSuccess(urls.login, { mpid: testMPID, @@ -3524,8 +3402,7 @@ await Promise.resolve(); it('should return the correct user for Previous User', async () => { let callbackCalled = false; - await waitForCondition(hasBeforeEachCallbackReturned) - await Promise.resolve(); + await waitForCondition(hasBeforeEachCallbackReturned); const cookies = JSON.stringify({ gs: { @@ -3561,16 +3438,14 @@ await Promise.resolve(); let identityResult; - await waitForCondition(() => mParticle.Identity.getCurrentUser()?.getMPID() === '1') - await Promise.resolve(); + await waitForCondition(() => mParticle.Identity.getCurrentUser()?.getMPID() === '1'); mParticle.Identity.identify(EmptyUserIdentities, function(result) { identityResult = result; callbackCalled = true; }); - await waitForCondition(() => callbackCalled) - await Promise.resolve(); + await waitForCondition(() => callbackCalled); identityResult .getUser() .getMPID() @@ -3820,8 +3695,7 @@ await Promise.resolve(); mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); // Mock clock so we can use simple integers for time clock = sinon.useFakeTimers(); @@ -3858,8 +3732,7 @@ await Promise.resolve(); setCookie(workspaceCookieName, cookies); mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); // Mock clock so we can use simple integers for time clock = sinon.useFakeTimers(); @@ -3902,8 +3775,7 @@ await Promise.resolve(); mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); clock = sinon.useFakeTimers(); clock.tick(millisPerDay * 2); @@ -3957,8 +3829,7 @@ await Promise.resolve(); mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); // Mock clock so we can use simple integers for time clock = sinon.useFakeTimers(); @@ -4015,8 +3886,7 @@ await Promise.resolve(); it('should set isFirtRun to false after an app is initialized', async () => { mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); mParticle.getInstance()._Store.isFirstRun.should.equal(false); @@ -4027,8 +3897,7 @@ await Promise.resolve(); mParticle.Identity.login({ userIdentities: { customerid: 'abc' } }); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); const ls = mParticle.getInstance()._Persistence.getLocalStorage(); ls['testMPID'].lst.should.not.equal(null); @@ -4052,8 +3921,7 @@ await Promise.resolve(); mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); result.httpCode.should.equal(-1); @@ -4071,8 +3939,7 @@ await Promise.resolve(); mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); expect(fetchMock.calls().length).to.equal(1); const firstCall = fetchMock.calls()[0]; expect(firstCall[0].split('/')[4]).to.equal('identify'); @@ -4090,8 +3957,7 @@ await Promise.resolve(); mParticle.Identity.login({ userIdentities: { customerid: 'test' } }); - await waitForCondition(hasLoginReturned) - await Promise.resolve(); + await waitForCondition(hasLoginReturned); // Should include two more calls: Login and UIC expect(fetchMock.calls().length).to.equal(2); @@ -4134,8 +4000,7 @@ await Promise.resolve(); fetchMock.resetHistory(); - await waitForCondition(hasIdentifyReturned) - await Promise.resolve(); + await waitForCondition(hasIdentifyReturned); fetchMockSuccess( urls.identify, { @@ -4164,8 +4029,7 @@ await Promise.resolve(); mParticle.Identity.getCurrentUser()?.getUserIdentities() ?.userIdentities?.email === 'test@gmail.com' ); - }) - await Promise.resolve(); + }); const now = new Date(); const idCache: IdentityCache = JSON.parse( localStorage.getItem('mprtcl-v4_abcdef-id-cache') @@ -4218,8 +4082,7 @@ await Promise.resolve(); mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); // Just make sure calls were actually made expect(fetchMock.calls().length).to.greaterThanOrEqual(1); @@ -4231,8 +4094,7 @@ await Promise.resolve(); const callback = sinon.spy(); mParticle.Identity.identify(identities, callback); - await waitForCondition(hasIdentifyReturned) - await Promise.resolve(); + await waitForCondition(hasIdentifyReturned); expect(fetchMock.calls().length).to.equal(0); // callback still gets called even if the identity call is not made` @@ -4264,8 +4126,7 @@ await Promise.resolve(); mParticle.config.flags.cacheIdentity = 'True'; mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); const initialIdentityCall = fetchMock.calls()[0]; expect(initialIdentityCall[0].split('/')[4]).to.equal('identify'); @@ -4284,8 +4145,7 @@ await Promise.resolve(); clock.restore(); - await waitForCondition(() => callbackCalled) - await Promise.resolve(); + await waitForCondition(() => callbackCalled); expect(fetchMock.calls().length).to.equal(1); const duplicateIdentityCall = fetchMock.calls()[0]; @@ -4326,8 +4186,7 @@ await Promise.resolve(); mParticle.config.flags.cacheIdentity = 'True'; mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); fetchMock.resetHistory(); @@ -4337,8 +4196,7 @@ await Promise.resolve(); mParticle.Identity.login(identities, callback); - await waitForCondition(() => mParticle.Identity?.getCurrentUser()?.getMPID() === testMPID) - await Promise.resolve(); + await waitForCondition(() => mParticle.Identity?.getCurrentUser()?.getMPID() === testMPID); // Just make sure calls were actually made expect(fetchMock.calls().length).to.greaterThanOrEqual(1); @@ -4353,8 +4211,7 @@ await Promise.resolve(); await waitForCondition(() => { return callbackCalled; - }) - await Promise.resolve(); + }); expect(fetchMock.calls().length).to.equal(0); @@ -4395,8 +4252,7 @@ await Promise.resolve(); mParticle.config.flags.cacheIdentity = 'True'; mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); const initialIdentityCall = fetchMock.calls()[0]; expect(initialIdentityCall[0].split('/')[4]).to.equal('identify'); @@ -4409,8 +4265,7 @@ await Promise.resolve(); mParticle.Identity.login(identities, callback); - await waitForCondition(() => callbackCalled) - await Promise.resolve(); + await waitForCondition(() => callbackCalled); // Just make sure calls were actually made expect(fetchMock.calls().length).to.greaterThanOrEqual(1); @@ -4429,8 +4284,7 @@ await Promise.resolve(); clock.restore(); - await waitForCondition(() => callbackCalled) - await Promise.resolve(); + await waitForCondition(() => callbackCalled); expect(fetchMock.calls().length).to.equal(1); const secondLoginCall = fetchMock.calls()[0]; @@ -4474,8 +4328,7 @@ await Promise.resolve(); mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); const idCache = localStorage.getItem('mprtcl-v4_abcdef-id-cache'); expect(idCache).to.be.ok; @@ -4486,8 +4339,7 @@ await Promise.resolve(); }, }); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); const secondIdCache = localStorage.getItem( 'mprtcl-v4_abcdef-id-cache' ); @@ -4526,16 +4378,14 @@ await Promise.resolve(); mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); let idCache = localStorage.getItem('mprtcl-v4_abcdef-id-cache'); expect(idCache).to.be.ok; mParticle.Identity.logout(); - await waitForCondition(hasIdentityCallInflightReturned) - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); let secondIdCache = localStorage.getItem( 'mprtcl-v4_abcdef-id-cache' @@ -4580,7 +4430,6 @@ await Promise.resolve(); mParticle.init(apiKey, { ...window.mParticle.config, kitConfigs: [roktConfig] }); await waitForCondition(() => hasIdentifyReturned(testRoktMPID)); - await Promise.resolve(); const mpInstance = mParticle.getInstance(); @@ -4593,7 +4442,6 @@ await Promise.resolve(); }); await waitForCondition(() => hasIdentifyReturnedWithEmail(testRoktEmail)); - await Promise.resolve(); expect(mpInstance._RoktManager['currentUser']).to.not.be.null; expect(mpInstance._RoktManager['currentUser'].getUserIdentities().userIdentities.email).to.equal(testRoktEmail); @@ -4619,15 +4467,13 @@ await Promise.resolve(); mParticle.init(apiKey, { ...window.mParticle.config, kitConfigs: [roktConfig] }); - await waitForCondition(hasIdentityCallInflightReturned); - await Promise.resolve(); + await waitForCondition(hasIdentityCallInflightReturned); const mpInstance = mParticle.getInstance(); mpInstance._RoktManager.attachKit(roktKit); await waitForCondition(hasIdentityCallInflightReturned); - await Promise.resolve(); expect(mpInstance._RoktManager['currentUser']).be.null; }) @@ -4646,7 +4492,6 @@ await Promise.resolve(); mParticle.init(apiKey, { ...window.mParticle.config, kitConfigs: [roktConfig] }); await waitForCondition(() => hasIdentifyReturned('testMPID')); - await Promise.resolve(); fetchMock.post(urls.identify, { status: HTTP_BAD_REQUEST, @@ -4676,7 +4521,6 @@ await Promise.resolve(); }); await waitForCondition(hasIdentityCallInflightReturned); - await Promise.resolve(); // Current user will be the initial anonymous user from the initial identify call via mParticle.init // but should not have an email @@ -4693,8 +4537,7 @@ await Promise.resolve(); it("should deprecate the user's cart", async () => { mParticle.init(apiKey, window.mParticle.config); const bond = sinon.spy(mParticle.getInstance().Logger, 'warning'); - await waitForCondition(hasIdentifyReturned) - await Promise.resolve(); + await waitForCondition(hasIdentifyReturned); mParticle .getInstance() .Identity.getCurrentUser() @@ -4713,8 +4556,7 @@ await Promise.resolve(); mParticle.init(apiKey, window.mParticle.config); const bond = sinon.spy(mParticle.getInstance().Logger, 'warning'); - await waitForCondition(hasIdentifyReturned) - await Promise.resolve(); + await waitForCondition(hasIdentifyReturned); const product: SDKProduct = mParticle.eCommerce.createProduct( 'iPhone', @@ -4743,8 +4585,7 @@ await Promise.resolve(); mParticle.init(apiKey, window.mParticle.config); const bond = sinon.spy(mParticle.getInstance().Logger, 'warning'); - await waitForCondition(hasIdentifyReturned) - await Promise.resolve(); + await waitForCondition(hasIdentifyReturned); const product: SDKProduct = mParticle.eCommerce.createProduct( 'iPhone', @@ -4772,8 +4613,7 @@ await Promise.resolve(); it('should deprecate clear', async () => { mParticle.init(apiKey, window.mParticle.config); const bond = sinon.spy(mParticle.getInstance().Logger, 'warning'); - await waitForCondition(hasIdentifyReturned) - await Promise.resolve(); + await waitForCondition(hasIdentifyReturned); mParticle .getInstance() .Identity.getCurrentUser() @@ -4796,8 +4636,7 @@ await Promise.resolve(); mParticle.init(apiKey, window.mParticle.config); const bond = sinon.spy(mParticle.getInstance().Logger, 'warning'); - await waitForCondition(hasIdentifyReturned) - await Promise.resolve(); + await waitForCondition(hasIdentifyReturned); mParticle .getInstance() diff --git a/test/src/tests-identityApiClient.ts b/test/src/tests-identityApiClient.ts index 64e4e886c..4dc5f2550 100644 --- a/test/src/tests-identityApiClient.ts +++ b/test/src/tests-identityApiClient.ts @@ -32,7 +32,7 @@ declare global { const mParticle = window.mParticle; -describe('Identity Api Client', () => { +describe.only('Identity Api Client', () => { describe('#sendIdentityRequest', () => { const identityRequest: IIdentityAPIRequestData = { client_sdk: { From 46d2c3b4d1168c3d4c9b0cfae509650fa4c99efa Mon Sep 17 00:00:00 2001 From: Jaissica Date: Wed, 22 Oct 2025 20:26:58 -0400 Subject: [PATCH 03/40] test: updated identity test for failing test --- test/src/tests-identity.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/test/src/tests-identity.ts b/test/src/tests-identity.ts index b68770328..1dbb45c48 100644 --- a/test/src/tests-identity.ts +++ b/test/src/tests-identity.ts @@ -3159,6 +3159,7 @@ describe.only('identity', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(() => mParticle.Identity.getCurrentUser()?.getMPID() === 'MPID1'); + await Promise.resolve(); cookies = mParticle.getInstance()._Persistence.getPersistence(); cookies.should.have.property('gs'); From c0fb30e6719ccb0170a85e090edf278ea2cfbca1 Mon Sep 17 00:00:00 2001 From: Jaissica Date: Wed, 22 Oct 2025 20:39:44 -0400 Subject: [PATCH 04/40] test: updated identity test to handle identity calls --- test/src/tests-identity.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/src/tests-identity.ts b/test/src/tests-identity.ts index 1dbb45c48..eedddbd47 100644 --- a/test/src/tests-identity.ts +++ b/test/src/tests-identity.ts @@ -2083,6 +2083,7 @@ describe.only('identity', function() { // 1 for the modify // 1 for the UIC event await waitForCondition(hasIdentityCallInflightReturned); + await Promise.resolve(); expect(fetchMock.calls().length).to.equal(6); // This will add a new UAC Event to the call @@ -2115,6 +2116,7 @@ describe.only('identity', function() { mParticle.Identity.logout(user2); await waitForCondition(hasLogOutReturned); + await Promise.resolve(); // This will add the following new calls: // 1 for the logout @@ -2141,6 +2143,7 @@ describe.only('identity', function() { await waitForCondition(() => { return mParticle.Identity.getCurrentUser().getMPID() === 'testMPID'; }); + await Promise.resolve(); // This will add the following new calls: // 1 for the login From 6e80ee610b847d3ae3fd7c4b0ad3ae010bd4b2ce Mon Sep 17 00:00:00 2001 From: Jaissica Date: Thu, 23 Oct 2025 09:42:44 -0400 Subject: [PATCH 05/40] test: document Firefox timing issues in identity tests --- test/src/tests-identities-attributes.ts | 1 + test/src/tests-identity.ts | 15 +++++++++------ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/test/src/tests-identities-attributes.ts b/test/src/tests-identities-attributes.ts index fd181c0bd..a0106a695 100644 --- a/test/src/tests-identities-attributes.ts +++ b/test/src/tests-identities-attributes.ts @@ -897,6 +897,7 @@ describe.only('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 () => { fetchMock.resetHistory(); diff --git a/test/src/tests-identity.ts b/test/src/tests-identity.ts index eedddbd47..1e4b881c9 100644 --- a/test/src/tests-identity.ts +++ b/test/src/tests-identity.ts @@ -672,6 +672,7 @@ describe.only('identity', function() { // https://go.mparticle.com/work/SQDSDKS-6849 // This test passes with no issue when it is run on its own, but fails when tests-forwarders.js are also ran. + // https://go/j-SDKE-420 it('should respect consent rules on consent-change', async () => { mParticle.config.isDevelopmentMode = false; const mockForwarder = new MockForwarder('MockForwarder1'); @@ -858,6 +859,7 @@ describe.only('identity', function() { }); }); + // https://go/j-SDKE-420 it('cookies - should switch user cookies to new mpid details from cookies when a new mpid is provided', async () => { mParticle.config.useCookieStorage = true; @@ -900,7 +902,7 @@ describe.only('identity', function() { mParticle.Identity.login(userIdentities1); - await waitForCondition(hasLoginReturned); + await waitForCondition(hasLoginReturned); const cookiesAfterMPIDChange = findCookie(); cookiesAfterMPIDChange.should.have.properties([ @@ -2083,7 +2085,6 @@ describe.only('identity', function() { // 1 for the modify // 1 for the UIC event await waitForCondition(hasIdentityCallInflightReturned); - await Promise.resolve(); expect(fetchMock.calls().length).to.equal(6); // This will add a new UAC Event to the call @@ -2116,7 +2117,6 @@ describe.only('identity', function() { mParticle.Identity.logout(user2); await waitForCondition(hasLogOutReturned); - await Promise.resolve(); // This will add the following new calls: // 1 for the logout @@ -2143,7 +2143,6 @@ describe.only('identity', function() { await waitForCondition(() => { return mParticle.Identity.getCurrentUser().getMPID() === 'testMPID'; }); - await Promise.resolve(); // This will add the following new calls: // 1 for the login @@ -2160,6 +2159,7 @@ describe.only('identity', function() { }); }); + // https://go/j-SDKE-420 it('should add new MPIDs to cookie structure when initializing new identity requests, returning an existing mpid when reinitializing with a previous identity', async () => { const user1 = { userIdentities: { @@ -2239,7 +2239,6 @@ describe.only('identity', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentityCallInflightReturned); - const user5 = mParticle.Identity.getCurrentUser(); user5.getUserIdentities().userIdentities.customerid.should.equal('1'); user5.getMPID().should.equal('testMPID'); @@ -2952,6 +2951,7 @@ describe.only('identity', function() { .should.have.property('test', 'value'); }); + // https://go/j-SDKE-420 describe('identityCallback responses', function () { it('should have a getUser function on identify result object', async () => { let result; @@ -2987,6 +2987,7 @@ describe.only('identity', function() { .should.have.property('attr', 'value'); }); + // https://go/j-SDKE-420 it('should have a getUser function on login result object', async () => { let result let loginResult; @@ -3032,6 +3033,7 @@ describe.only('identity', function() { .should.have.property('attr', 'value'); }); + // https://go/j-SDKE-420 it('should have a getUser function on logout result object', async () => { let result; let logoutResult; @@ -3077,6 +3079,7 @@ describe.only('identity', function() { .should.have.property('attr', 'value'); }); + // https://go/j-SDKE-420 it('should have a getUser function on modify result object', async () => { let result let modifyResult; @@ -3162,7 +3165,6 @@ describe.only('identity', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(() => mParticle.Identity.getCurrentUser()?.getMPID() === 'MPID1'); - await Promise.resolve(); cookies = mParticle.getInstance()._Persistence.getPersistence(); cookies.should.have.property('gs'); @@ -4422,6 +4424,7 @@ describe.only('identity', function() { } as unknown as IRoktKit; }); + // https://go/j-SDKE-420 it('should set currentUser once the email is positively identified', async () => { fetchMockSuccess(urls.identify, { mpid: testRoktMPID, From a4c5c44fd52d560def2dff01b83a3852521347dc Mon Sep 17 00:00:00 2001 From: Jaissica Date: Thu, 23 Oct 2025 13:57:17 -0400 Subject: [PATCH 06/40] test: updated karma timeout config --- test/karma.config.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/test/karma.config.js b/test/karma.config.js index 25347ef04..02a6958e5 100644 --- a/test/karma.config.js +++ b/test/karma.config.js @@ -42,10 +42,14 @@ module.exports = function(config) { debug: true, logLevel: config.LOG_INFO, browserConsoleLogOptions, + browserDisconnectTimeout: 10000, + browserDisconnectTolerance: 1, + captureTimeout: 120000, + processKillTimeout: 100000, client: { captureConsole, mocha: { - timeout: 5000 // 5 seconds. Increase from default 2 seconds. + timeout: 10000 } }, customLaunchers: { From f69153984e2dd87c4c54b348c6ae0b1ff9ae63da Mon Sep 17 00:00:00 2001 From: Jaissica Date: Fri, 24 Oct 2025 11:26:53 -0400 Subject: [PATCH 07/40] test: updated identity tests to resolve flaky tests --- test/src/tests-identities-attributes.ts | 9 ++++ test/src/tests-identity.ts | 71 ++++++++++++++++++++++--- 2 files changed, 73 insertions(+), 7 deletions(-) diff --git a/test/src/tests-identities-attributes.ts b/test/src/tests-identities-attributes.ts index a0106a695..ce93129df 100644 --- a/test/src/tests-identities-attributes.ts +++ b/test/src/tests-identities-attributes.ts @@ -1244,6 +1244,15 @@ describe.only('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( diff --git a/test/src/tests-identity.ts b/test/src/tests-identity.ts index 1e4b881c9..e91efa116 100644 --- a/test/src/tests-identity.ts +++ b/test/src/tests-identity.ts @@ -1762,17 +1762,32 @@ describe.only('identity', function() { it('queue events when MPID is 0, and then flush events once MPID changes', async () => { fetchMock.resetHistory(); - fetchMockSuccess( - urls.identify, - { - status: 400, - body: JSON.stringify({}), - } - ); + fetchMock.post(urls.identify, { + status: HTTP_BAD_REQUEST, + body: { + Errors: [ + { + message: 'Bad Request', + code: 'BAD_REQUEST' + }, + ], + ErrorCode: 'BAD_REQUEST', + StatusCode: HTTP_BAD_REQUEST, + RequestId: '123', + }, + }, { + overwriteRoutes: true, + }); mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentityCallInflightReturned); + + await waitForCondition(() => { + const currentUser = mParticle.Identity.getCurrentUser(); + return currentUser && currentUser.getMPID() === '0'; + }); + mParticle.logEvent('Test Event 1'); // There should be 3 calls here: @@ -1834,6 +1849,7 @@ describe.only('identity', function() { expect(testEvent2).to.be.ok; expect(ASTEvent).to.be.ok; expect(sessionStartEvent).to.be.ok; + expect(loginCall).to.be.ok; expect(loginCall[0].split('/')[4]).to.equal('login'); }); @@ -2085,6 +2101,15 @@ describe.only('identity', function() { // 1 for the modify // 1 for the UIC event await waitForCondition(hasIdentityCallInflightReturned); + + await waitForCondition(() => { + const currentUser = mParticle.Identity.getCurrentUser(); + const userIdentities = currentUser?.getUserIdentities()?.userIdentities; + return userIdentities && + userIdentities.customerid === 'customerid1' && + userIdentities.email === 'email2@test.com'; + }); + expect(fetchMock.calls().length).to.equal(6); // This will add a new UAC Event to the call @@ -2191,6 +2216,12 @@ describe.only('identity', function() { await waitForCondition(hasIdentityCallInflightReturned); + await waitForCondition(() => { + const currentUser = mParticle.Identity.getCurrentUser(); + const userIdentities = currentUser?.getUserIdentities()?.userIdentities; + return userIdentities && userIdentities.customerid === '1'; + }); + const user1UIs = mParticle.Identity.getCurrentUser().getUserIdentities(); user1UIs.userIdentities.customerid.should.equal('1'); @@ -2204,6 +2235,12 @@ describe.only('identity', function() { await waitForCondition(hasIdentityCallInflightReturned); + await waitForCondition(() => { + const currentUser = mParticle.Identity.getCurrentUser(); + const userIdentities = currentUser?.getUserIdentities()?.userIdentities; + return userIdentities && userIdentities.customerid === '2'; + }); + const user2UIs = mParticle.Identity.getCurrentUser().getUserIdentities(); user2UIs.userIdentities.customerid.should.equal('2'); @@ -2216,6 +2253,12 @@ describe.only('identity', function() { await waitForCondition(hasIdentityCallInflightReturned); + await waitForCondition(() => { + const currentUser = mParticle.Identity.getCurrentUser(); + const userIdentities = currentUser?.getUserIdentities()?.userIdentities; + return userIdentities && userIdentities.customerid === '3'; + }); + const user3UIs = mParticle.Identity.getCurrentUser().getUserIdentities(); user3UIs.userIdentities.customerid.should.equal('3'); @@ -2228,6 +2271,12 @@ describe.only('identity', function() { await waitForCondition(hasIdentityCallInflightReturned); + await waitForCondition(() => { + const currentUser = mParticle.Identity.getCurrentUser(); + const userIdentities = currentUser?.getUserIdentities()?.userIdentities; + return userIdentities && userIdentities.customerid === '4'; + }); + const user4UIs = mParticle.Identity.getCurrentUser().getUserIdentities(); user4UIs.userIdentities.customerid.should.equal('4'); @@ -2239,6 +2288,14 @@ describe.only('identity', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentityCallInflightReturned); + + await waitForCondition(() => { + const currentUser = mParticle.Identity.getCurrentUser(); + const userIdentities = currentUser?.getUserIdentities()?.userIdentities; + const mpid = currentUser?.getMPID(); + return userIdentities && userIdentities.customerid === '1' && mpid === 'testMPID'; + }); + const user5 = mParticle.Identity.getCurrentUser(); user5.getUserIdentities().userIdentities.customerid.should.equal('1'); user5.getMPID().should.equal('testMPID'); From b245b05d32841b3177a95ba03e384094dfbbdf8e Mon Sep 17 00:00:00 2001 From: Jaissica Date: Fri, 24 Oct 2025 11:38:05 -0400 Subject: [PATCH 08/40] test: updated identity test when mpid is zero --- test/src/tests-identity.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/src/tests-identity.ts b/test/src/tests-identity.ts index e91efa116..629fc2b79 100644 --- a/test/src/tests-identity.ts +++ b/test/src/tests-identity.ts @@ -1785,8 +1785,9 @@ describe.only('identity', function() { await waitForCondition(() => { const currentUser = mParticle.Identity.getCurrentUser(); - return currentUser && currentUser.getMPID() === '0'; - }); + const mpid = currentUser?.getMPID(); + return currentUser && (mpid === '0' || mpid === String(0)); + }, 1000); mParticle.logEvent('Test Event 1'); From 1eb173bc3cfd9ad5fea6671ad0ad2ff26e11e909 Mon Sep 17 00:00:00 2001 From: Jaissica Date: Fri, 24 Oct 2025 12:29:18 -0400 Subject: [PATCH 09/40] test: updated identity tests when mpid is invalid --- test/src/tests-identity.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/test/src/tests-identity.ts b/test/src/tests-identity.ts index 629fc2b79..d1cd691e1 100644 --- a/test/src/tests-identity.ts +++ b/test/src/tests-identity.ts @@ -1781,13 +1781,12 @@ describe.only('identity', function() { mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentityCallInflightReturned); + await waitForCondition(hasIdentityCallInflightReturned, 2000); - await waitForCondition(() => { - const currentUser = mParticle.Identity.getCurrentUser(); - const mpid = currentUser?.getMPID(); - return currentUser && (mpid === '0' || mpid === String(0)); - }, 1000); + expect(mParticle.Identity.getCurrentUser()).to.be.null; + + const identifyCall = fetchMock.calls().find(call => call[0].includes('/identify')); + expect(identifyCall).to.be.ok; mParticle.logEvent('Test Event 1'); @@ -1813,6 +1812,7 @@ describe.only('identity', function() { mParticle.logEvent('Test Event 2'); mParticle.Identity.login(); + await waitForCondition(hasIdentityCallInflightReturned); await waitForCondition(hasLoginReturned); // server requests will now have the following events: From 4e4de0bac07c987542423994f897d9c81a965409 Mon Sep 17 00:00:00 2001 From: Jaissica Date: Fri, 24 Oct 2025 12:50:59 -0400 Subject: [PATCH 10/40] test: updated karma config for timeout issues --- test/karma.config.js | 3 ++- test/src/tests-identity.ts | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/test/karma.config.js b/test/karma.config.js index 02a6958e5..89a1b8ddd 100644 --- a/test/karma.config.js +++ b/test/karma.config.js @@ -49,13 +49,14 @@ module.exports = function(config) { client: { captureConsole, mocha: { - timeout: 10000 + timeout: 20000 } }, customLaunchers: { FirefoxHeadless: { base: 'Firefox', flags: ['-headless'], + browserNoActivityTimeout: 60000, }, }, junitReporter: { diff --git a/test/src/tests-identity.ts b/test/src/tests-identity.ts index d1cd691e1..275ee930f 100644 --- a/test/src/tests-identity.ts +++ b/test/src/tests-identity.ts @@ -3222,7 +3222,7 @@ describe.only('identity', function() { fetchMock.resetHistory(); mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(() => mParticle.Identity.getCurrentUser()?.getMPID() === 'MPID1'); + await waitForCondition(() => mParticle.Identity.getCurrentUser()?.getMPID() === 'MPID1', 1000); cookies = mParticle.getInstance()._Persistence.getPersistence(); cookies.should.have.property('gs'); From b2ab3451311ad7a85832a288d8bd43e5caf32295 Mon Sep 17 00:00:00 2001 From: Jaissica Date: Fri, 24 Oct 2025 13:04:18 -0400 Subject: [PATCH 11/40] test: increase timeout for flaky identity tests for Firefox --- test/src/tests-identity.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/src/tests-identity.ts b/test/src/tests-identity.ts index 275ee930f..d4573ff89 100644 --- a/test/src/tests-identity.ts +++ b/test/src/tests-identity.ts @@ -3069,7 +3069,7 @@ describe.only('identity', function() { await waitForCondition(() => { return mParticle.Identity.getCurrentUser()?.getMPID() === 'MPID1'; - }); + }, 2000); const identityRequest = { userIdentities: { customerid: 'test123' } }; function loginCallback(result) { @@ -3078,7 +3078,7 @@ describe.only('identity', function() { mParticle.Identity.login(identityRequest, loginCallback); - await waitForCondition(hasIdentityCallInflightReturned); + await waitForCondition(hasIdentityCallInflightReturned, 2000); loginResult .getUser() @@ -3189,7 +3189,7 @@ describe.only('identity', function() { // client had no programmatic handling of a failed identify request mParticle._resetForTests(MPConfig); - await waitForCondition(hasIdentityCallInflightReturned); + await waitForCondition(hasIdentityCallInflightReturned, 2000); fetchMockSuccess(urls.identify, { mpid: 'MPID1', @@ -3206,7 +3206,7 @@ describe.only('identity', function() { fetchMock.resetHistory(); mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentityCallInflightReturned); + await waitForCondition(hasIdentityCallInflightReturned, 2000); let cookies = mParticle.getInstance()._Persistence.getPersistence(); cookies.should.have.property('gs'); @@ -3222,7 +3222,7 @@ describe.only('identity', function() { fetchMock.resetHistory(); mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(() => mParticle.Identity.getCurrentUser()?.getMPID() === 'MPID1', 1000); + await waitForCondition(() => mParticle.Identity.getCurrentUser()?.getMPID() === 'MPID1', 2000); cookies = mParticle.getInstance()._Persistence.getPersistence(); cookies.should.have.property('gs'); From 71302f98e2b1909315ec5483e20f3d8a4a5c3dce Mon Sep 17 00:00:00 2001 From: Jaissica Date: Fri, 24 Oct 2025 13:30:29 -0400 Subject: [PATCH 12/40] test: reduce browserNoActivityTimeout to 20000 for Firefox browser --- test/karma.config.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/karma.config.js b/test/karma.config.js index 89a1b8ddd..c278e6df6 100644 --- a/test/karma.config.js +++ b/test/karma.config.js @@ -49,14 +49,14 @@ module.exports = function(config) { client: { captureConsole, mocha: { - timeout: 20000 + timeout: 5000 // 5 seconds. Increase from default 2 seconds. } }, customLaunchers: { FirefoxHeadless: { base: 'Firefox', flags: ['-headless'], - browserNoActivityTimeout: 60000, + browserNoActivityTimeout: 20000, }, }, junitReporter: { From 301d5f9cf20e9df14ed499391d9d295b22cc6cd6 Mon Sep 17 00:00:00 2001 From: Jaissica Date: Fri, 24 Oct 2025 13:42:58 -0400 Subject: [PATCH 13/40] test: increase browserNoActivityTimeout to 60000 for Firefox browser --- test/karma.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/karma.config.js b/test/karma.config.js index c278e6df6..101e45407 100644 --- a/test/karma.config.js +++ b/test/karma.config.js @@ -56,7 +56,7 @@ module.exports = function(config) { FirefoxHeadless: { base: 'Firefox', flags: ['-headless'], - browserNoActivityTimeout: 20000, + browserNoActivityTimeout: 60000, }, }, junitReporter: { From f537ab71ca9034f688c92eedb63aa1794b362981 Mon Sep 17 00:00:00 2001 From: Jaissica Date: Fri, 24 Oct 2025 13:58:53 -0400 Subject: [PATCH 14/40] test: increase mocha timeout to 10 seconds --- test/karma.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/karma.config.js b/test/karma.config.js index 101e45407..d1a2b4fe7 100644 --- a/test/karma.config.js +++ b/test/karma.config.js @@ -49,7 +49,7 @@ module.exports = function(config) { client: { captureConsole, mocha: { - timeout: 5000 // 5 seconds. Increase from default 2 seconds. + timeout: 10000 // 10 seconds. Increase from default 2 seconds. } }, customLaunchers: { From 00fad324131db5d4990bd12de377c4d00bb9955f Mon Sep 17 00:00:00 2001 From: Jaissica Date: Fri, 24 Oct 2025 15:12:58 -0400 Subject: [PATCH 15/40] test: updated timeout for identity test --- test/src/tests-identity.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/src/tests-identity.ts b/test/src/tests-identity.ts index d4573ff89..37c972bfd 100644 --- a/test/src/tests-identity.ts +++ b/test/src/tests-identity.ts @@ -3000,7 +3000,7 @@ describe.only('identity', function() { mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentityCallInflightReturned); + await waitForCondition(hasIdentityCallInflightReturned, 2000); result.should.have.property('getUser'); @@ -3161,7 +3161,7 @@ describe.only('identity', function() { await waitForCondition(() => { return mParticle.Identity.getCurrentUser()?.getMPID() === 'MPID1'; - }); + }, 2000); const identityRequest = { userIdentities: { customerid: 'test123' } }; function modifyCallback(result) { @@ -3170,7 +3170,7 @@ describe.only('identity', function() { mParticle.Identity.modify(identityRequest, modifyCallback); - await waitForCondition(hasIdentityCallInflightReturned); + await waitForCondition(hasIdentityCallInflightReturned, 2000); modifyResult .getUser() From c738b43182657861c67f1a68ad7649125fe8c440 Mon Sep 17 00:00:00 2001 From: Jaissica Date: Fri, 24 Oct 2025 15:28:34 -0400 Subject: [PATCH 16/40] test: reverted timeout changes from individual tests --- test/src/config/utils.js | 2 +- test/src/tests-identity.ts | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/test/src/config/utils.js b/test/src/config/utils.js index 2580710ae..c897e2f83 100644 --- a/test/src/config/utils.js +++ b/test/src/config/utils.js @@ -593,7 +593,7 @@ var pluses = /\+/g, }, waitForCondition = function async( conditionFn, - timeout = 200, + timeout = 2000, interval = 10 ) { return new Promise((resolve, reject) => { diff --git a/test/src/tests-identity.ts b/test/src/tests-identity.ts index 37c972bfd..9a05d4e80 100644 --- a/test/src/tests-identity.ts +++ b/test/src/tests-identity.ts @@ -1781,7 +1781,7 @@ describe.only('identity', function() { mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentityCallInflightReturned, 2000); + await waitForCondition(hasIdentityCallInflightReturned); expect(mParticle.Identity.getCurrentUser()).to.be.null; @@ -3000,7 +3000,7 @@ describe.only('identity', function() { mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentityCallInflightReturned, 2000); + await waitForCondition(hasIdentityCallInflightReturned); result.should.have.property('getUser'); @@ -3078,7 +3078,7 @@ describe.only('identity', function() { mParticle.Identity.login(identityRequest, loginCallback); - await waitForCondition(hasIdentityCallInflightReturned, 2000); + await waitForCondition(hasIdentityCallInflightReturned); loginResult .getUser() @@ -3170,7 +3170,7 @@ describe.only('identity', function() { mParticle.Identity.modify(identityRequest, modifyCallback); - await waitForCondition(hasIdentityCallInflightReturned, 2000); + await waitForCondition(hasIdentityCallInflightReturned); modifyResult .getUser() @@ -3189,7 +3189,7 @@ describe.only('identity', function() { // client had no programmatic handling of a failed identify request mParticle._resetForTests(MPConfig); - await waitForCondition(hasIdentityCallInflightReturned, 2000); + await waitForCondition(hasIdentityCallInflightReturned); fetchMockSuccess(urls.identify, { mpid: 'MPID1', @@ -3206,7 +3206,7 @@ describe.only('identity', function() { fetchMock.resetHistory(); mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentityCallInflightReturned, 2000); + await waitForCondition(hasIdentityCallInflightReturned); let cookies = mParticle.getInstance()._Persistence.getPersistence(); cookies.should.have.property('gs'); From 01a78d8601c799ead701ac9a110d46d3a53ec0e8 Mon Sep 17 00:00:00 2001 From: Jaissica Date: Fri, 24 Oct 2025 15:56:28 -0400 Subject: [PATCH 17/40] test: updated waitForCondition for identity login --- test/src/tests-identities-attributes.ts | 2 ++ test/src/tests-identity.ts | 14 +++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/test/src/tests-identities-attributes.ts b/test/src/tests-identities-attributes.ts index ce93129df..cd01ee140 100644 --- a/test/src/tests-identities-attributes.ts +++ b/test/src/tests-identities-attributes.ts @@ -1053,6 +1053,7 @@ describe.only('identities and attributes', function() { }); mParticle.Identity.logout(logoutUser); + await waitForCondition(hasIdentityCallInflightReturned); await waitForCondition(() => { return ( mParticle.Identity.getCurrentUser()?.getMPID() === 'mpid2' @@ -1275,6 +1276,7 @@ describe.only('identities and attributes', function() { }); mParticle.Identity.logout(logoutUser); + await waitForCondition(hasIdentityCallInflightReturned); await waitForCondition(() => { return ( diff --git a/test/src/tests-identity.ts b/test/src/tests-identity.ts index 9a05d4e80..b5230cc48 100644 --- a/test/src/tests-identity.ts +++ b/test/src/tests-identity.ts @@ -773,6 +773,7 @@ describe.only('identity', function() { }; mParticle.Identity.login(userIdentities1); + await waitForCondition(hasIdentityCallInflightReturned); await waitForCondition(hasLoginReturned); const localStorageDataBeforeSessionEnd = mParticle @@ -902,6 +903,7 @@ describe.only('identity', function() { mParticle.Identity.login(userIdentities1); + await waitForCondition(hasIdentityCallInflightReturned); await waitForCondition(hasLoginReturned); const cookiesAfterMPIDChange = findCookie(); @@ -2166,6 +2168,7 @@ describe.only('identity', function() { }); mParticle.Identity.login(user1); + await waitForCondition(hasIdentityCallInflightReturned); await waitForCondition(() => { return mParticle.Identity.getCurrentUser().getMPID() === 'testMPID'; }); @@ -2691,6 +2694,7 @@ describe.only('identity', function() { }; mParticle.Identity.login(user2); + await waitForCondition(hasIdentityCallInflightReturned); await waitForCondition(() => mParticle.Identity.getCurrentUser().getMPID() === 'otherMPID'); @@ -2730,6 +2734,7 @@ describe.only('identity', function() { }; mParticle.Identity.login(user3); + await waitForCondition(hasIdentityCallInflightReturned); await waitForCondition(() => mParticle.Identity.getCurrentUser().getMPID() === 'otherMPID2'); @@ -3069,7 +3074,7 @@ describe.only('identity', function() { await waitForCondition(() => { return mParticle.Identity.getCurrentUser()?.getMPID() === 'MPID1'; - }, 2000); + }); const identityRequest = { userIdentities: { customerid: 'test123' } }; function loginCallback(result) { @@ -3161,7 +3166,7 @@ describe.only('identity', function() { await waitForCondition(() => { return mParticle.Identity.getCurrentUser()?.getMPID() === 'MPID1'; - }, 2000); + }); const identityRequest = { userIdentities: { customerid: 'test123' } }; function modifyCallback(result) { @@ -3222,7 +3227,7 @@ describe.only('identity', function() { fetchMock.resetHistory(); mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(() => mParticle.Identity.getCurrentUser()?.getMPID() === 'MPID1', 2000); + await waitForCondition(() => mParticle.Identity.getCurrentUser()?.getMPID() === 'MPID1'); cookies = mParticle.getInstance()._Persistence.getPersistence(); cookies.should.have.property('gs'); @@ -3298,6 +3303,7 @@ describe.only('identity', function() { fetchMock.resetHistory(); mParticle.Identity.login(userIdentities1); + await waitForCondition(hasIdentityCallInflightReturned); await waitForCondition(() => mParticle.Identity.getCurrentUser().getMPID() === 'MPID1'); @@ -3326,6 +3332,7 @@ describe.only('identity', function() { fetchMock.resetHistory(); mParticle.Identity.login(); + await waitForCondition(hasIdentityCallInflightReturned); await waitForCondition(() => mParticle.Identity.getCurrentUser().getMPID() === testMPID); @@ -4259,6 +4266,7 @@ describe.only('identity', function() { }; mParticle.Identity.login(identities, callback); + await waitForCondition(hasIdentityCallInflightReturned); await waitForCondition(() => mParticle.Identity?.getCurrentUser()?.getMPID() === testMPID); From 62aef2922c6255aef16749842c3a14c7da34d58c Mon Sep 17 00:00:00 2001 From: Jaissica Date: Mon, 27 Oct 2025 09:20:01 -0400 Subject: [PATCH 18/40] test: cleanup identity tests --- test/src/config/utils.js | 2 +- test/src/tests-identities-attributes.ts | 8 +------- test/src/tests-identity.ts | 2 +- 3 files changed, 3 insertions(+), 9 deletions(-) diff --git a/test/src/config/utils.js b/test/src/config/utils.js index c897e2f83..2580710ae 100644 --- a/test/src/config/utils.js +++ b/test/src/config/utils.js @@ -593,7 +593,7 @@ var pluses = /\+/g, }, waitForCondition = function async( conditionFn, - timeout = 2000, + timeout = 200, interval = 10 ) { return new Promise((resolve, reject) => { diff --git a/test/src/tests-identities-attributes.ts b/test/src/tests-identities-attributes.ts index cd01ee140..7b3169e58 100644 --- a/test/src/tests-identities-attributes.ts +++ b/test/src/tests-identities-attributes.ts @@ -1053,7 +1053,6 @@ describe.only('identities and attributes', function() { }); mParticle.Identity.logout(logoutUser); - await waitForCondition(hasIdentityCallInflightReturned); await waitForCondition(() => { return ( mParticle.Identity.getCurrentUser()?.getMPID() === 'mpid2' @@ -1240,12 +1239,6 @@ describe.only('identities and attributes', function() { mParticle.Identity.login(loginUser); - await waitForCondition(() => { - return ( - mParticle.getInstance()._Store.identityCallInFlight === false - ); - }); - await waitForCondition(() => { const currentUser = mParticle.Identity.getCurrentUser(); const userIdentities = currentUser?.getUserIdentities()?.userIdentities; @@ -1303,6 +1296,7 @@ describe.only('identities and attributes', function() { mParticle.getInstance()._Store.identityCallInFlight === false ); }); + // switching back to logged in user should not result in any UIC events expect(fetchMock.calls().length).to.equal(1); const data = getIdentityEvent(fetchMock.calls(), 'login'); diff --git a/test/src/tests-identity.ts b/test/src/tests-identity.ts index b5230cc48..8077dd2f8 100644 --- a/test/src/tests-identity.ts +++ b/test/src/tests-identity.ts @@ -4197,7 +4197,7 @@ describe.only('identity', function() { mParticle.config.flags.cacheIdentity = 'True'; mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentityCallInflightReturned); + await waitForCondition(hasIdentityCallInflightReturned); const initialIdentityCall = fetchMock.calls()[0]; expect(initialIdentityCall[0].split('/')[4]).to.equal('identify'); From 45b98922f6d5da67e1cd110f8605b5ef728113cb Mon Sep 17 00:00:00 2001 From: Jaissica Date: Mon, 27 Oct 2025 11:54:30 -0400 Subject: [PATCH 19/40] test: use logger spy for robust identity test SDKE-420 --- test/src/config/utils.js | 20 +++++++- test/src/tests-identity.ts | 96 +++++++++++++++----------------------- 2 files changed, 56 insertions(+), 60 deletions(-) diff --git a/test/src/config/utils.js b/test/src/config/utils.js index 2580710ae..0e00bfe3d 100644 --- a/test/src/config/utils.js +++ b/test/src/config/utils.js @@ -10,6 +10,7 @@ import { das, } from './constants'; import fetchMock from 'fetch-mock/esm/client'; +import sinon from 'sinon'; var pluses = /\+/g, decoded = function decoded(s) { @@ -624,7 +625,22 @@ var pluses = /\+/g, return window.mParticle.Identity.getCurrentUser()?.getMPID() === _mpid; }, hasIdentityCallInflightReturned = () => !mParticle.getInstance()?._Store?.identityCallInFlight, - hasConfigurationReturned = () => !!mParticle.getInstance()?._Store?.configurationLoaded; + hasConfigurationReturned = () => !!mParticle.getInstance()?._Store?.configurationLoaded, + setupLoggerSpy = () => { + const loggerSpy = { + verbose: sinon.spy(), + warning: sinon.spy(), + error: sinon.spy(), + }; + window.mParticle.config.logger = loggerSpy; + window.mParticle.config.logLevel = 'verbose'; + return loggerSpy; + }, + hasIdentityResponseParsed = (loggerSpy) => { + return loggerSpy?.verbose?.getCalls()?.some(call => + call.args[0] === 'Successfully parsed Identity Response' + ) || false; + }; var TestsCore = { findCookie: findCookie, @@ -653,6 +669,8 @@ var TestsCore = { hasIdentifyReturned: hasIdentifyReturned, hasIdentityCallInflightReturned, hasConfigurationReturned, + setupLoggerSpy, + hasIdentityResponseParsed, }; export default TestsCore; \ No newline at end of file diff --git a/test/src/tests-identity.ts b/test/src/tests-identity.ts index 8077dd2f8..d1318c82d 100644 --- a/test/src/tests-identity.ts +++ b/test/src/tests-identity.ts @@ -674,6 +674,7 @@ describe.only('identity', function() { // This test passes with no issue when it is run on its own, but fails when tests-forwarders.js are also ran. // https://go/j-SDKE-420 it('should respect consent rules on consent-change', async () => { + const loggerSpy = Utils.setupLoggerSpy(); mParticle.config.isDevelopmentMode = false; const mockForwarder = new MockForwarder('MockForwarder1'); mockForwarder.register(window.mParticle.config); @@ -717,7 +718,7 @@ describe.only('identity', function() { mParticle.init(apiKey, window.mParticle.config); - await waitForCondition( () => mParticle.Identity.getCurrentUser()?.getMPID() === 'MPID1'); + await waitForCondition(() => Utils.hasIdentityResponseParsed(loggerSpy)); let activeForwarders = mParticle.getInstance()._getActiveForwarders(); expect(activeForwarders.length).to.equal(0); @@ -738,9 +739,10 @@ describe.only('identity', function() { is_logged_in: false, }); + loggerSpy.verbose.resetHistory(); mParticle.Identity.login(); - await waitForCondition(hasIdentityCallInflightReturned); + await waitForCondition(() => Utils.hasIdentityResponseParsed(loggerSpy)); activeForwarders = mParticle.getInstance()._getActiveForwarders(); expect(activeForwarders.length).to.equal(0); @@ -862,13 +864,14 @@ describe.only('identity', function() { // https://go/j-SDKE-420 it('cookies - should switch user cookies to new mpid details from cookies when a new mpid is provided', async () => { + const loggerSpy = Utils.setupLoggerSpy(); mParticle.config.useCookieStorage = true; setLocalStorage(); mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentifyReturned); + await waitForCondition(() => Utils.hasIdentityResponseParsed(loggerSpy)); const cookiesAfterInit = findCookie(); cookiesAfterInit.should.have.properties('gs', 'cu', testMPID); @@ -901,10 +904,10 @@ describe.only('identity', function() { }, }; + loggerSpy.verbose.resetHistory(); mParticle.Identity.login(userIdentities1); - await waitForCondition(hasIdentityCallInflightReturned); - await waitForCondition(hasLoginReturned); + await waitForCondition(() => Utils.hasIdentityResponseParsed(loggerSpy)); const cookiesAfterMPIDChange = findCookie(); cookiesAfterMPIDChange.should.have.properties([ @@ -2190,6 +2193,7 @@ describe.only('identity', function() { // https://go/j-SDKE-420 it('should add new MPIDs to cookie structure when initializing new identity requests, returning an existing mpid when reinitializing with a previous identity', async () => { + const loggerSpy = Utils.setupLoggerSpy(); const user1 = { userIdentities: { customerid: '1', @@ -2218,13 +2222,7 @@ describe.only('identity', function() { mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentityCallInflightReturned); - - await waitForCondition(() => { - const currentUser = mParticle.Identity.getCurrentUser(); - const userIdentities = currentUser?.getUserIdentities()?.userIdentities; - return userIdentities && userIdentities.customerid === '1'; - }); + await waitForCondition(() => Utils.hasIdentityResponseParsed(loggerSpy)); const user1UIs = mParticle.Identity.getCurrentUser().getUserIdentities(); @@ -2235,15 +2233,10 @@ describe.only('identity', function() { is_logged_in: true, }); + loggerSpy.verbose.resetHistory(); mParticle.Identity.login(user2); - await waitForCondition(hasIdentityCallInflightReturned); - - await waitForCondition(() => { - const currentUser = mParticle.Identity.getCurrentUser(); - const userIdentities = currentUser?.getUserIdentities()?.userIdentities; - return userIdentities && userIdentities.customerid === '2'; - }); + await waitForCondition(() => Utils.hasIdentityResponseParsed(loggerSpy)); const user2UIs = mParticle.Identity.getCurrentUser().getUserIdentities(); user2UIs.userIdentities.customerid.should.equal('2'); @@ -2253,15 +2246,10 @@ describe.only('identity', function() { is_logged_in: true, }); + loggerSpy.verbose.resetHistory(); mParticle.Identity.login(user3); - await waitForCondition(hasIdentityCallInflightReturned); - - await waitForCondition(() => { - const currentUser = mParticle.Identity.getCurrentUser(); - const userIdentities = currentUser?.getUserIdentities()?.userIdentities; - return userIdentities && userIdentities.customerid === '3'; - }); + await waitForCondition(() => Utils.hasIdentityResponseParsed(loggerSpy)); const user3UIs = mParticle.Identity.getCurrentUser().getUserIdentities(); user3UIs.userIdentities.customerid.should.equal('3'); @@ -2271,15 +2259,10 @@ describe.only('identity', function() { is_logged_in: true, }); + loggerSpy.verbose.resetHistory(); mParticle.Identity.login(user4); - await waitForCondition(hasIdentityCallInflightReturned); - - await waitForCondition(() => { - const currentUser = mParticle.Identity.getCurrentUser(); - const userIdentities = currentUser?.getUserIdentities()?.userIdentities; - return userIdentities && userIdentities.customerid === '4'; - }); + await waitForCondition(() => Utils.hasIdentityResponseParsed(loggerSpy)); const user4UIs = mParticle.Identity.getCurrentUser().getUserIdentities(); user4UIs.userIdentities.customerid.should.equal('4'); @@ -2289,16 +2272,10 @@ describe.only('identity', function() { is_logged_in: true, }); + loggerSpy.verbose.resetHistory(); mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentityCallInflightReturned); - - await waitForCondition(() => { - const currentUser = mParticle.Identity.getCurrentUser(); - const userIdentities = currentUser?.getUserIdentities()?.userIdentities; - const mpid = currentUser?.getMPID(); - return userIdentities && userIdentities.customerid === '1' && mpid === 'testMPID'; - }); + await waitForCondition(() => Utils.hasIdentityResponseParsed(loggerSpy)); const user5 = mParticle.Identity.getCurrentUser(); user5.getUserIdentities().userIdentities.customerid.should.equal('1'); @@ -3017,6 +2994,7 @@ describe.only('identity', function() { // https://go/j-SDKE-420 describe('identityCallback responses', function () { it('should have a getUser function on identify result object', async () => { + const loggerSpy = Utils.setupLoggerSpy(); let result; mParticle.config.identityCallback = function(resp) { @@ -3032,9 +3010,7 @@ describe.only('identity', function() { // Init fires an identify call mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(() => { - return mParticle.Identity.getCurrentUser()?.getMPID() === 'MPID1'; - }); + await waitForCondition(() => Utils.hasIdentityResponseParsed(loggerSpy)); result.should.have.properties('body', 'httpCode', 'getUser'); result.httpCode.should.equal(200); @@ -3052,6 +3028,7 @@ describe.only('identity', function() { // https://go/j-SDKE-420 it('should have a getUser function on login result object', async () => { + const loggerSpy = Utils.setupLoggerSpy(); let result let loginResult; @@ -3072,18 +3049,17 @@ describe.only('identity', function() { mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(() => { - return mParticle.Identity.getCurrentUser()?.getMPID() === 'MPID1'; - }); + await waitForCondition(() => Utils.hasIdentityResponseParsed(loggerSpy)); const identityRequest = { userIdentities: { customerid: 'test123' } }; function loginCallback(result) { loginResult = result; } + loggerSpy.verbose.resetHistory(); mParticle.Identity.login(identityRequest, loginCallback); - await waitForCondition(hasIdentityCallInflightReturned); + await waitForCondition(() => Utils.hasIdentityResponseParsed(loggerSpy)); loginResult .getUser() @@ -3098,6 +3074,7 @@ describe.only('identity', function() { // https://go/j-SDKE-420 it('should have a getUser function on logout result object', async () => { + const loggerSpy = Utils.setupLoggerSpy(); let result; let logoutResult; @@ -3118,18 +3095,17 @@ describe.only('identity', function() { mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(() => { - return mParticle.Identity.getCurrentUser()?.getMPID() === 'MPID1'; - }); + await waitForCondition(() => Utils.hasIdentityResponseParsed(loggerSpy)); const identityRequest = { userIdentities: { customerid: 'test123' } }; function logoutCallback(result) { logoutResult = result; } + loggerSpy.verbose.resetHistory(); mParticle.Identity.logout(identityRequest, logoutCallback); - await waitForCondition(hasIdentityCallInflightReturned); + await waitForCondition(() => Utils.hasIdentityResponseParsed(loggerSpy)); logoutResult .getUser() @@ -3144,6 +3120,7 @@ describe.only('identity', function() { // https://go/j-SDKE-420 it('should have a getUser function on modify result object', async () => { + const loggerSpy = Utils.setupLoggerSpy(); let result let modifyResult; @@ -3157,25 +3134,24 @@ describe.only('identity', function() { is_logged_in: false, }); - fetchMockSuccess(urls.modify, { + fetchMockSuccess('https://identity.mparticle.com/v1/MPID1/modify', { mpid: 'MPID1', is_logged_in: false, }); mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(() => { - return mParticle.Identity.getCurrentUser()?.getMPID() === 'MPID1'; - }); + await waitForCondition(() => Utils.hasIdentityResponseParsed(loggerSpy)); const identityRequest = { userIdentities: { customerid: 'test123' } }; function modifyCallback(result) { modifyResult = result; } + loggerSpy.verbose.resetHistory(); mParticle.Identity.modify(identityRequest, modifyCallback); - await waitForCondition(hasIdentityCallInflightReturned); + await waitForCondition(() => Utils.hasIdentityResponseParsed(loggerSpy)); modifyResult .getUser() @@ -4492,6 +4468,7 @@ describe.only('identity', function() { // https://go/j-SDKE-420 it('should set currentUser once the email is positively identified', async () => { + const loggerSpy = Utils.setupLoggerSpy(); fetchMockSuccess(urls.identify, { mpid: testRoktMPID, is_logged_in: false, @@ -4502,19 +4479,20 @@ describe.only('identity', function() { mParticle.init(apiKey, { ...window.mParticle.config, kitConfigs: [roktConfig] }); - await waitForCondition(() => hasIdentifyReturned(testRoktMPID)); + await waitForCondition(() => Utils.hasIdentityResponseParsed(loggerSpy)); const mpInstance = mParticle.getInstance(); mpInstance._RoktManager.attachKit(roktKit); + loggerSpy.verbose.resetHistory(); mParticle.Identity.identify({ userIdentities: { email: testRoktEmail, }, }); - await waitForCondition(() => hasIdentifyReturnedWithEmail(testRoktEmail)); + await waitForCondition(() => Utils.hasIdentityResponseParsed(loggerSpy)); expect(mpInstance._RoktManager['currentUser']).to.not.be.null; expect(mpInstance._RoktManager['currentUser'].getUserIdentities().userIdentities.email).to.equal(testRoktEmail); From cf6392095d43c146611d1c537d3877b576993d7f Mon Sep 17 00:00:00 2001 From: Jaissica Date: Mon, 27 Oct 2025 13:01:35 -0400 Subject: [PATCH 20/40] test: updated failing identities attributes test --- test/src/tests-identities-attributes.ts | 39 +++++++++---------------- 1 file changed, 14 insertions(+), 25 deletions(-) diff --git a/test/src/tests-identities-attributes.ts b/test/src/tests-identities-attributes.ts index 7b3169e58..de0300225 100644 --- a/test/src/tests-identities-attributes.ts +++ b/test/src/tests-identities-attributes.ts @@ -897,8 +897,9 @@ describe.only('identities and attributes', function() { delete window.mParticle.config.flags; }); - // https://go/j-SDKE-420 - Intermittently fails in Firefox due to timing + // https://go/j-SDKE-420 it('should send user identity change requests when setting new identities on new users', async () => { + const loggerSpy = Utils.setupLoggerSpy(); fetchMock.resetHistory(); window.mParticle.config.identifyRequest = { @@ -908,7 +909,7 @@ describe.only('identities and attributes', function() { }; mParticle.config.flags.eventBatchingIntervalMillis = 5000 mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentifyReturned); + await waitForCondition(() => Utils.hasIdentityResponseParsed(loggerSpy)); mParticle.upload(); expect( JSON.parse(`${fetchMock.lastOptions().body}`).user_identities @@ -933,12 +934,9 @@ describe.only('identities and attributes', function() { customerid: 'customerid1', }, }; + loggerSpy.verbose.resetHistory(); mParticle.Identity.login(loginUser); - await waitForCondition(() => { - return ( - mParticle.Identity.getCurrentUser()?.getMPID() === 'anotherMPID' - ); - }); + await waitForCondition(() => Utils.hasIdentityResponseParsed(loggerSpy)); let body = JSON.parse(`${fetchMock.lastOptions().body}`); // should be the new MPID @@ -978,16 +976,13 @@ describe.only('identities and attributes', function() { }, }; - fetchMockSuccess('https://identity.mparticle.com/v1/anotherMPID/modify', { - mpid: 'anotherMPID', is_logged_in: true - }); + fetchMockSuccess('https://identity.mparticle.com/v1/anotherMPID/modify', { + mpid: 'anotherMPID', is_logged_in: true + }); + loggerSpy.verbose.resetHistory(); mParticle.Identity.modify(modifyUser); - await waitForCondition(() => { - return ( - mParticle.getInstance()._Store.identityCallInFlight === false - ); - }); + await waitForCondition(() => Utils.hasIdentityResponseParsed(loggerSpy)); const body2 = JSON.parse(`${fetchMock.lastOptions().body}`); expect(body2.mpid).to.equal('anotherMPID'); expect(body2.user_identities).to.have.property( @@ -1018,12 +1013,9 @@ describe.only('identities and attributes', function() { fetchMock.resetHistory(); + loggerSpy.verbose.resetHistory(); mParticle.Identity.modify(modifyUser2); - await waitForCondition(() => { - return ( - mParticle.getInstance()._Store.identityCallInFlight === false - ); - }); + await waitForCondition(() => Utils.hasIdentityResponseParsed(loggerSpy)); const body3 = JSON.parse(`${fetchMock.lastOptions().body}`); expect(body3.mpid).to.equal('anotherMPID'); @@ -1052,12 +1044,9 @@ describe.only('identities and attributes', function() { mpid: 'mpid2', is_logged_in: false }); + loggerSpy.verbose.resetHistory(); mParticle.Identity.logout(logoutUser); - await waitForCondition(() => { - return ( - mParticle.Identity.getCurrentUser()?.getMPID() === 'mpid2' - ); - }); + await waitForCondition(() => Utils.hasIdentityResponseParsed(loggerSpy)); // Calls are for logout and UIC expect(fetchMock.calls().length).to.equal(2); const body4 = JSON.parse(`${fetchMock.lastOptions().body}`); From ea9563684769b1b6a2449725ae3182c6c3e88e94 Mon Sep 17 00:00:00 2001 From: Jaissica Date: Mon, 27 Oct 2025 13:57:59 -0400 Subject: [PATCH 21/40] test: use logger spy for identity response in identity attributes tests --- test/src/config/utils.js | 2 +- test/src/tests-identities-attributes.ts | 51 +++++++++---------------- 2 files changed, 20 insertions(+), 33 deletions(-) diff --git a/test/src/config/utils.js b/test/src/config/utils.js index 7d239aaa3..24a254f33 100644 --- a/test/src/config/utils.js +++ b/test/src/config/utils.js @@ -638,7 +638,7 @@ var pluses = /\+/g, return loggerSpy; }, hasIdentityResponseParsed = (loggerSpy) => { - return loggerSpy?.verbose?.getCalls()?.some(call => + return () => loggerSpy?.verbose?.getCalls()?.some(call => call.args[0] === 'Successfully parsed Identity Response' ) || false; }, diff --git a/test/src/tests-identities-attributes.ts b/test/src/tests-identities-attributes.ts index de0300225..5302d50da 100644 --- a/test/src/tests-identities-attributes.ts +++ b/test/src/tests-identities-attributes.ts @@ -10,12 +10,12 @@ import Utils from './config/utils'; import { AllUserAttributes, UserAttributesValue } from '@mparticle/web-sdk'; import { UserAttributes } from '../../src/identity-user-interfaces'; import { Batch, CustomEvent, UserAttributeChangeEvent } from '@mparticle/event-models'; -import { IMParticleInstanceManager, SDKProduct } from '../../src/sdkRuntimeModels'; +import { IMParticleInstanceManager } from '../../src/sdkRuntimeModels'; const { waitForCondition, fetchMockSuccess, - hasIdentifyReturned, - hasIdentityCallInflightReturned, + hasIdentifyReturned, + hasIdentityResponseParsed, findEventFromRequest, findBatch, getLocalStorage, @@ -54,12 +54,14 @@ const BAD_USER_ATTRIBUTE_KEY_AS_ARRAY = ([ const BAD_USER_ATTRIBUTE_LIST_VALUE = (1234 as unknown) as UserAttributesValue[]; describe.only('identities and attributes', function() { + let loggerSpy; let beforeEachCallbackCalled = false; let hasBeforeEachCallbackReturned; beforeEach(function() { mParticle._resetForTests(MPConfig); fetchMock.config.overwriteRoutes = true; + loggerSpy = Utils.setupLoggerSpy(); fetchMockSuccess(urls.identify, { mpid: testMPID, is_logged_in: false @@ -897,9 +899,7 @@ describe.only('identities and attributes', function() { delete window.mParticle.config.flags; }); - // https://go/j-SDKE-420 it('should send user identity change requests when setting new identities on new users', async () => { - const loggerSpy = Utils.setupLoggerSpy(); fetchMock.resetHistory(); window.mParticle.config.identifyRequest = { @@ -909,7 +909,7 @@ describe.only('identities and attributes', function() { }; mParticle.config.flags.eventBatchingIntervalMillis = 5000 mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(() => Utils.hasIdentityResponseParsed(loggerSpy)); + await waitForCondition(hasIdentityResponseParsed(loggerSpy)); mParticle.upload(); expect( JSON.parse(`${fetchMock.lastOptions().body}`).user_identities @@ -936,7 +936,7 @@ describe.only('identities and attributes', function() { }; loggerSpy.verbose.resetHistory(); mParticle.Identity.login(loginUser); - await waitForCondition(() => Utils.hasIdentityResponseParsed(loggerSpy)); + await waitForCondition(hasIdentityResponseParsed(loggerSpy)); let body = JSON.parse(`${fetchMock.lastOptions().body}`); // should be the new MPID @@ -982,7 +982,7 @@ describe.only('identities and attributes', function() { loggerSpy.verbose.resetHistory(); mParticle.Identity.modify(modifyUser); - await waitForCondition(() => Utils.hasIdentityResponseParsed(loggerSpy)); + await waitForCondition(hasIdentityResponseParsed(loggerSpy)); const body2 = JSON.parse(`${fetchMock.lastOptions().body}`); expect(body2.mpid).to.equal('anotherMPID'); expect(body2.user_identities).to.have.property( @@ -1015,7 +1015,7 @@ describe.only('identities and attributes', function() { loggerSpy.verbose.resetHistory(); mParticle.Identity.modify(modifyUser2); - await waitForCondition(() => Utils.hasIdentityResponseParsed(loggerSpy)); + await waitForCondition(hasIdentityResponseParsed(loggerSpy)); const body3 = JSON.parse(`${fetchMock.lastOptions().body}`); expect(body3.mpid).to.equal('anotherMPID'); @@ -1046,7 +1046,7 @@ describe.only('identities and attributes', function() { loggerSpy.verbose.resetHistory(); mParticle.Identity.logout(logoutUser); - await waitForCondition(() => Utils.hasIdentityResponseParsed(loggerSpy)); + await waitForCondition(hasIdentityResponseParsed(loggerSpy)); // Calls are for logout and UIC expect(fetchMock.calls().length).to.equal(2); const body4 = JSON.parse(`${fetchMock.lastOptions().body}`); @@ -1088,7 +1088,7 @@ describe.only('identities and attributes', function() { mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentityCallInflightReturned); + await waitForCondition(hasIdentityResponseParsed(loggerSpy)); mParticle.logEvent('Test Event 1'); mParticle.logEvent('Test Event 2'); @@ -1157,7 +1157,7 @@ describe.only('identities and attributes', function() { expect(mParticle.getInstance()._preInit.readyQueue.length).to.equal(3); - await waitForCondition(hasIdentityCallInflightReturned); + await waitForCondition(hasIdentityResponseParsed(loggerSpy)); expect(fetchMock.calls().length).to.equal(7); @@ -1215,7 +1215,7 @@ describe.only('identities and attributes', function() { mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentifyReturned); + await waitForCondition(hasIdentityResponseParsed(loggerSpy)); fetchMockSuccess(urls.login, { mpid: 'testMPID', is_logged_in: true }); @@ -1226,15 +1226,10 @@ describe.only('identities and attributes', function() { }, }; + loggerSpy.verbose.resetHistory(); mParticle.Identity.login(loginUser); - await waitForCondition(() => { - const currentUser = mParticle.Identity.getCurrentUser(); - const userIdentities = currentUser?.getUserIdentities()?.userIdentities; - return userIdentities && - userIdentities.customerid === 'customerid1' && - userIdentities.email === 'initial@gmail.com'; - }); + await waitForCondition(hasIdentityResponseParsed(loggerSpy)); let batch = JSON.parse(`${fetchMock.lastOptions().body}`); expect(batch.mpid).to.equal(testMPID); @@ -1257,14 +1252,9 @@ describe.only('identities and attributes', function() { mpid: 'mpid2', is_logged_in: false }); + loggerSpy.verbose.resetHistory(); mParticle.Identity.logout(logoutUser); - await waitForCondition(hasIdentityCallInflightReturned); - - await waitForCondition(() => { - return ( - mParticle.Identity.getCurrentUser()?.getMPID() === 'mpid2' - ); - }); + await waitForCondition(hasIdentityResponseParsed(loggerSpy)); batch = JSON.parse(`${fetchMock.lastOptions().body}`); expect(batch.mpid).to.equal('mpid2'); expect(batch.user_identities).to.have.property('other', 'other1'); @@ -1278,13 +1268,10 @@ describe.only('identities and attributes', function() { mpid: 'testMPID', is_logged_in: true }); + loggerSpy.verbose.resetHistory(); mParticle.Identity.login(loginUser); - await waitForCondition(() => { - return ( - mParticle.getInstance()._Store.identityCallInFlight === false - ); - }); + await waitForCondition(hasIdentityResponseParsed(loggerSpy)); // switching back to logged in user should not result in any UIC events expect(fetchMock.calls().length).to.equal(1); From e0032c7d594221eb4a5615f1c1797a8d143cba0d Mon Sep 17 00:00:00 2001 From: Jaissica Date: Mon, 27 Oct 2025 14:17:31 -0400 Subject: [PATCH 22/40] test: fix logger spy scope in identity attributes test --- test/src/tests-identities-attributes.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/src/tests-identities-attributes.ts b/test/src/tests-identities-attributes.ts index 5302d50da..bdeca6998 100644 --- a/test/src/tests-identities-attributes.ts +++ b/test/src/tests-identities-attributes.ts @@ -61,7 +61,6 @@ describe.only('identities and attributes', function() { beforeEach(function() { mParticle._resetForTests(MPConfig); fetchMock.config.overwriteRoutes = true; - loggerSpy = Utils.setupLoggerSpy(); fetchMockSuccess(urls.identify, { mpid: testMPID, is_logged_in: false @@ -901,6 +900,8 @@ describe.only('identities and attributes', function() { it('should send user identity change requests when setting new identities on new users', async () => { fetchMock.resetHistory(); + + loggerSpy = Utils.setupLoggerSpy(); window.mParticle.config.identifyRequest = { userIdentities: { @@ -1079,6 +1080,8 @@ describe.only('identities and attributes', function() { // Clear out before each init call await waitForCondition(hasBeforeEachCallbackReturned); + + loggerSpy = Utils.setupLoggerSpy(); window.mParticle.config.identifyRequest = { userIdentities: { @@ -1142,6 +1145,8 @@ describe.only('identities and attributes', function() { // Clear out before each init call await waitForCondition(hasBeforeEachCallbackReturned); + + loggerSpy = Utils.setupLoggerSpy(); window.mParticle.config.identifyRequest = { userIdentities: { @@ -1202,6 +1207,8 @@ describe.only('identities and attributes', function() { }); it('should send historical UIs on batches when MPID changes', async () => { + loggerSpy = Utils.setupLoggerSpy(); + window.mParticle.config.identifyRequest = { userIdentities: { email: 'initial@gmail.com', From 565cec7945f157c4a5647c837a9d503ea07b7d70 Mon Sep 17 00:00:00 2001 From: Jaissica Date: Tue, 28 Oct 2025 09:20:55 -0400 Subject: [PATCH 23/40] test: update logger spy in identity tests --- test/src/tests-identities-attributes.ts | 20 +++++--- test/src/tests-identity.ts | 61 +++++++++++++------------ 2 files changed, 45 insertions(+), 36 deletions(-) diff --git a/test/src/tests-identities-attributes.ts b/test/src/tests-identities-attributes.ts index bdeca6998..33a43ea9a 100644 --- a/test/src/tests-identities-attributes.ts +++ b/test/src/tests-identities-attributes.ts @@ -20,7 +20,8 @@ const { findBatch, getLocalStorage, MockForwarder, - getIdentityEvent + getIdentityEvent, + setupLoggerSpy } = Utils; declare global { @@ -899,9 +900,11 @@ describe.only('identities and attributes', function() { }); it('should send user identity change requests when setting new identities on new users', async () => { + mParticle._resetForTests(MPConfig); fetchMock.resetHistory(); - - loggerSpy = Utils.setupLoggerSpy(); + loggerSpy = setupLoggerSpy(); + // Clear out before each init call + await waitForCondition(hasBeforeEachCallbackReturned); window.mParticle.config.identifyRequest = { userIdentities: { @@ -1081,7 +1084,7 @@ describe.only('identities and attributes', function() { // Clear out before each init call await waitForCondition(hasBeforeEachCallbackReturned); - loggerSpy = Utils.setupLoggerSpy(); + loggerSpy = setupLoggerSpy(); window.mParticle.config.identifyRequest = { userIdentities: { @@ -1146,7 +1149,7 @@ describe.only('identities and attributes', function() { // Clear out before each init call await waitForCondition(hasBeforeEachCallbackReturned); - loggerSpy = Utils.setupLoggerSpy(); + loggerSpy = setupLoggerSpy(); window.mParticle.config.identifyRequest = { userIdentities: { @@ -1207,7 +1210,12 @@ describe.only('identities and attributes', function() { }); it('should send historical UIs on batches when MPID changes', async () => { - loggerSpy = Utils.setupLoggerSpy(); + mParticle._resetForTests(MPConfig); + fetchMock.resetHistory(); + // Clear out before each init call + await waitForCondition(hasBeforeEachCallbackReturned); + + loggerSpy = setupLoggerSpy(); window.mParticle.config.identifyRequest = { userIdentities: { diff --git a/test/src/tests-identity.ts b/test/src/tests-identity.ts index d1318c82d..94b39dcfe 100644 --- a/test/src/tests-identity.ts +++ b/test/src/tests-identity.ts @@ -40,6 +40,8 @@ const { MockForwarder, waitForCondition, hasIdentityCallInflightReturned, + setupLoggerSpy, + hasIdentityResponseParsed, } = Utils; const { HTTPCodes } = Constants; @@ -91,6 +93,7 @@ const fetchMockSuccess = (url: string, body: any = {}, headers: any = {}) => { describe.only('identity', function() { let clock; + let loggerSpy; let hasIdentifyReturned; let hasIdentifyReturnedWithEmail; let hasLoginReturned; @@ -673,8 +676,8 @@ describe.only('identity', function() { // https://go.mparticle.com/work/SQDSDKS-6849 // This test passes with no issue when it is run on its own, but fails when tests-forwarders.js are also ran. // https://go/j-SDKE-420 - it('should respect consent rules on consent-change', async () => { - const loggerSpy = Utils.setupLoggerSpy(); + it('should respect consent rules on consent-change', async () => { + loggerSpy = setupLoggerSpy(); mParticle.config.isDevelopmentMode = false; const mockForwarder = new MockForwarder('MockForwarder1'); mockForwarder.register(window.mParticle.config); @@ -718,7 +721,7 @@ describe.only('identity', function() { mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(() => Utils.hasIdentityResponseParsed(loggerSpy)); + await waitForCondition(hasIdentityResponseParsed(loggerSpy)); let activeForwarders = mParticle.getInstance()._getActiveForwarders(); expect(activeForwarders.length).to.equal(0); @@ -742,7 +745,7 @@ describe.only('identity', function() { loggerSpy.verbose.resetHistory(); mParticle.Identity.login(); - await waitForCondition(() => Utils.hasIdentityResponseParsed(loggerSpy)); + await waitForCondition(hasIdentityResponseParsed(loggerSpy)); activeForwarders = mParticle.getInstance()._getActiveForwarders(); expect(activeForwarders.length).to.equal(0); @@ -864,14 +867,14 @@ describe.only('identity', function() { // https://go/j-SDKE-420 it('cookies - should switch user cookies to new mpid details from cookies when a new mpid is provided', async () => { - const loggerSpy = Utils.setupLoggerSpy(); + loggerSpy = setupLoggerSpy(); mParticle.config.useCookieStorage = true; setLocalStorage(); mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(() => Utils.hasIdentityResponseParsed(loggerSpy)); + await waitForCondition(hasIdentifyReturned); const cookiesAfterInit = findCookie(); cookiesAfterInit.should.have.properties('gs', 'cu', testMPID); @@ -904,10 +907,9 @@ describe.only('identity', function() { }, }; - loggerSpy.verbose.resetHistory(); mParticle.Identity.login(userIdentities1); - await waitForCondition(() => Utils.hasIdentityResponseParsed(loggerSpy)); + await waitForCondition(hasIdentityResponseParsed(loggerSpy)); const cookiesAfterMPIDChange = findCookie(); cookiesAfterMPIDChange.should.have.properties([ @@ -2193,7 +2195,7 @@ describe.only('identity', function() { // https://go/j-SDKE-420 it('should add new MPIDs to cookie structure when initializing new identity requests, returning an existing mpid when reinitializing with a previous identity', async () => { - const loggerSpy = Utils.setupLoggerSpy(); + loggerSpy = setupLoggerSpy(); const user1 = { userIdentities: { customerid: '1', @@ -2222,7 +2224,7 @@ describe.only('identity', function() { mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(() => Utils.hasIdentityResponseParsed(loggerSpy)); + await waitForCondition(hasIdentityResponseParsed(loggerSpy)); const user1UIs = mParticle.Identity.getCurrentUser().getUserIdentities(); @@ -2236,7 +2238,7 @@ describe.only('identity', function() { loggerSpy.verbose.resetHistory(); mParticle.Identity.login(user2); - await waitForCondition(() => Utils.hasIdentityResponseParsed(loggerSpy)); + await waitForCondition(hasIdentityResponseParsed(loggerSpy)); const user2UIs = mParticle.Identity.getCurrentUser().getUserIdentities(); user2UIs.userIdentities.customerid.should.equal('2'); @@ -2249,7 +2251,7 @@ describe.only('identity', function() { loggerSpy.verbose.resetHistory(); mParticle.Identity.login(user3); - await waitForCondition(() => Utils.hasIdentityResponseParsed(loggerSpy)); + await waitForCondition(hasIdentityResponseParsed(loggerSpy)); const user3UIs = mParticle.Identity.getCurrentUser().getUserIdentities(); user3UIs.userIdentities.customerid.should.equal('3'); @@ -2262,7 +2264,7 @@ describe.only('identity', function() { loggerSpy.verbose.resetHistory(); mParticle.Identity.login(user4); - await waitForCondition(() => Utils.hasIdentityResponseParsed(loggerSpy)); + await waitForCondition(hasIdentityResponseParsed(loggerSpy)); const user4UIs = mParticle.Identity.getCurrentUser().getUserIdentities(); user4UIs.userIdentities.customerid.should.equal('4'); @@ -2275,7 +2277,7 @@ describe.only('identity', function() { loggerSpy.verbose.resetHistory(); mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(() => Utils.hasIdentityResponseParsed(loggerSpy)); + await waitForCondition(hasIdentityResponseParsed(loggerSpy)); const user5 = mParticle.Identity.getCurrentUser(); user5.getUserIdentities().userIdentities.customerid.should.equal('1'); @@ -3010,7 +3012,7 @@ describe.only('identity', function() { // Init fires an identify call mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(() => Utils.hasIdentityResponseParsed(loggerSpy)); + await waitForCondition(hasIdentityResponseParsed(loggerSpy)); result.should.have.properties('body', 'httpCode', 'getUser'); result.httpCode.should.equal(200); @@ -3028,7 +3030,7 @@ describe.only('identity', function() { // https://go/j-SDKE-420 it('should have a getUser function on login result object', async () => { - const loggerSpy = Utils.setupLoggerSpy(); + loggerSpy = setupLoggerSpy(); let result let loginResult; @@ -3049,7 +3051,7 @@ describe.only('identity', function() { mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(() => Utils.hasIdentityResponseParsed(loggerSpy)); + await waitForCondition(hasIdentityResponseParsed(loggerSpy)); const identityRequest = { userIdentities: { customerid: 'test123' } }; function loginCallback(result) { @@ -3059,7 +3061,7 @@ describe.only('identity', function() { loggerSpy.verbose.resetHistory(); mParticle.Identity.login(identityRequest, loginCallback); - await waitForCondition(() => Utils.hasIdentityResponseParsed(loggerSpy)); + await waitForCondition(hasIdentityResponseParsed(loggerSpy)); loginResult .getUser() @@ -3074,7 +3076,7 @@ describe.only('identity', function() { // https://go/j-SDKE-420 it('should have a getUser function on logout result object', async () => { - const loggerSpy = Utils.setupLoggerSpy(); + loggerSpy = setupLoggerSpy(); let result; let logoutResult; @@ -3095,7 +3097,7 @@ describe.only('identity', function() { mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(() => Utils.hasIdentityResponseParsed(loggerSpy)); + await waitForCondition(hasIdentityResponseParsed(loggerSpy)); const identityRequest = { userIdentities: { customerid: 'test123' } }; function logoutCallback(result) { @@ -3105,7 +3107,7 @@ describe.only('identity', function() { loggerSpy.verbose.resetHistory(); mParticle.Identity.logout(identityRequest, logoutCallback); - await waitForCondition(() => Utils.hasIdentityResponseParsed(loggerSpy)); + await waitForCondition(hasIdentityResponseParsed(loggerSpy)); logoutResult .getUser() @@ -3120,7 +3122,7 @@ describe.only('identity', function() { // https://go/j-SDKE-420 it('should have a getUser function on modify result object', async () => { - const loggerSpy = Utils.setupLoggerSpy(); + loggerSpy = setupLoggerSpy(); let result let modifyResult; @@ -3134,14 +3136,14 @@ describe.only('identity', function() { is_logged_in: false, }); - fetchMockSuccess('https://identity.mparticle.com/v1/MPID1/modify', { + fetchMockSuccess("https://identity.mparticle.com/v1/MPID1/modify", { mpid: 'MPID1', is_logged_in: false, }); mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(() => Utils.hasIdentityResponseParsed(loggerSpy)); + await waitForCondition(hasIdentityResponseParsed(loggerSpy)); const identityRequest = { userIdentities: { customerid: 'test123' } }; function modifyCallback(result) { @@ -3151,7 +3153,7 @@ describe.only('identity', function() { loggerSpy.verbose.resetHistory(); mParticle.Identity.modify(identityRequest, modifyCallback); - await waitForCondition(() => Utils.hasIdentityResponseParsed(loggerSpy)); + await waitForCondition(hasIdentityResponseParsed(loggerSpy)); modifyResult .getUser() @@ -3170,8 +3172,6 @@ describe.only('identity', function() { // client had no programmatic handling of a failed identify request mParticle._resetForTests(MPConfig); - await waitForCondition(hasIdentityCallInflightReturned); - fetchMockSuccess(urls.identify, { mpid: 'MPID1', is_logged_in: false, @@ -4468,7 +4468,7 @@ describe.only('identity', function() { // https://go/j-SDKE-420 it('should set currentUser once the email is positively identified', async () => { - const loggerSpy = Utils.setupLoggerSpy(); + loggerSpy = setupLoggerSpy(); fetchMockSuccess(urls.identify, { mpid: testRoktMPID, is_logged_in: false, @@ -4479,12 +4479,13 @@ describe.only('identity', function() { mParticle.init(apiKey, { ...window.mParticle.config, kitConfigs: [roktConfig] }); - await waitForCondition(() => Utils.hasIdentityResponseParsed(loggerSpy)); + await waitForCondition(() => hasIdentifyReturned(testRoktMPID)); const mpInstance = mParticle.getInstance(); mpInstance._RoktManager.attachKit(roktKit); + fetchMock.resetHistory(); loggerSpy.verbose.resetHistory(); mParticle.Identity.identify({ userIdentities: { @@ -4492,7 +4493,7 @@ describe.only('identity', function() { }, }); - await waitForCondition(() => Utils.hasIdentityResponseParsed(loggerSpy)); + await waitForCondition(hasIdentityResponseParsed(loggerSpy)); expect(mpInstance._RoktManager['currentUser']).to.not.be.null; expect(mpInstance._RoktManager['currentUser'].getUserIdentities().userIdentities.email).to.equal(testRoktEmail); From 32e35f339f5d0fd316dec225af3d8e61811ad194 Mon Sep 17 00:00:00 2001 From: Jaissica Date: Tue, 28 Oct 2025 09:34:41 -0400 Subject: [PATCH 24/40] test: updated identity callback test to handle timeout error --- test/src/tests-identity.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/src/tests-identity.ts b/test/src/tests-identity.ts index 94b39dcfe..d2470f34c 100644 --- a/test/src/tests-identity.ts +++ b/test/src/tests-identity.ts @@ -2972,6 +2972,7 @@ describe.only('identity', function() { it('identifyCallback response should have a getUser function on the result object', async () => { let result; + loggerSpy = setupLoggerSpy(); fetchMockSuccess(urls.identify, { mpid: 'MPID1', is_logged_in: false, @@ -2984,7 +2985,7 @@ describe.only('identity', function() { mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentityCallInflightReturned); + await waitForCondition(hasIdentityResponseParsed(loggerSpy)); result.should.have.property('getUser'); From 1dec71775d4124e0da8cd876c3e911bb1116ce91 Mon Sep 17 00:00:00 2001 From: Jaissica Date: Tue, 28 Oct 2025 09:45:44 -0400 Subject: [PATCH 25/40] test: rollback karma config timeout to 5 sec --- test/karma.config.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/test/karma.config.js b/test/karma.config.js index d1a2b4fe7..b5aafb1f0 100644 --- a/test/karma.config.js +++ b/test/karma.config.js @@ -49,14 +49,13 @@ module.exports = function(config) { client: { captureConsole, mocha: { - timeout: 10000 // 10 seconds. Increase from default 2 seconds. + timeout: 5000 // 5 seconds. Increase from default 2 seconds. } }, customLaunchers: { FirefoxHeadless: { base: 'Firefox', flags: ['-headless'], - browserNoActivityTimeout: 60000, }, }, junitReporter: { From 1dc590e1e605054c822dd191f1d92b1da492341c Mon Sep 17 00:00:00 2001 From: Jaissica Date: Tue, 28 Oct 2025 10:08:40 -0400 Subject: [PATCH 26/40] test: update failing identity tests to with logger spy --- test/src/tests-identity.ts | 35 ++++++++++++++++------------------- 1 file changed, 16 insertions(+), 19 deletions(-) diff --git a/test/src/tests-identity.ts b/test/src/tests-identity.ts index d2470f34c..8c1f3edfa 100644 --- a/test/src/tests-identity.ts +++ b/test/src/tests-identity.ts @@ -805,6 +805,7 @@ describe.only('identity', function() { }); it('localStorage - should switch user cookies to new mpid details from cookies when a new mpid is provided', async () => { + loggerSpy = setupLoggerSpy(); window.mParticle.config.useCookieStorage = false; setLocalStorage(); @@ -827,7 +828,7 @@ describe.only('identity', function() { }; mParticle.Identity.login(userIdentities1); - await waitForCondition(hasLoginReturned); + await waitForCondition(hasIdentityResponseParsed(loggerSpy)); const cookiesAfterMPIDChange = mParticle .getInstance() ._Persistence.getLocalStorage(); @@ -2064,6 +2065,7 @@ describe.only('identity', function() { }); it("should find the related MPID's cookies when given a UI with fewer IDs when passed to login, logout, and identify, and then log events with updated cookies", async () => { + loggerSpy = setupLoggerSpy(); fetchMock.restore(); const user1: IdentityApiData = { userIdentities: { @@ -2101,22 +2103,16 @@ describe.only('identity', function() { ], }); - await waitForCondition(hasIdentifyReturned); + await waitForCondition(hasIdentityResponseParsed(loggerSpy)); + + loggerSpy.verbose.resetHistory(); mParticle.Identity.modify(user1modified); // Should contain the following calls: // 1 for the initial identify // 3 for the events (Session Start, UAT and UIC) // 1 for the modify // 1 for the UIC event - await waitForCondition(hasIdentityCallInflightReturned); - - await waitForCondition(() => { - const currentUser = mParticle.Identity.getCurrentUser(); - const userIdentities = currentUser?.getUserIdentities()?.userIdentities; - return userIdentities && - userIdentities.customerid === 'customerid1' && - userIdentities.email === 'email2@test.com'; - }); + await waitForCondition(hasIdentityResponseParsed(loggerSpy)); expect(fetchMock.calls().length).to.equal(6); @@ -2145,11 +2141,12 @@ describe.only('identity', function() { fetchMockSuccess(urls.logout, { mpid: 'logged-out-user', is_logged_in: true, - }); + }); + loggerSpy.verbose.resetHistory(); mParticle.Identity.logout(user2); - await waitForCondition(hasLogOutReturned); + await waitForCondition(hasIdentityResponseParsed(loggerSpy)); // This will add the following new calls: // 1 for the logout @@ -2170,13 +2167,11 @@ describe.only('identity', function() { fetchMockSuccess(urls.login, { mpid: 'testMPID', is_logged_in: true, - }); + }); + loggerSpy.verbose.resetHistory(); mParticle.Identity.login(user1); - await waitForCondition(hasIdentityCallInflightReturned); - await waitForCondition(() => { - return mParticle.Identity.getCurrentUser().getMPID() === 'testMPID'; - }); + await waitForCondition(hasIdentityResponseParsed(loggerSpy)); // This will add the following new calls: // 1 for the login @@ -3169,6 +3164,7 @@ describe.only('identity', function() { }); it('should call identify when there is an active session but no current user', async () => { + loggerSpy = setupLoggerSpy(); // this broken cookie state occurs when an initial identify request is made, fails, and the // client had no programmatic handling of a failed identify request mParticle._resetForTests(MPConfig); @@ -3202,9 +3198,10 @@ describe.only('identity', function() { }, }; fetchMock.resetHistory(); + loggerSpy.verbose.resetHistory(); mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(() => mParticle.Identity.getCurrentUser()?.getMPID() === 'MPID1'); + await waitForCondition(hasIdentityResponseParsed(loggerSpy)); cookies = mParticle.getInstance()._Persistence.getPersistence(); cookies.should.have.property('gs'); From fa332dd3d7b897c053b423a35dba120ffcaea27c Mon Sep 17 00:00:00 2001 From: Jaissica Date: Tue, 28 Oct 2025 10:32:44 -0400 Subject: [PATCH 27/40] test: update identity test waitForCondition for modify function --- test/src/tests-identity.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/test/src/tests-identity.ts b/test/src/tests-identity.ts index 8c1f3edfa..34d0e4b9a 100644 --- a/test/src/tests-identity.ts +++ b/test/src/tests-identity.ts @@ -2112,7 +2112,13 @@ describe.only('identity', function() { // 3 for the events (Session Start, UAT and UIC) // 1 for the modify // 1 for the UIC event - await waitForCondition(hasIdentityResponseParsed(loggerSpy)); + await waitForCondition(() => { + const currentUser = mParticle.Identity.getCurrentUser(); + const userIdentities = currentUser?.getUserIdentities()?.userIdentities; + return userIdentities && + userIdentities.customerid === 'customerid1' && + userIdentities.email === 'email2@test.com'; + }); expect(fetchMock.calls().length).to.equal(6); @@ -2172,7 +2178,6 @@ describe.only('identity', function() { loggerSpy.verbose.resetHistory(); mParticle.Identity.login(user1); await waitForCondition(hasIdentityResponseParsed(loggerSpy)); - // This will add the following new calls: // 1 for the login // 1 for Test Event 3 From 2c02bcdb6789495d451802c3a0ef94036cb81162 Mon Sep 17 00:00:00 2001 From: Jaissica Date: Tue, 28 Oct 2025 10:45:57 -0400 Subject: [PATCH 28/40] test: rollback karma config and remove SDKE-420 ticket comment --- test/karma.config.js | 3 ++- test/src/tests-identity.ts | 8 -------- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/test/karma.config.js b/test/karma.config.js index b5aafb1f0..d1a2b4fe7 100644 --- a/test/karma.config.js +++ b/test/karma.config.js @@ -49,13 +49,14 @@ module.exports = function(config) { client: { captureConsole, mocha: { - timeout: 5000 // 5 seconds. Increase from default 2 seconds. + timeout: 10000 // 10 seconds. Increase from default 2 seconds. } }, customLaunchers: { FirefoxHeadless: { base: 'Firefox', flags: ['-headless'], + browserNoActivityTimeout: 60000, }, }, junitReporter: { diff --git a/test/src/tests-identity.ts b/test/src/tests-identity.ts index 34d0e4b9a..2ebfba9a4 100644 --- a/test/src/tests-identity.ts +++ b/test/src/tests-identity.ts @@ -675,7 +675,6 @@ describe.only('identity', function() { // https://go.mparticle.com/work/SQDSDKS-6849 // This test passes with no issue when it is run on its own, but fails when tests-forwarders.js are also ran. - // https://go/j-SDKE-420 it('should respect consent rules on consent-change', async () => { loggerSpy = setupLoggerSpy(); mParticle.config.isDevelopmentMode = false; @@ -866,7 +865,6 @@ describe.only('identity', function() { }); }); - // https://go/j-SDKE-420 it('cookies - should switch user cookies to new mpid details from cookies when a new mpid is provided', async () => { loggerSpy = setupLoggerSpy(); mParticle.config.useCookieStorage = true; @@ -2193,7 +2191,6 @@ describe.only('identity', function() { }); }); - // https://go/j-SDKE-420 it('should add new MPIDs to cookie structure when initializing new identity requests, returning an existing mpid when reinitializing with a previous identity', async () => { loggerSpy = setupLoggerSpy(); const user1 = { @@ -2994,7 +2991,6 @@ describe.only('identity', function() { .should.have.property('test', 'value'); }); - // https://go/j-SDKE-420 describe('identityCallback responses', function () { it('should have a getUser function on identify result object', async () => { const loggerSpy = Utils.setupLoggerSpy(); @@ -3029,7 +3025,6 @@ describe.only('identity', function() { .should.have.property('attr', 'value'); }); - // https://go/j-SDKE-420 it('should have a getUser function on login result object', async () => { loggerSpy = setupLoggerSpy(); let result @@ -3075,7 +3070,6 @@ describe.only('identity', function() { .should.have.property('attr', 'value'); }); - // https://go/j-SDKE-420 it('should have a getUser function on logout result object', async () => { loggerSpy = setupLoggerSpy(); let result; @@ -3121,7 +3115,6 @@ describe.only('identity', function() { .should.have.property('attr', 'value'); }); - // https://go/j-SDKE-420 it('should have a getUser function on modify result object', async () => { loggerSpy = setupLoggerSpy(); let result @@ -4469,7 +4462,6 @@ describe.only('identity', function() { } as unknown as IRoktKit; }); - // https://go/j-SDKE-420 it('should set currentUser once the email is positively identified', async () => { loggerSpy = setupLoggerSpy(); fetchMockSuccess(urls.identify, { From 9c90192428d4e66d6b84a751300639c9cc178d99 Mon Sep 17 00:00:00 2001 From: Jaissica Date: Tue, 28 Oct 2025 11:03:01 -0400 Subject: [PATCH 29/40] test: removed extra spaces and waitForCondition calls from identity tests --- test/src/tests-identity.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/test/src/tests-identity.ts b/test/src/tests-identity.ts index 2ebfba9a4..04afef1c2 100644 --- a/test/src/tests-identity.ts +++ b/test/src/tests-identity.ts @@ -777,7 +777,6 @@ describe.only('identity', function() { }; mParticle.Identity.login(userIdentities1); - await waitForCondition(hasIdentityCallInflightReturned); await waitForCondition(hasLoginReturned); const localStorageDataBeforeSessionEnd = mParticle @@ -1371,8 +1370,7 @@ describe.only('identity', function() { const identityAPIRequest = BAD_USER_IDENTITIES_AS_STRING; mParticle.Identity.login(identityAPIRequest); - await waitForCondition(hasIdentityCallInflightReturned) - + await waitForCondition(hasIdentityCallInflightReturned); expect(fetchMock.calls().length).to.equal(0); }); @@ -2275,7 +2273,7 @@ describe.only('identity', function() { mParticle.init(apiKey, window.mParticle.config); await waitForCondition(hasIdentityResponseParsed(loggerSpy)); - + const user5 = mParticle.Identity.getCurrentUser(); user5.getUserIdentities().userIdentities.customerid.should.equal('1'); user5.getMPID().should.equal('testMPID'); @@ -2612,7 +2610,6 @@ describe.only('identity', function() { await waitForCondition(hasIdentityCallInflightReturned); - expect(hasBeenRun).to.be.true; }); @@ -4514,7 +4511,7 @@ describe.only('identity', function() { mParticle.init(apiKey, { ...window.mParticle.config, kitConfigs: [roktConfig] }); - await waitForCondition(hasIdentityCallInflightReturned); + await waitForCondition(hasIdentityCallInflightReturned); const mpInstance = mParticle.getInstance(); From 705e462d51d9f52f122781d72afb02496e6b571e Mon Sep 17 00:00:00 2001 From: Jaissica Date: Tue, 28 Oct 2025 11:25:23 -0400 Subject: [PATCH 30/40] test: added ticket SDKE-420 comment for flakey test --- test/src/tests-identity.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/test/src/tests-identity.ts b/test/src/tests-identity.ts index 04afef1c2..f0d803a48 100644 --- a/test/src/tests-identity.ts +++ b/test/src/tests-identity.ts @@ -3158,6 +3158,7 @@ describe.only('identity', function() { }); }); + // https://go.mparticle.com/work/SDKE-420 it('should call identify when there is an active session but no current user', async () => { loggerSpy = setupLoggerSpy(); // this broken cookie state occurs when an initial identify request is made, fails, and the From 7eb53bc4630134419d536bdbb82c5e54515ab735 Mon Sep 17 00:00:00 2001 From: Jaissica Date: Tue, 28 Oct 2025 16:00:02 -0400 Subject: [PATCH 31/40] test: clean up identity tests and add SDKE-420 comment to flaky tests --- test/src/config/utils.js | 2 +- test/src/tests-identities-attributes.ts | 19 +++++++++---------- test/src/tests-identity.ts | 19 ++++++++++++------- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/test/src/config/utils.js b/test/src/config/utils.js index 24a254f33..1f48146f6 100644 --- a/test/src/config/utils.js +++ b/test/src/config/utils.js @@ -640,7 +640,7 @@ var pluses = /\+/g, hasIdentityResponseParsed = (loggerSpy) => { return () => loggerSpy?.verbose?.getCalls()?.some(call => call.args[0] === 'Successfully parsed Identity Response' - ) || false; + ); }, getBeaconBatch = async function(beaconSpy, callIndex = 0) { const beaconCall = beaconSpy.getCall(callIndex); diff --git a/test/src/tests-identities-attributes.ts b/test/src/tests-identities-attributes.ts index 33a43ea9a..fde385b72 100644 --- a/test/src/tests-identities-attributes.ts +++ b/test/src/tests-identities-attributes.ts @@ -900,11 +900,12 @@ describe.only('identities and attributes', function() { }); it('should send user identity change requests when setting new identities on new users', async () => { + // Clear out before each init call + await waitForCondition(hasBeforeEachCallbackReturned); + mParticle._resetForTests(MPConfig); fetchMock.resetHistory(); loggerSpy = setupLoggerSpy(); - // Clear out before each init call - await waitForCondition(hasBeforeEachCallbackReturned); window.mParticle.config.identifyRequest = { userIdentities: { @@ -1078,12 +1079,11 @@ describe.only('identities and attributes', function() { }); it('should order user identity change events before logging any events', async () => { - mParticle._resetForTests(MPConfig); - fetchMock.resetHistory(); - // Clear out before each init call await waitForCondition(hasBeforeEachCallbackReturned); + mParticle._resetForTests(MPConfig); + fetchMock.resetHistory(); loggerSpy = setupLoggerSpy(); window.mParticle.config.identifyRequest = { @@ -1143,12 +1143,11 @@ describe.only('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(); - // Clear out before each init call await waitForCondition(hasBeforeEachCallbackReturned); + mParticle._resetForTests(MPConfig); + fetchMock.resetHistory(); loggerSpy = setupLoggerSpy(); window.mParticle.config.identifyRequest = { @@ -1210,11 +1209,11 @@ describe.only('identities and attributes', function() { }); it('should send historical UIs on batches when MPID changes', async () => { - mParticle._resetForTests(MPConfig); - fetchMock.resetHistory(); // Clear out before each init call await waitForCondition(hasBeforeEachCallbackReturned); + mParticle._resetForTests(MPConfig); + fetchMock.resetHistory(); loggerSpy = setupLoggerSpy(); window.mParticle.config.identifyRequest = { diff --git a/test/src/tests-identity.ts b/test/src/tests-identity.ts index f0d803a48..a97ebb959 100644 --- a/test/src/tests-identity.ts +++ b/test/src/tests-identity.ts @@ -864,6 +864,7 @@ describe.only('identity', function() { }); }); + // https://go.mparticle.com/work/SDKE-420 it('cookies - should switch user cookies to new mpid details from cookies when a new mpid is provided', async () => { loggerSpy = setupLoggerSpy(); mParticle.config.useCookieStorage = true; @@ -1763,7 +1764,9 @@ describe.only('identity', function() { spy.calledOnce.should.be.ok(); }); + // https://go.mparticle.com/work/SDKE-420 it('queue events when MPID is 0, and then flush events once MPID changes', async () => { + loggerSpy = setupLoggerSpy(); fetchMock.resetHistory(); fetchMock.post(urls.identify, { @@ -1785,7 +1788,7 @@ describe.only('identity', function() { mParticle.init(apiKey, window.mParticle.config); - await waitForCondition(hasIdentityCallInflightReturned); + await waitForCondition(hasIdentityResponseParsed(loggerSpy)); expect(mParticle.Identity.getCurrentUser()).to.be.null; @@ -1814,10 +1817,9 @@ describe.only('identity', function() { }); mParticle.logEvent('Test Event 2'); + loggerSpy.verbose.resetHistory(); mParticle.Identity.login(); - - await waitForCondition(hasIdentityCallInflightReturned); - await waitForCondition(hasLoginReturned); + await waitForCondition(hasIdentityResponseParsed(loggerSpy)); // server requests will now have the following events: // 1. Identify (from init) @@ -2060,6 +2062,7 @@ describe.only('identity', function() { expect(Object.keys(combinedUIsByType).length).to.equal(4); }); + // https://go.mparticle.com/work/SDKE-420 it("should find the related MPID's cookies when given a UI with fewer IDs when passed to login, logout, and identify, and then log events with updated cookies", async () => { loggerSpy = setupLoggerSpy(); fetchMock.restore(); @@ -2189,6 +2192,7 @@ describe.only('identity', function() { }); }); + // https://go.mparticle.com/work/SDKE-420 it('should add new MPIDs to cookie structure when initializing new identity requests, returning an existing mpid when reinitializing with a previous identity', async () => { loggerSpy = setupLoggerSpy(); const user1 = { @@ -2839,9 +2843,8 @@ describe.only('identity', function() { }); it('should trigger the identityCallback before eventQueue is flushed', async () => { - mParticle._resetForTests(MPConfig); - await waitForCondition(hasBeforeEachCallbackReturned); + mParticle._resetForTests(MPConfig); fetchMock.resetHistory(); @@ -2964,6 +2967,7 @@ describe.only('identity', function() { .should.have.property('attr', 'value'); }); + // https://go.mparticle.com/work/SDKE-420 it('identifyCallback response should have a getUser function on the result object', async () => { let result; loggerSpy = setupLoggerSpy(); @@ -4460,6 +4464,7 @@ describe.only('identity', function() { } as unknown as IRoktKit; }); + // https://go.mparticle.com/work/SDKE-420 it('should set currentUser once the email is positively identified', async () => { loggerSpy = setupLoggerSpy(); fetchMockSuccess(urls.identify, { @@ -4472,7 +4477,7 @@ describe.only('identity', function() { mParticle.init(apiKey, { ...window.mParticle.config, kitConfigs: [roktConfig] }); - await waitForCondition(() => hasIdentifyReturned(testRoktMPID)); + await waitForCondition(hasIdentityResponseParsed(loggerSpy)); const mpInstance = mParticle.getInstance(); From 088aa6ca52f7879e0b03e44bb2a0c6151fbaf1e2 Mon Sep 17 00:00:00 2001 From: Jaissica Date: Tue, 28 Oct 2025 16:23:12 -0400 Subject: [PATCH 32/40] test: updated test message content --- test/src/tests-identity.ts | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/test/src/tests-identity.ts b/test/src/tests-identity.ts index a97ebb959..a2493d627 100644 --- a/test/src/tests-identity.ts +++ b/test/src/tests-identity.ts @@ -865,8 +865,7 @@ describe.only('identity', function() { }); // https://go.mparticle.com/work/SDKE-420 - it('cookies - should switch user cookies to new mpid details from cookies when a new mpid is provided', async () => { - loggerSpy = setupLoggerSpy(); + it('should switch user cookies to new mpid details from cookies when a new mpid is provided', async () => { mParticle.config.useCookieStorage = true; setLocalStorage(); @@ -908,7 +907,7 @@ describe.only('identity', function() { mParticle.Identity.login(userIdentities1); - await waitForCondition(hasIdentityResponseParsed(loggerSpy)); + await waitForCondition(hasLoginReturned); const cookiesAfterMPIDChange = findCookie(); cookiesAfterMPIDChange.should.have.properties([ From 6dea100ce20705ba0006ad030b2733e294b1b000 Mon Sep 17 00:00:00 2001 From: Robert Ing Date: Tue, 28 Oct 2025 16:17:15 -0400 Subject: [PATCH 33/40] fix test for queue events when MPID is 0 --- test/src/tests-identity.ts | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/test/src/tests-identity.ts b/test/src/tests-identity.ts index a2493d627..14d18f9ce 100644 --- a/test/src/tests-identity.ts +++ b/test/src/tests-identity.ts @@ -1763,11 +1763,14 @@ describe.only('identity', function() { spy.calledOnce.should.be.ok(); }); - // https://go.mparticle.com/work/SDKE-420 it('queue events when MPID is 0, and then flush events once MPID changes', async () => { + await waitForCondition(hasIdentityCallInflightReturned); + mParticle._resetForTests(MPConfig); loggerSpy = setupLoggerSpy(); + fetchMock.resetHistory(); + // HTTP Bad Request results in an MPID of 0 fetchMock.post(urls.identify, { status: HTTP_BAD_REQUEST, body: { @@ -1793,15 +1796,12 @@ describe.only('identity', function() { const identifyCall = fetchMock.calls().find(call => call[0].includes('/identify')); expect(identifyCall).to.be.ok; - mParticle.logEvent('Test Event 1'); - // There should be 3 calls here: + // There should be 1 call here: // 1. Identify (from init) - // 2. AST - // 3. Session start - // The event should not be sent because the MPID is 0 - expect(fetchMock.calls().length).to.equal(3); + // AST, session start, and logEvent are all queued since MPID is 0 + expect(fetchMock.calls().length).to.equal(1); let testEvent1 = findEventFromRequest( fetchMock.calls(), @@ -1818,16 +1818,18 @@ describe.only('identity', function() { mParticle.logEvent('Test Event 2'); loggerSpy.verbose.resetHistory(); mParticle.Identity.login(); + await waitForCondition(hasIdentityResponseParsed(loggerSpy)); // server requests will now have the following events: - // 1. Identify (from init) - // 2. AST - // 3. Session start - // 4. Test1, - // 5. Login + // 1. Identify + // 2. Login + // 3. AST + // 4. Session start + // 5. Test1, // 6. Test2 expect(fetchMock.calls().length).to.equal(6); + fetchMock.calls().forEach(call => console.log('call', call[0])) testEvent1 = findEventFromRequest( fetchMock.calls(), @@ -1849,7 +1851,7 @@ describe.only('identity', function() { 'session_start' ); - const loginCall = fetchMock.calls()[3]; + const loginCall = fetchMock.calls()[1]; expect(testEvent1).to.be.ok; expect(testEvent2).to.be.ok; From acfaa826d04b97b1be771d0558effade8bea528d Mon Sep 17 00:00:00 2001 From: Jaissica Date: Tue, 28 Oct 2025 17:01:20 -0400 Subject: [PATCH 34/40] test: updated identity localStorage flaky test --- test/src/tests-identity.ts | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/src/tests-identity.ts b/test/src/tests-identity.ts index 14d18f9ce..9e36c6beb 100644 --- a/test/src/tests-identity.ts +++ b/test/src/tests-identity.ts @@ -803,13 +803,14 @@ describe.only('identity', function() { }); it('localStorage - should switch user cookies to new mpid details from cookies when a new mpid is provided', async () => { - loggerSpy = setupLoggerSpy(); window.mParticle.config.useCookieStorage = false; setLocalStorage(); mParticle.init(apiKey, window.mParticle.config); + await waitForCondition(hasIdentifyReturned); + const cookies1 = mParticle.getInstance()._Persistence.getLocalStorage(); cookies1.cu.should.equal(testMPID); cookies1[testMPID].should.have.property('csd'); @@ -826,7 +827,9 @@ describe.only('identity', function() { }; mParticle.Identity.login(userIdentities1); - await waitForCondition(hasIdentityResponseParsed(loggerSpy)); + + await waitForCondition(hasLoginReturned); + const cookiesAfterMPIDChange = mParticle .getInstance() ._Persistence.getLocalStorage(); From e4ee4e5780eb0bac27665955f4e72ba10f929aea Mon Sep 17 00:00:00 2001 From: Robert Ing Date: Wed, 29 Oct 2025 22:28:35 -0400 Subject: [PATCH 35/40] fix additional tests by adding waitForCondition and resetForTests at the top of each test --- test/src/tests-identity.ts | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/test/src/tests-identity.ts b/test/src/tests-identity.ts index 9e36c6beb..a5d3cf8d5 100644 --- a/test/src/tests-identity.ts +++ b/test/src/tests-identity.ts @@ -149,7 +149,6 @@ describe.only('identity', function() { }; hasBeforeEachCallbackReturned = () => beforeEachCallbackCalled; - }); afterEach(function () { @@ -803,6 +802,8 @@ describe.only('identity', function() { }); it('localStorage - should switch user cookies to new mpid details from cookies when a new mpid is provided', async () => { + await waitForCondition(hasIdentityCallInflightReturned); + mParticle._resetForTests(MPConfig); window.mParticle.config.useCookieStorage = false; setLocalStorage(); @@ -867,8 +868,9 @@ describe.only('identity', function() { }); }); - // https://go.mparticle.com/work/SDKE-420 it('should switch user cookies to new mpid details from cookies when a new mpid is provided', async () => { + await waitForCondition(hasIdentityCallInflightReturned); + mParticle._resetForTests(MPConfig); mParticle.config.useCookieStorage = true; setLocalStorage(); @@ -2066,8 +2068,9 @@ describe.only('identity', function() { expect(Object.keys(combinedUIsByType).length).to.equal(4); }); - // https://go.mparticle.com/work/SDKE-420 it("should find the related MPID's cookies when given a UI with fewer IDs when passed to login, logout, and identify, and then log events with updated cookies", async () => { + await waitForCondition(hasIdentityCallInflightReturned); + mParticle._resetForTests(MPConfig); loggerSpy = setupLoggerSpy(); fetchMock.restore(); const user1: IdentityApiData = { @@ -2196,8 +2199,9 @@ describe.only('identity', function() { }); }); - // https://go.mparticle.com/work/SDKE-420 - it('should add new MPIDs to cookie structure when initializing new identity requests, returning an existing mpid when reinitializing with a previous identity', async () => { + it('should add new MPIDs to cookie structure when initializing new with a previous identity', async () => { + await waitForCondition(hasIdentityCallInflightReturned); + mParticle._resetForTests(MPConfig); loggerSpy = setupLoggerSpy(); const user1 = { userIdentities: { @@ -2971,8 +2975,9 @@ describe.only('identity', function() { .should.have.property('attr', 'value'); }); - // https://go.mparticle.com/work/SDKE-420 it('identifyCallback response should have a getUser function on the result object', async () => { + await waitForCondition(hasIdentityCallInflightReturned); + mParticle._resetForTests(MPConfig); let result; loggerSpy = setupLoggerSpy(); fetchMockSuccess(urls.identify, { @@ -3121,6 +3126,8 @@ describe.only('identity', function() { }); it('should have a getUser function on modify result object', async () => { + await waitForCondition(hasIdentityCallInflightReturned); + mParticle._resetForTests(MPConfig); loggerSpy = setupLoggerSpy(); let result let modifyResult; @@ -3166,8 +3173,9 @@ describe.only('identity', function() { }); }); - // https://go.mparticle.com/work/SDKE-420 it('should call identify when there is an active session but no current user', async () => { + await waitForCondition(hasIdentityCallInflightReturned); + mParticle._resetForTests(MPConfig); loggerSpy = setupLoggerSpy(); // this broken cookie state occurs when an initial identify request is made, fails, and the // client had no programmatic handling of a failed identify request @@ -4470,6 +4478,8 @@ describe.only('identity', function() { // https://go.mparticle.com/work/SDKE-420 it('should set currentUser once the email is positively identified', async () => { + await waitForCondition(hasIdentityCallInflightReturned); + mParticle._resetForTests(MPConfig); loggerSpy = setupLoggerSpy(); fetchMockSuccess(urls.identify, { mpid: testRoktMPID, From 11bf973eecf895b80101258d097027320a6b2dab Mon Sep 17 00:00:00 2001 From: Robert Ing Date: Wed, 29 Oct 2025 22:36:59 -0400 Subject: [PATCH 36/40] remove jira ticket --- test/src/tests-identity.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/test/src/tests-identity.ts b/test/src/tests-identity.ts index a5d3cf8d5..4918c3406 100644 --- a/test/src/tests-identity.ts +++ b/test/src/tests-identity.ts @@ -4476,7 +4476,6 @@ describe.only('identity', function() { } as unknown as IRoktKit; }); - // https://go.mparticle.com/work/SDKE-420 it('should set currentUser once the email is positively identified', async () => { await waitForCondition(hasIdentityCallInflightReturned); mParticle._resetForTests(MPConfig); From 9952a4d1f8b8674ca750f3b6b0bfc6b6ac8ff090 Mon Sep 17 00:00:00 2001 From: Jaissica Date: Thu, 30 Oct 2025 09:57:24 -0400 Subject: [PATCH 37/40] fix consent change test by adding waitForCondition and resetForTests --- test/src/tests-identity.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/src/tests-identity.ts b/test/src/tests-identity.ts index 4918c3406..fb646214d 100644 --- a/test/src/tests-identity.ts +++ b/test/src/tests-identity.ts @@ -675,6 +675,8 @@ describe.only('identity', function() { // https://go.mparticle.com/work/SQDSDKS-6849 // This test passes with no issue when it is run on its own, but fails when tests-forwarders.js are also ran. it('should respect consent rules on consent-change', async () => { + await waitForCondition(hasIdentityCallInflightReturned); + mParticle._resetForTests(MPConfig); loggerSpy = setupLoggerSpy(); mParticle.config.isDevelopmentMode = false; const mockForwarder = new MockForwarder('MockForwarder1'); From c6fdcebf73573b4ef7e1579fa9c2720a5c8e073b Mon Sep 17 00:00:00 2001 From: Jaissica Date: Thu, 30 Oct 2025 10:03:17 -0400 Subject: [PATCH 38/40] revert karma config changes --- test/karma.config.js | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/test/karma.config.js b/test/karma.config.js index d1a2b4fe7..d4557b507 100644 --- a/test/karma.config.js +++ b/test/karma.config.js @@ -41,22 +41,16 @@ module.exports = function(config) { singleRun, debug: true, logLevel: config.LOG_INFO, - browserConsoleLogOptions, - browserDisconnectTimeout: 10000, - browserDisconnectTolerance: 1, - captureTimeout: 120000, - processKillTimeout: 100000, client: { captureConsole, mocha: { - timeout: 10000 // 10 seconds. Increase from default 2 seconds. + timeout: 5000 // 5 seconds. Increase from default 2 seconds. } }, customLaunchers: { FirefoxHeadless: { base: 'Firefox', flags: ['-headless'], - browserNoActivityTimeout: 60000, }, }, junitReporter: { From 3ad0a46ba2764f1b59d299b601439c44d5910e14 Mon Sep 17 00:00:00 2001 From: Jaissica Date: Thu, 30 Oct 2025 10:08:16 -0400 Subject: [PATCH 39/40] added browserConsoleLogOptions to karma config --- test/karma.config.js | 1 + 1 file changed, 1 insertion(+) diff --git a/test/karma.config.js b/test/karma.config.js index d4557b507..25347ef04 100644 --- a/test/karma.config.js +++ b/test/karma.config.js @@ -41,6 +41,7 @@ module.exports = function(config) { singleRun, debug: true, logLevel: config.LOG_INFO, + browserConsoleLogOptions, client: { captureConsole, mocha: { From 13c3454207cee966a387c73fe8932ee9775cbfe0 Mon Sep 17 00:00:00 2001 From: Jaissica Date: Thu, 30 Oct 2025 11:43:27 -0400 Subject: [PATCH 40/40] remove comment and jira ticket for consent rules test --- test/src/tests-identity.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/src/tests-identity.ts b/test/src/tests-identity.ts index fb646214d..429c174da 100644 --- a/test/src/tests-identity.ts +++ b/test/src/tests-identity.ts @@ -672,8 +672,6 @@ describe.only('identity', function() { }); }); - // https://go.mparticle.com/work/SQDSDKS-6849 - // This test passes with no issue when it is run on its own, but fails when tests-forwarders.js are also ran. it('should respect consent rules on consent-change', async () => { await waitForCondition(hasIdentityCallInflightReturned); mParticle._resetForTests(MPConfig);