Skip to content

Commit

Permalink
fix: Combine End Session Logging Messaging flow (#848)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexs-mparticle authored Mar 20, 2024
1 parent dd1920f commit 12ac789
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
7 changes: 1 addition & 6 deletions src/sessionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand Down
21 changes: 10 additions & 11 deletions test/src/tests-session-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('SessionManager', () => {
]);
});

afterEach(function () {
afterEach(function() {
sandbox.restore();
clock.restore();
mockServer.restore();
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -882,4 +881,4 @@ describe('SessionManager', () => {
expect(persistenceSpy.called).to.equal(true);
});
});
});
});

0 comments on commit 12ac789

Please sign in to comment.