@@ -118,6 +118,7 @@ describe('Adagio Rtd Provider', function () {
118118 describe ( 'store session data in localStorage' , function ( ) {
119119 const session = {
120120 lastActivityTime : 1714116520700 ,
121+ id : 'uid-1234' ,
121122 rnd : 0.5697 ,
122123 vwSmplg : 0.1 ,
123124 vwSmplgNxt : 0.1
@@ -128,6 +129,7 @@ describe('Adagio Rtd Provider', function () {
128129 sandbox . stub ( storage , 'getDataFromLocalStorage' ) . callsArgWith ( 1 , storageValue ) ;
129130 sandbox . stub ( Date , 'now' ) . returns ( 1714116520710 ) ;
130131 sandbox . stub ( Math , 'random' ) . returns ( 0.8 ) ;
132+ sandbox . stub ( utils , 'generateUUID' ) . returns ( 'uid-1234' ) ;
131133
132134 const spy = sandbox . spy ( _internal . getAdagioNs ( ) . queue , 'push' )
133135
@@ -136,6 +138,7 @@ describe('Adagio Rtd Provider', function () {
136138 const expected = {
137139 session : {
138140 new : true ,
141+ id : utils . generateUUID ( ) ,
139142 rnd : Math . random ( )
140143 }
141144 }
@@ -176,6 +179,7 @@ describe('Adagio Rtd Provider', function () {
176179 sandbox . stub ( Date , 'now' ) . returns ( 1715679344351 ) ;
177180 sandbox . stub ( storage , 'getDataFromLocalStorage' ) . callsArgWith ( 1 , storageValue ) ;
178181 sandbox . stub ( Math , 'random' ) . returns ( 0.8 ) ;
182+ sandbox . stub ( utils , 'generateUUID' ) . returns ( 'uid-5678' ) ;
179183
180184 const spy = sandbox . spy ( _internal . getAdagioNs ( ) . queue , 'push' )
181185
@@ -185,6 +189,7 @@ describe('Adagio Rtd Provider', function () {
185189 session : {
186190 ...session ,
187191 new : true ,
192+ id : utils . generateUUID ( ) ,
188193 rnd : Math . random ( ) ,
189194 }
190195 }
@@ -196,6 +201,73 @@ describe('Adagio Rtd Provider', function () {
196201 } ) . calledOnce ) . to . be . true ;
197202 } ) ;
198203 } ) ;
204+
205+ describe ( 'store session data in localStorage when used with external AB Test snippet' , function ( ) {
206+ const sessionWithABTest = {
207+ lastActivityTime : 1714116520700 ,
208+ id : 'uid-1234' ,
209+ rnd : 0.5697 ,
210+ vwSmplg : 0.1 ,
211+ vwSmplgNxt : 0.1 ,
212+ testName : 'adg-test' ,
213+ testVersion : 'srv' ,
214+ initiator : 'snippet'
215+ } ;
216+
217+ it ( 'store new session data instancied by the AB Test snippet for further usage' , function ( ) {
218+ const sessionWithNewFlag = { ...sessionWithABTest , new : true } ;
219+ const storageValue = JSON . stringify ( { session : sessionWithNewFlag } ) ;
220+ sandbox . stub ( storage , 'getDataFromLocalStorage' ) . callsArgWith ( 1 , storageValue ) ;
221+ sandbox . stub ( Date , 'now' ) . returns ( 1714116520710 ) ;
222+ sandbox . stub ( Math , 'random' ) . returns ( 0.8 ) ;
223+
224+ const spy = sandbox . spy ( _internal . getAdagioNs ( ) . queue , 'push' )
225+
226+ adagioRtdSubmodule . init ( config ) ;
227+
228+ const expected = {
229+ session : {
230+ ...sessionWithNewFlag
231+ }
232+ }
233+
234+ expect ( spy . withArgs ( {
235+ action : 'session' ,
236+ ts : Date . now ( ) ,
237+ data : expected ,
238+ } ) . calledOnce ) . to . be . true ;
239+ } ) ;
240+
241+ it ( 'store new session data after removing AB Test props when initiator is not the snippet' , function ( ) {
242+ const sessionWithNewFlag = { ...sessionWithABTest , new : false , initiator : 'adgjs' } ;
243+ const storageValue = JSON . stringify ( { session : sessionWithNewFlag } ) ;
244+ sandbox . stub ( storage , 'getDataFromLocalStorage' ) . callsArgWith ( 1 , storageValue ) ;
245+ sandbox . stub ( Date , 'now' ) . returns ( 1714116520710 ) ;
246+ sandbox . stub ( Math , 'random' ) . returns ( 0.8 ) ;
247+ sandbox . stub ( utils , 'generateUUID' ) . returns ( 'uid-5678' ) ;
248+
249+ const spy = sandbox . spy ( _internal . getAdagioNs ( ) . queue , 'push' )
250+
251+ adagioRtdSubmodule . init ( config ) ;
252+
253+ const expected = {
254+ session : {
255+ ...sessionWithNewFlag ,
256+ new : true ,
257+ id : utils . generateUUID ( ) ,
258+ rnd : Math . random ( ) ,
259+ }
260+ }
261+ delete expected . session . testName ;
262+ delete expected . session . testVersion ;
263+
264+ expect ( spy . withArgs ( {
265+ action : 'session' ,
266+ ts : Date . now ( ) ,
267+ data : expected ,
268+ } ) . calledOnce ) . to . be . true ;
269+ } ) ;
270+ } ) ;
199271 } ) ;
200272
201273 describe ( 'submodule `getBidRequestData`' , function ( ) {
0 commit comments