@@ -241,10 +241,41 @@ describe('AmplitudeClient', function() {
241
241
assert . equal ( cookieData . sequenceNumber , 5000 ) ;
242
242
} ) ;
243
243
244
- it ( 'should migrate cookie data from old cookie name and ignore local storage values ' , function ( ) {
244
+ it ( 'should load device id from the cookie' , function ( ) {
245
245
var now = new Date ( ) . getTime ( ) ;
246
246
247
247
// deviceId and sequenceNumber not set, init should load value from localStorage
248
+ var cookieData = {
249
+ deviceId : 'current_device_id' ,
250
+ }
251
+
252
+ cookie . set ( amplitude . options . cookieName + '_' + apiKey , cookieData ) ;
253
+
254
+ amplitude . init ( apiKey ) ;
255
+ assert . equal ( amplitude . options . deviceId , 'current_device_id' ) ;
256
+ } ) ;
257
+
258
+ it ( 'should migrate device id from old non name spaced cookie name (pre 4.10)' , function ( ) {
259
+ var now = new Date ( ) . getTime ( ) ;
260
+
261
+ var cookieData = {
262
+ deviceId : 'old_device_id' ,
263
+ optOut : false ,
264
+ sessionId : now ,
265
+ lastEventTime : now ,
266
+ eventId : 50 ,
267
+ identifyId : 60
268
+ }
269
+
270
+ cookie . set ( amplitude . options . cookieName , cookieData ) ;
271
+
272
+ amplitude . init ( apiKey ) ;
273
+ assert . equal ( amplitude . options . deviceId , 'old_device_id' ) ;
274
+ } ) ;
275
+
276
+ it ( 'should migrate cookie data from old cookie name and ignore local storage values' , function ( ) {
277
+ var now = new Date ( ) . getTime ( ) ;
278
+
248
279
var cookieData = {
249
280
userId : 'test_user_id' ,
250
281
optOut : false ,
@@ -254,7 +285,7 @@ describe('AmplitudeClient', function() {
254
285
identifyId : 60
255
286
}
256
287
257
- cookie . set ( amplitude . options . cookieName + '_' + apiKey , cookieData ) ;
288
+ cookie . set ( amplitude . options . cookieName , cookieData ) ;
258
289
localStorage . setItem ( 'amplitude_deviceId' + keySuffix , 'old_device_id' ) ;
259
290
localStorage . setItem ( 'amplitude_userId' + keySuffix , 'fake_user_id' ) ;
260
291
localStorage . setItem ( 'amplitude_optOut' + keySuffix , true ) ;
@@ -278,7 +309,7 @@ describe('AmplitudeClient', function() {
278
309
it ( 'should skip the migration if the new cookie already has deviceId, sessionId, lastEventTime' , function ( ) {
279
310
var now = new Date ( ) . getTime ( ) ;
280
311
281
- cookie . set ( amplitude . options . cookieName + '_' + apiKey , {
312
+ cookie . set ( amplitude . options . cookieName , {
282
313
deviceId : 'new_device_id' ,
283
314
sessionId : now ,
284
315
lastEventTime : now
0 commit comments