@@ -9,6 +9,7 @@ import queryString from 'query-string';
99import Identify from '../src/identify.js' ;
1010import Revenue from '../src/revenue.js' ;
1111import constants from '../src/constants.js' ;
12+ import { mockCookie , restoreCookie , getCookie } from './mock-cookie' ;
1213
1314// maintain for testing backwards compatability
1415describe ( 'AmplitudeClient' , function ( ) {
@@ -34,6 +35,7 @@ describe('AmplitudeClient', function() {
3435 function reset ( ) {
3536 localStorage . clear ( ) ;
3637 sessionStorage . clear ( ) ;
38+ restoreCookie ( ) ;
3739 cookie . remove ( amplitude . options . cookieName ) ;
3840 cookie . remove ( amplitude . options . cookieName + keySuffix ) ;
3941 cookie . remove ( amplitude . options . cookieName + '_new_app' ) ;
@@ -74,6 +76,24 @@ describe('AmplitudeClient', function() {
7476 assert . ok ( onInitCalled ) ;
7577 } ) ;
7678
79+ it ( 'should set the Secure flag on cookie with the secureCookie option' , ( ) => {
80+ mockCookie ( ) ;
81+ amplitude . init ( apiKey , null , { secureCookie : true } ) ;
82+ assert . include ( getCookie ( 'amplitude_id_' + apiKey ) . options , 'Secure' ) ;
83+ } ) ;
84+
85+ it ( 'should set the SameSite cookie option to None by default' , ( ) => {
86+ mockCookie ( ) ;
87+ amplitude . init ( apiKey ) ;
88+ assert . include ( getCookie ( 'amplitude_id_' + apiKey ) . options , 'SameSite=None' ) ;
89+ } ) ;
90+
91+ it ( 'should set the sameSite option on a cookie with the sameSiteCookie Option' , ( ) => {
92+ mockCookie ( ) ;
93+ amplitude . init ( apiKey , null , { sameSiteCookie : 'Strict' } ) ;
94+ assert . include ( getCookie ( 'amplitude_id_' + apiKey ) . options , 'SameSite=Strict' ) ;
95+ } ) ;
96+
7797 it ( 'should immediately invoke onInit callbacks if already initialized' , function ( ) {
7898 let onInitCalled = false ;
7999 amplitude . init ( apiKey ) ;
@@ -3352,6 +3372,7 @@ describe('setVersionName', function() {
33523372 assert . lengthOf ( server . requests , 1 , 'should have sent a request to Amplitude' ) ;
33533373 assert . equal ( events [ 0 ] . event_type , '$identify' ) ;
33543374 } ) ;
3375+
33553376 describe ( 'prior to opting into analytics' , function ( ) {
33563377 beforeEach ( function ( ) {
33573378 reset ( ) ;
0 commit comments