@@ -337,6 +337,129 @@ describe('Testing Rating plugin', function() {
337
337
} ) ;
338
338
} ) ;
339
339
340
+ var check_if_merges_finished = function ( tries , done ) {
341
+ if ( tries == 3 ) {
342
+ done ( ) ;
343
+ }
344
+ else {
345
+ testUtils . db . collection ( "app_user_merges" ) . find ( { "_id" : { "$regex" : "^" + APP_ID } } ) . toArray ( function ( err , res ) {
346
+ if ( res && res . length > 0 ) {
347
+ console . log ( JSON . stringify ( res ) ) ;
348
+ setTimeout ( function ( ) {
349
+ check_if_merges_finished ( tries + 1 , done ) ;
350
+ } , 10000 ) ;
351
+ }
352
+ else {
353
+ done ( ) ;
354
+ }
355
+ } ) ;
356
+ }
357
+ } ;
358
+
359
+ describe ( 'Test user merging' , function ( ) {
360
+ it ( 'Send in some user' , function ( done ) {
361
+ var events = [ {
362
+ "key" : "[CLY]_star_rating" ,
363
+ "count" : 1 ,
364
+ "timestamp" : 1419432000000 ,
365
+ "hour" : 10 ,
366
+ "dow" : 2 ,
367
+ "segmentation" : {
368
+ "contactMe" : true ,
369
+
370
+ "comment" : "It's a old comment." ,
371
+ "rating" : 5 ,
372
+ "app_version" : "5.5" ,
373
+ "platform" : "iOS" ,
374
+ "widget_id" : WIDGET_ID
375
+ }
376
+ } ] ;
377
+
378
+ request . get ( '/i/feedback/input?app_key=' + APP_KEY + '&device_id=' + 'OLD' + "&events=" + JSON . stringify ( events ) )
379
+ . expect ( 200 )
380
+ . end ( function ( err , res ) {
381
+ if ( err ) {
382
+ return done ( err ) ;
383
+ }
384
+ var ob = JSON . parse ( res . text ) ;
385
+ ob . should . have . property ( 'result' , 'Success' ) ;
386
+ setTimeout ( done , 100 * testUtils . testScalingFactor ) ;
387
+ } ) ;
388
+ } ) ;
389
+
390
+ it ( 'Send in some other user' , function ( done ) {
391
+ var events = [ {
392
+ "key" : "[CLY]_star_rating" ,
393
+ "count" : 1 ,
394
+ "timestamp" : 1419432000000 ,
395
+ "hour" : 10 ,
396
+ "dow" : 2 ,
397
+ "segmentation" : {
398
+ "contactMe" : true ,
399
+
400
+ "comment" : "It's a test comment." ,
401
+ "rating" : 5 ,
402
+ "app_version" : "5.5" ,
403
+ "platform" : "iOS" ,
404
+ "widget_id" : WIDGET_ID
405
+ }
406
+ } ] ;
407
+
408
+ request . get ( '/i/feedback/input?app_key=' + APP_KEY + '&device_id=' + 'NEW' + "&events=" + JSON . stringify ( events ) )
409
+ . expect ( 200 )
410
+ . end ( function ( err , res ) {
411
+ if ( err ) {
412
+ return done ( err ) ;
413
+ }
414
+ var ob = JSON . parse ( res . text ) ;
415
+ ob . should . have . property ( 'result' , 'Success' ) ;
416
+ setTimeout ( done , 100 * testUtils . testScalingFactor ) ;
417
+ } ) ;
418
+ } ) ;
419
+
420
+ it ( 'Merge users' , function ( done ) {
421
+ request
422
+ . get ( '/i?device_id=NEW&old_device_id=OLD&app_key=' + APP_KEY )
423
+ . expect ( 200 )
424
+ . end ( function ( err , res ) {
425
+ if ( err ) {
426
+ return done ( err ) ;
427
+ }
428
+ var ob = JSON . parse ( res . text ) ;
429
+ ob . should . have . property ( 'result' , 'Success' ) ;
430
+ setTimeout ( done , 100 * testUtils . testScalingFactor ) ;
431
+ } ) ;
432
+ } ) ;
433
+ it ( 'making sure merge is finished' , function ( done ) {
434
+ check_if_merges_finished ( 0 , done ) ;
435
+ } ) ;
436
+ it ( 'Validate in docs are correct in database' , function ( done ) {
437
+ testUtils . db . collection ( "app_users" + APP_ID ) . findOne ( { "did" : "NEW" } , function ( err , res ) {
438
+ if ( err ) {
439
+ done ( "user not found" ) ;
440
+ }
441
+ else {
442
+ var uid = res . uid ;
443
+ testUtils . db . collection ( "feedback" + APP_ID ) . find ( { "uid" : uid } ) . toArray ( function ( err , res ) {
444
+ if ( err ) {
445
+ done ( err ) ;
446
+ }
447
+ else {
448
+ if ( res && res . length === 2 ) {
449
+ done ( ) ;
450
+ }
451
+ else {
452
+ console . log ( JSON . stringify ( res ) ) ;
453
+ done ( "feedback collection not properly merged. Expected 2 records." ) ;
454
+ }
455
+ }
456
+ } ) ;
457
+ }
458
+ } ) ;
459
+ } ) ;
460
+
461
+
462
+ } ) ;
340
463
describe ( 'Reset app' , function ( ) {
341
464
it ( 'should reset data' , function ( done ) {
342
465
var params = {
0 commit comments