@@ -2739,23 +2739,54 @@ describe('AmplitudeClient', function () {
27392739 } ) ;
27402740 } ) ;
27412741
2742- it ( 'should not create any cookies if disabledCookies = true' , function ( ) {
2742+ it ( 'should not use any cookies with simple host if disabledCookies = true' , function ( ) {
27432743 deleteAllCookies ( ) ;
27442744 clock . tick ( 20 ) ;
27452745
27462746 var cookieArray = getAllCookies ( ) ;
27472747 assert . equal ( cookieArray . length , 0 ) ;
27482748
27492749 var deviceId = 'test_device_id' ;
2750- var amplitude2 = new AmplitudeClient ( ) ;
2750+ var amplitude = new AmplitudeClient ( ) ;
27512751
2752- amplitude2 . init ( apiKey , null , {
2752+ amplitude . init ( apiKey , null , {
2753+ deviceId : deviceId ,
2754+ disableCookies : true ,
2755+ } ) ;
2756+
2757+ cookieArray = getAllCookies ( ) ;
2758+ assert . equal ( cookieArray . length , 0 ) ;
2759+ } ) ;
2760+
2761+ it ( 'should not use any cookies with multiple domains in host if disabledCookies = true' , function ( ) {
2762+ const stubbedGetLocation = sinon . stub ( utils , 'getLocation' ) . returns ( { href : 'https://abc.def.xyz/test' } ) ;
2763+ const spiedSet = sinon . spy ( baseCookie , 'set' ) ;
2764+ const spiedGet = sinon . spy ( baseCookie , 'get' ) ;
2765+ deleteAllCookies ( ) ;
2766+ clock . tick ( 20 ) ;
2767+
2768+ var cookieArray = getAllCookies ( ) ;
2769+ assert . equal ( cookieArray . length , 0 ) ;
2770+
2771+ var deviceId = 'test_device_id' ;
2772+ var amplitude = new AmplitudeClient ( ) ;
2773+
2774+ amplitude . init ( apiKey , null , {
27532775 deviceId : deviceId ,
27542776 disableCookies : true ,
27552777 } ) ;
27562778
27572779 cookieArray = getAllCookies ( ) ;
27582780 assert . equal ( cookieArray . length , 0 ) ;
2781+
2782+ // spied cookie operations should not be fired
2783+ assert . equal ( spiedSet . called , false ) ;
2784+ assert . equal ( spiedGet . called , false ) ;
2785+
2786+ // restore stub, spy
2787+ stubbedGetLocation . restore ( ) ;
2788+ spiedSet . restore ( ) ;
2789+ spiedGet . restore ( ) ;
27592790 } ) ;
27602791
27612792 it ( 'should create cookies if disabledCookies = false' , function ( ) {
@@ -2766,9 +2797,9 @@ describe('AmplitudeClient', function () {
27662797 assert . equal ( cookieArray . length , 0 ) ;
27672798
27682799 var deviceId = 'test_device_id' ;
2769- var amplitude2 = new AmplitudeClient ( ) ;
2800+ var amplitude = new AmplitudeClient ( ) ;
27702801
2771- amplitude2 . init ( apiKey , null , {
2802+ amplitude . init ( apiKey , null , {
27722803 deviceId : deviceId ,
27732804 disableCookies : false ,
27742805 } ) ;
0 commit comments