Skip to content

Commit ddd4939

Browse files
author
Daniel Jih
committed
add tests
1 parent c7e90ab commit ddd4939

File tree

5 files changed

+23
-11
lines changed

5 files changed

+23
-11
lines changed

amplitude.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -568,9 +568,6 @@ AmplitudeClient.prototype.init = function init(apiKey, opt_userId, opt_config, o
568568
this.options.userId = (type(opt_userId) === 'string' && !utils.isEmptyString(opt_userId) && opt_userId) ||
569569
this.options.userId || null;
570570

571-
// if custom session id specified in config, override what is stored in cookie
572-
this._sessionId = this.options.sessionId > 0 ? this.options.sessionId : this._sessionId;
573-
574571
// load unsent events and identifies before any attempt to log new ones
575572
if (this.options.saveEvents) {
576573
this._unsentEvents = this._loadSavedUnsentEvents(this.options.unsentKey);
@@ -5021,7 +5018,6 @@ module.exports = {
50215018
includeGclid: false,
50225019
saveParamsReferrerOncePerSession: true,
50235020
deviceIdFromUrlParam: false,
5024-
sessionId: 0,
50255021
};
50265022

50275023
}, {"./language":29}],

amplitude.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/amplitude-client.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,6 @@ AmplitudeClient.prototype.init = function init(apiKey, opt_userId, opt_config, o
8787
this.options.userId = (type(opt_userId) === 'string' && !utils.isEmptyString(opt_userId) && opt_userId) ||
8888
this.options.userId || null;
8989

90-
// if custom session id specified in config, override what is stored in cookie
91-
this._sessionId = this.options.sessionId > 0 ? this.options.sessionId : this._sessionId;
92-
9390
// load unsent events and identifies before any attempt to log new ones
9491
if (this.options.saveEvents) {
9592
this._unsentEvents = this._loadSavedUnsentEvents(this.options.unsentKey);

src/options.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,4 @@ module.exports = {
2424
includeGclid: false,
2525
saveParamsReferrerOncePerSession: true,
2626
deviceIdFromUrlParam: false,
27-
sessionId: 0,
2827
};

test/amplitude-client.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2692,6 +2692,7 @@ describe('setVersionName', function() {
26922692
describe('sessionId', function() {
26932693
var clock;
26942694
beforeEach(function() {
2695+
reset();
26952696
clock = sinon.useFakeTimers();
26962697
amplitude.init(apiKey);
26972698
});
@@ -2722,5 +2723,24 @@ describe('setVersionName', function() {
27222723
assert.equal(amplitude2.getSessionId(), timestamp);
27232724
assert.equal(amplitude2.getSessionId(), amplitude2._sessionId);
27242725
});
2726+
2727+
it('should let user override sessionId with setSessionId', function() {
2728+
var amplitude2 = new AmplitudeClient();
2729+
var cookieStorage = new CookieStorage().getStorage();
2730+
2731+
// set up initial session
2732+
var sessionId = 1000;
2733+
clock.tick(sessionId);
2734+
amplitude2.init(apiKey);
2735+
assert.equal(amplitude2._sessionId, sessionId);
2736+
assert.equal(cookieStorage.get(amplitude2.options.cookieName).sessionId, sessionId);
2737+
2738+
// override sessionId with setSessionId
2739+
var newSessionId = 10000;
2740+
amplitude2.setSessionId(newSessionId);
2741+
assert.equal(amplitude2._sessionId, newSessionId);
2742+
// verify saved to cookie
2743+
assert.equal(cookieStorage.get(amplitude2.options.cookieName).sessionId, newSessionId);
2744+
});
27252745
});
27262746
});

0 commit comments

Comments
 (0)