Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Update Store to use mpid within getLastSeenTime method #878

Open
wants to merge 1 commit into
base: refactor/SQDSDKS-6400-consent-state-seen-times
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions src/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ export interface IStore {
integrationDelayTimeoutStart: number; // UNIX Timestamp
webviewBridgeEnabled?: boolean;
wrapperSDKInfo: WrapperSDKInfo;
mpid?: MPID;

persistenceData?: IPersistenceMinified;

Expand Down Expand Up @@ -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();
}
Expand Down
20 changes: 4 additions & 16 deletions test/src/tests-store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});
Expand Down Expand Up @@ -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);
Expand Down
Loading