@@ -2840,6 +2840,18 @@ describe('AmplitudeClient', function () {
2840
2840
} ) ;
2841
2841
} ) ;
2842
2842
2843
+ describe ( 'logEvent with outOfSession' , function ( ) {
2844
+ this . beforeEach ( function ( ) {
2845
+ reset ( ) ;
2846
+ } ) ;
2847
+
2848
+ it ( 'should reset the sessionId' , function ( ) {
2849
+ amplitude . init ( apiKey ) ;
2850
+ amplitude . logEvent ( 'Event Type' , null , null , null , true ) ;
2851
+ assert . equal ( amplitude . _sessionId , - 1 ) ;
2852
+ } ) ;
2853
+ } ) ;
2854
+
2843
2855
describe ( 'setEventUploadThreshold' , function ( ) {
2844
2856
beforeEach ( function ( ) {
2845
2857
reset ( ) ;
@@ -4387,4 +4399,53 @@ describe('AmplitudeClient', function () {
4387
4399
assert . equal ( amplitude . _unsentEvents . length , 0 ) ;
4388
4400
} ) ;
4389
4401
} ) ;
4402
+
4403
+ describe ( 'setUserId' , function ( ) {
4404
+ let clock , startTime ;
4405
+ beforeEach ( function ( ) {
4406
+ reset ( ) ;
4407
+ startTime = Date . now ( ) ;
4408
+ clock = sinon . useFakeTimers ( startTime ) ;
4409
+ amplitude . init ( apiKey ) ;
4410
+ } ) ;
4411
+
4412
+ it ( 'should not renew the session id with invalid startNewSession input' , function ( ) {
4413
+ var amplitude = new AmplitudeClient ( ) ;
4414
+ // set up initial session
4415
+ var sessionId = 1000 ;
4416
+ clock . tick ( sessionId ) ;
4417
+ amplitude . init ( apiKey ) ;
4418
+ assert . equal ( amplitude . getSessionId ( ) , startTime ) ;
4419
+
4420
+ amplitude . setUserId ( 'test user' , 'invalid startNewSession' ) ;
4421
+ assert . notEqual ( amplitude . getSessionId ( ) , new Date ( ) . getTime ( ) ) ;
4422
+ assert . notEqual ( amplitude . options . userId , 'test user' ) ;
4423
+ } ) ;
4424
+
4425
+ it ( 'should renew the session id with current timestemp' , function ( ) {
4426
+ var amplitude = new AmplitudeClient ( ) ;
4427
+ // set up initial session
4428
+ var sessionId = 1000 ;
4429
+ clock . tick ( sessionId ) ;
4430
+ amplitude . init ( apiKey ) ;
4431
+ assert . equal ( amplitude . getSessionId ( ) , startTime ) ;
4432
+
4433
+ amplitude . setUserId ( 'test user' , true ) ;
4434
+ assert . equal ( amplitude . getSessionId ( ) , new Date ( ) . getTime ( ) ) ;
4435
+ assert . equal ( amplitude . options . userId , 'test user' ) ;
4436
+ } ) ;
4437
+
4438
+ it ( 'should continue the old session' , function ( ) {
4439
+ var amplitude = new AmplitudeClient ( ) ;
4440
+ // set up initial session
4441
+ var sessionId = 1000 ;
4442
+ clock . tick ( sessionId ) ;
4443
+ amplitude . init ( apiKey ) ;
4444
+ assert . equal ( amplitude . getSessionId ( ) , startTime ) ;
4445
+
4446
+ amplitude . setUserId ( 'test user' ) ;
4447
+ assert . equal ( amplitude . getSessionId ( ) , startTime ) ;
4448
+ assert . equal ( amplitude . options . userId , 'test user' ) ;
4449
+ } ) ;
4450
+ } ) ;
4390
4451
} ) ;
0 commit comments