@@ -31,6 +31,7 @@ describe('ConstructorIO - Utils - Request Queue', function utilsRequestQueue() {
31
31
this . timeout ( 3000 ) ;
32
32
33
33
const storageKey = '_constructorio_requests' ;
34
+ const humanityStorageKey = '_constructorio_is_human' ;
34
35
const waitInterval = 2000 ;
35
36
let requestQueueOptions = { } ;
36
37
const piiExamples = [
@@ -179,7 +180,8 @@ describe('ConstructorIO - Utils - Request Queue', function utilsRequestQueue() {
179
180
helpers . clearStorage ( ) ;
180
181
} ) ;
181
182
182
- it ( 'Should add url requests to the queue' , ( ) => {
183
+ it ( 'Should add url requests to the queue if the user is human' , async ( ) => {
184
+ store . session . set ( humanityStorageKey , true ) ;
183
185
const requests = new RequestQueue ( requestQueueOptions ) ;
184
186
185
187
requests . queue ( 'https://ac.cnstrc.com/behavior?action=session_start' ) ;
@@ -191,7 +193,8 @@ describe('ConstructorIO - Utils - Request Queue', function utilsRequestQueue() {
191
193
expect ( store . local . get ( storageKey ) ) . to . be . an ( 'array' ) . length ( 3 ) ;
192
194
} ) ;
193
195
194
- it ( 'Should add object requests to the queue - POST with body' , ( ) => {
196
+ it ( 'Should add object requests to the queue - POST with body if the user is human' , ( ) => {
197
+ store . session . set ( humanityStorageKey , true ) ;
195
198
const requests = new RequestQueue ( requestQueueOptions ) ;
196
199
197
200
requests . queue ( 'https://ac.cnstrc.com/behavior' , 'POST' , { action : 'session_start' } ) ;
@@ -218,6 +221,7 @@ describe('ConstructorIO - Utils - Request Queue', function utilsRequestQueue() {
218
221
} ) ;
219
222
220
223
it ( 'Should obfuscate requests if PII is detected' , ( ) => {
224
+ store . session . set ( humanityStorageKey , true ) ; // Enabled for the test to run
221
225
const requests = new RequestQueue ( requestQueueOptions ) ;
222
226
const allExamples = [ ] ;
223
227
@@ -252,6 +256,7 @@ describe('ConstructorIO - Utils - Request Queue', function utilsRequestQueue() {
252
256
} ) ;
253
257
254
258
it ( 'Should not obfuscate requests if no PII is detected' , ( ) => {
259
+ store . session . set ( humanityStorageKey , true ) ; // Enabled for the test to run
255
260
const requests = new RequestQueue ( requestQueueOptions ) ;
256
261
257
262
notPiiExamples . forEach ( ( query ) => {
@@ -343,12 +348,13 @@ describe('ConstructorIO - Utils - Request Queue', function utilsRequestQueue() {
343
348
it ( 'Should send all url tracking requests if queue is populated and user is human' , ( done ) => {
344
349
const requests = new RequestQueue ( requestQueueOptions ) ;
345
350
351
+ helpers . triggerResize ( ) ; // Human-like action
352
+
346
353
requests . queue ( 'https://ac.cnstrc.com/behavior?action=session_start' ) ;
347
354
requests . queue ( 'https://ac.cnstrc.com/behavior?action=focus' ) ;
348
355
requests . queue ( 'https://ac.cnstrc.com/behavior?action=magic_number_three' ) ;
349
356
350
357
expect ( RequestQueue . get ( ) ) . to . be . an ( 'array' ) . length ( 3 ) ;
351
- helpers . triggerResize ( ) ;
352
358
requests . send ( ) ;
353
359
354
360
setTimeout ( ( ) => {
@@ -359,6 +365,7 @@ describe('ConstructorIO - Utils - Request Queue', function utilsRequestQueue() {
359
365
} ) ;
360
366
361
367
it ( 'Should send all object tracking requests if queue is populated and user is human - POST with body' , ( done ) => {
368
+ store . session . set ( humanityStorageKey , true ) ;
362
369
const requests = new RequestQueue ( requestQueueOptions ) ;
363
370
364
371
requests . queue ( 'https://ac.cnstrc.com/behavior' , 'POST' , { action : 'session_start' } ) ;
@@ -376,14 +383,26 @@ describe('ConstructorIO - Utils - Request Queue', function utilsRequestQueue() {
376
383
} , waitInterval ) ;
377
384
} ) ;
378
385
379
- it ( 'Should not send tracking requests if queue is populated and user is not human' , ( done ) => {
386
+ it ( 'Should not send tracking requests if queue was populated and user is not human' , ( done ) => {
380
387
const requests = new RequestQueue ( requestQueueOptions ) ;
381
388
382
- requests . queue ( 'https://ac.cnstrc.com/behavior?action=session_start' ) ;
383
- requests . queue ( 'https://ac.cnstrc.com/behavior?action=focus' ) ;
384
- requests . queue ( 'https://ac.cnstrc.com/behavior?action=magic_number_three' ) ;
389
+ store . local . set ( storageKey , [
390
+ {
391
+ url : 'https://ac.cnstrc.com/behavior?action=session_start' ,
392
+ method : 'GET' ,
393
+ } ,
394
+ {
395
+ url : 'https://ac.cnstrc.com/behavior?action=focus' ,
396
+ method : 'GET' ,
397
+ } ,
398
+ {
399
+ url : 'https://ac.cnstrc.com/behavior?action=magic_number_three' ,
400
+ method : 'GET' ,
401
+ } ,
402
+ ] ) ;
385
403
386
404
expect ( RequestQueue . get ( ) ) . to . be . an ( 'array' ) . length ( 3 ) ;
405
+
387
406
requests . send ( ) ;
388
407
389
408
setTimeout ( ( ) => {
@@ -395,9 +414,20 @@ describe('ConstructorIO - Utils - Request Queue', function utilsRequestQueue() {
395
414
it ( 'Should not send tracking requests if queue is populated and user is human and page is unloading' , ( done ) => {
396
415
const requests = new RequestQueue ( requestQueueOptions ) ;
397
416
398
- requests . queue ( 'https://ac.cnstrc.com/behavior?action=session_start' ) ;
399
- requests . queue ( 'https://ac.cnstrc.com/behavior?action=focus' ) ;
400
- requests . queue ( 'https://ac.cnstrc.com/behavior?action=magic_number_three' ) ;
417
+ store . local . set ( storageKey , [
418
+ {
419
+ url : 'https://ac.cnstrc.com/behavior?action=session_start' ,
420
+ method : 'GET' ,
421
+ } ,
422
+ {
423
+ url : 'https://ac.cnstrc.com/behavior?action=focus' ,
424
+ method : 'GET' ,
425
+ } ,
426
+ {
427
+ url : 'https://ac.cnstrc.com/behavior?action=magic_number_three' ,
428
+ method : 'GET' ,
429
+ } ,
430
+ ] ) ;
401
431
402
432
expect ( RequestQueue . get ( ) ) . to . be . an ( 'array' ) . length ( 3 ) ;
403
433
helpers . triggerResize ( ) ;
@@ -413,9 +443,20 @@ describe('ConstructorIO - Utils - Request Queue', function utilsRequestQueue() {
413
443
it ( 'Should not send tracking requests if queue is populated and user is human and page is unloading and send was called before unload' , ( done ) => {
414
444
const requests = new RequestQueue ( requestQueueOptions ) ;
415
445
416
- requests . queue ( 'https://ac.cnstrc.com/behavior?action=session_start' ) ;
417
- requests . queue ( 'https://ac.cnstrc.com/behavior?action=focus' ) ;
418
- requests . queue ( 'https://ac.cnstrc.com/behavior?action=magic_number_three' ) ;
446
+ store . local . set ( storageKey , [
447
+ {
448
+ url : 'https://ac.cnstrc.com/behavior?action=session_start' ,
449
+ method : 'GET' ,
450
+ } ,
451
+ {
452
+ url : 'https://ac.cnstrc.com/behavior?action=focus' ,
453
+ method : 'GET' ,
454
+ } ,
455
+ {
456
+ url : 'https://ac.cnstrc.com/behavior?action=magic_number_three' ,
457
+ method : 'GET' ,
458
+ } ,
459
+ ] ) ;
419
460
420
461
expect ( RequestQueue . get ( ) ) . to . be . an ( 'array' ) . length ( 3 ) ;
421
462
helpers . triggerResize ( ) ;
@@ -728,11 +769,28 @@ describe('ConstructorIO - Utils - Request Queue', function utilsRequestQueue() {
728
769
const sendSpy1 = sinon . spy ( requests1 , 'send' ) ;
729
770
const sendSpy2 = sinon . spy ( requests2 , 'send' ) ;
730
771
731
- requests1 . queue ( 'https://ac.cnstrc.com/behavior' , 'POST' , { action : 'number_one' } ) ;
732
- requests1 . queue ( 'https://ac.cnstrc.com/behavior' , 'POST' , { action : 'number_two' } ) ;
733
- requests1 . queue ( 'https://ac.cnstrc.com/behavior' , 'POST' , { action : 'number_three' } ) ;
734
- requests1 . queue ( 'https://ac.cnstrc.com/behavior' , 'POST' , { action : 'number_four' } ) ;
735
- requests1 . queue ( 'https://ac.cnstrc.com/behavior' , 'POST' , { action : 'number_five' } ) ;
772
+ store . local . set ( storageKey , [
773
+ {
774
+ url : 'https://ac.cnstrc.com/behavior?action=session_start' ,
775
+ method : 'GET' ,
776
+ } ,
777
+ {
778
+ url : 'https://ac.cnstrc.com/behavior?action=focus' ,
779
+ method : 'GET' ,
780
+ } ,
781
+ {
782
+ url : 'https://ac.cnstrc.com/behavior?action=magic_number_three' ,
783
+ method : 'GET' ,
784
+ } ,
785
+ {
786
+ url : 'https://ac.cnstrc.com/behavior?action=magic_number_four' ,
787
+ method : 'GET' ,
788
+ } ,
789
+ {
790
+ url : 'https://ac.cnstrc.com/behavior?action=magic_number_five' ,
791
+ method : 'GET' ,
792
+ } ,
793
+ ] ) ;
736
794
737
795
helpers . triggerResize ( ) ;
738
796
requests1 . send ( ) ;
@@ -754,11 +812,28 @@ describe('ConstructorIO - Utils - Request Queue', function utilsRequestQueue() {
754
812
const sendSpy1 = sinon . spy ( requests1 , 'send' ) ;
755
813
const sendSpy2 = sinon . spy ( requests2 , 'send' ) ;
756
814
757
- requests1 . queue ( 'https://ac.cnstrc.com/behavior' , 'POST' , { action : 'number_one' } ) ;
758
- requests2 . queue ( 'https://ac.cnstrc.com/behavior' , 'POST' , { action : 'number_two' } ) ;
759
- requests1 . queue ( 'https://ac.cnstrc.com/behavior' , 'POST' , { action : 'number_three' } ) ;
760
- requests2 . queue ( 'https://ac.cnstrc.com/behavior' , 'POST' , { action : 'number_four' } ) ;
761
- requests1 . queue ( 'https://ac.cnstrc.com/behavior' , 'POST' , { action : 'number_five' } ) ;
815
+ store . local . set ( storageKey , [
816
+ {
817
+ url : 'https://ac.cnstrc.com/behavior?action=session_start' ,
818
+ method : 'GET' ,
819
+ } ,
820
+ {
821
+ url : 'https://ac.cnstrc.com/behavior?action=focus' ,
822
+ method : 'GET' ,
823
+ } ,
824
+ {
825
+ url : 'https://ac.cnstrc.com/behavior?action=magic_number_three' ,
826
+ method : 'GET' ,
827
+ } ,
828
+ {
829
+ url : 'https://ac.cnstrc.com/behavior?action=magic_number_four' ,
830
+ method : 'GET' ,
831
+ } ,
832
+ {
833
+ url : 'https://ac.cnstrc.com/behavior?action=magic_number_five' ,
834
+ method : 'GET' ,
835
+ } ,
836
+ ] ) ;
762
837
763
838
helpers . triggerResize ( ) ;
764
839
requests1 . send ( ) ;
0 commit comments