Skip to content

Commit

Permalink
Address PR Comments
Browse files Browse the repository at this point in the history
  • Loading branch information
alexs-mparticle committed Oct 28, 2024
1 parent 60ec32c commit 7354cdf
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/mp-instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions src/pre-init-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
});
Expand Down
13 changes: 13 additions & 0 deletions test/jest/pre-init-utils.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')");
Expand Down

0 comments on commit 7354cdf

Please sign in to comment.