From 7354cdf0d9981032991620346695a88e85b6c726 Mon Sep 17 00:00:00 2001 From: Alexander Sapountzis Date: Mon, 28 Oct 2024 09:56:08 -0500 Subject: [PATCH] Address PR Comments --- src/mp-instance.js | 4 ++-- src/pre-init-utils.ts | 2 -- test/jest/pre-init-utils.spec.ts | 13 +++++++++++++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/mp-instance.js b/src/mp-instance.js index 671b4e35..1736ce1d 100644 --- a/src/mp-instance.js +++ b/src/mp-instance.js @@ -1362,8 +1362,8 @@ function completeSDKInitialization(apiKey, config, mpInstance) { ); } - // If for some reason the identity call inside of Session Manager does not run - // we should clear out the ready queue. + // We will continue to clear out the ready queue as part of the initial init flow + // if an identify request is unnecessary, such as if there is an existing session if ( (mpInstance._Store.mpid && !mpInstance._Store.identifyCalled) || mpInstance._Store.webviewBridgeEnabled diff --git a/src/pre-init-utils.ts b/src/pre-init-utils.ts index 7b597ef3..05178088 100644 --- a/src/pre-init-utils.ts +++ b/src/pre-init-utils.ts @@ -4,10 +4,8 @@ export const processReadyQueue = (readyQueue): Function[] => { if (!isEmpty(readyQueue)) { readyQueue.forEach(readyQueueItem => { if (isFunction(readyQueueItem)) { - // debugger; readyQueueItem(); } else if (Array.isArray(readyQueueItem)) { - // debugger; processPreloadedItem(readyQueueItem); } }); diff --git a/test/jest/pre-init-utils.spec.ts b/test/jest/pre-init-utils.spec.ts index 1479981c..75255518 100644 --- a/test/jest/pre-init-utils.spec.ts +++ b/test/jest/pre-init-utils.spec.ts @@ -48,6 +48,19 @@ describe('pre-init-utils', () => { expect(functionSpy).toHaveBeenCalledWith('foo'); }); + it('should process arrays passed as arguments with multiple methods and arguments', () => { + const functionSpy = jest.fn(); + const functionSpy2 = jest.fn(); + (window.mParticle as any) = { + fakeFunction: functionSpy, + anotherFakeFunction: functionSpy2, + }; + const readyQueue = [['fakeFunction', 'foo'], ['anotherFakeFunction', 'bar']]; + processReadyQueue(readyQueue); + expect(functionSpy).toHaveBeenCalledWith('foo'); + expect(functionSpy2).toHaveBeenCalledWith('bar'); + }); + it('should throw an error if it cannot compute the proper mParticle function', () => { const readyQueue = [['Identity.login']]; expect(() => processReadyQueue(readyQueue)).toThrowError("Unable to compute proper mParticle function TypeError: Cannot read properties of undefined (reading 'login')");