From 12ac78956b8edfe150782985f58b83ed9ee65b78 Mon Sep 17 00:00:00 2001 From: Alex S <49695018+alexs-mparticle@users.noreply.github.com> Date: Wed, 20 Mar 2024 12:22:25 -0400 Subject: [PATCH] fix: Combine End Session Logging Messaging flow (#848) --- src/sessionManager.ts | 7 +------ test/src/tests-session-manager.ts | 21 ++++++++++----------- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/src/sessionManager.ts b/src/sessionManager.ts index cfb39579..90c770a3 100644 --- a/src/sessionManager.ts +++ b/src/sessionManager.ts @@ -149,12 +149,7 @@ export default function SessionManager( const cookies: IPersistenceMinified = mpInstance._Persistence.getPersistence(); - // TODO: https://go.mparticle.com/work/SQDSDKS-5684 - if (!cookies) { - return; - } - - if (cookies.gs && !cookies.gs.sid) { + if (!cookies || cookies.gs && !cookies.gs.sid) { mpInstance.Logger.verbose( Messages.InformationMessages.NoSessionToEnd ); diff --git a/test/src/tests-session-manager.ts b/test/src/tests-session-manager.ts index a1accf95..0e4b56ed 100644 --- a/test/src/tests-session-manager.ts +++ b/test/src/tests-session-manager.ts @@ -43,7 +43,7 @@ describe('SessionManager', () => { ]); }); - afterEach(function () { + afterEach(function() { sandbox.restore(); clock.restore(); mockServer.restore(); @@ -329,7 +329,7 @@ describe('SessionManager', () => { expect(persistenceSpy.called).to.equal(true); }); - it('should log StartingEndSession message and return early if Persistence is null', () => { + it('should log NoSessionToEnd Message and return if Persistence is null', () => { mParticle.init(apiKey, window.mParticle.config); const mpInstance = mParticle.getInstance(); @@ -341,18 +341,17 @@ describe('SessionManager', () => { mpInstance._SessionManager.endSession(); - // This path currently goes through the !cookies path, - // which doesn't really return anything except for logging the - // initial StartingEndSession message - expect(consoleSpy.getCall(0).firstArg).to.equal( + // Should log initial StartingEndSession and NoSessionToEnd messages + expect(consoleSpy.getCalls().length).to.equal(2); + expect(consoleSpy.firstCall.firstArg).to.equal( Messages.InformationMessages.StartingEndSession ); - - // Should only log a single verbose log - expect(consoleSpy.getCalls().length).to.equal(1); + expect(consoleSpy.lastCall.firstArg).to.equal( + Messages.InformationMessages.NoSessionToEnd + ); }); - it('should log a NoSessionToEnd Message if Persistence Exists but does not return an sid', () => { + it('should log a NoSessionToEnd Message if Persistence exists but does not return an sid', () => { mParticle.init(apiKey, window.mParticle.config); const mpInstance = mParticle.getInstance(); @@ -882,4 +881,4 @@ describe('SessionManager', () => { expect(persistenceSpy.called).to.equal(true); }); }); -}); \ No newline at end of file +});