From 0afe69fd82762b5bec4c8737687d40ab4da3167e Mon Sep 17 00:00:00 2001 From: Alexander Sapountzis Date: Fri, 26 Apr 2024 15:46:48 -0400 Subject: [PATCH] refactor: Update Store to use mpid for current user in getLastSeenTime method --- src/store.ts | 5 ++--- test/src/tests-store.ts | 20 ++++---------------- 2 files changed, 6 insertions(+), 19 deletions(-) diff --git a/src/store.ts b/src/store.ts index 5d3d7067..773c2af3 100644 --- a/src/store.ts +++ b/src/store.ts @@ -182,6 +182,7 @@ export interface IStore { integrationDelayTimeoutStart: number; // UNIX Timestamp webviewBridgeEnabled?: boolean; wrapperSDKInfo: WrapperSDKInfo; + mpid?: MPID; persistenceData?: IPersistenceMinified; @@ -628,9 +629,7 @@ export default function Store( if (!mpid) { return null; } - // https://go.mparticle.com/work/SQDSDKS-6315 - const currentUser = mpInstance.Identity.getCurrentUser(); - if (mpid === currentUser?.getMPID()) { + if (mpid === this.mpid) { // if the mpid is the current user, its last seen time is the current time return new Date().getTime(); } diff --git a/test/src/tests-store.ts b/test/src/tests-store.ts index 155d5abf..e814538a 100644 --- a/test/src/tests-store.ts +++ b/test/src/tests-store.ts @@ -1099,19 +1099,13 @@ describe('Store', () => { }); it('should return the current time if mpid matches current user', () => { - const userSpy = sinon.stub( - window.mParticle.getInstance().Identity, - 'getCurrentUser' - ); - userSpy.returns({ - getMPID: () => 'testMPID', - }); - const store: IStore = new Store( sampleConfig, window.mParticle.getInstance() ); + store.mpid = 'testMPID'; + clock.tick(100) expect(store.getLastSeenTime(testMPID)).to.equal(100); }); @@ -1169,19 +1163,13 @@ describe('Store', () => { }); it('returns current time for the current user as the lastSeenTime', () => { - const userSpy = sinon.stub( - window.mParticle.getInstance().Identity, - 'getCurrentUser' - ); - userSpy.returns({ - getMPID: () => 'testMPID', - }); - const store: IStore = new Store( sampleConfig, window.mParticle.getInstance() ); + store.mpid = 'testMPID'; + // Simulates current time clock.tick(100); store.setLastSeenTime(testMPID, 12345);