@@ -31,6 +31,7 @@ describe('ConstructorIO - Utils - Request Queue', function utilsRequestQueue() {
3131 this . timeout ( 3000 ) ;
3232
3333 const storageKey = '_constructorio_requests' ;
34+ const humanityStorageKey = '_constructorio_is_human' ;
3435 const waitInterval = 2000 ;
3536 let requestQueueOptions = { } ;
3637 const piiExamples = [
@@ -179,7 +180,8 @@ describe('ConstructorIO - Utils - Request Queue', function utilsRequestQueue() {
179180 helpers . clearStorage ( ) ;
180181 } ) ;
181182
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 ) ;
183185 const requests = new RequestQueue ( requestQueueOptions ) ;
184186
185187 requests . queue ( 'https://ac.cnstrc.com/behavior?action=session_start' ) ;
@@ -191,7 +193,8 @@ describe('ConstructorIO - Utils - Request Queue', function utilsRequestQueue() {
191193 expect ( store . local . get ( storageKey ) ) . to . be . an ( 'array' ) . length ( 3 ) ;
192194 } ) ;
193195
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 ) ;
195198 const requests = new RequestQueue ( requestQueueOptions ) ;
196199
197200 requests . queue ( 'https://ac.cnstrc.com/behavior' , 'POST' , { action : 'session_start' } ) ;
@@ -218,6 +221,7 @@ describe('ConstructorIO - Utils - Request Queue', function utilsRequestQueue() {
218221 } ) ;
219222
220223 it ( 'Should obfuscate requests if PII is detected' , ( ) => {
224+ store . session . set ( humanityStorageKey , true ) ; // Enabled for the test to run
221225 const requests = new RequestQueue ( requestQueueOptions ) ;
222226 const allExamples = [ ] ;
223227
@@ -252,6 +256,7 @@ describe('ConstructorIO - Utils - Request Queue', function utilsRequestQueue() {
252256 } ) ;
253257
254258 it ( 'Should not obfuscate requests if no PII is detected' , ( ) => {
259+ store . session . set ( humanityStorageKey , true ) ; // Enabled for the test to run
255260 const requests = new RequestQueue ( requestQueueOptions ) ;
256261
257262 notPiiExamples . forEach ( ( query ) => {
@@ -343,12 +348,13 @@ describe('ConstructorIO - Utils - Request Queue', function utilsRequestQueue() {
343348 it ( 'Should send all url tracking requests if queue is populated and user is human' , ( done ) => {
344349 const requests = new RequestQueue ( requestQueueOptions ) ;
345350
351+ helpers . triggerResize ( ) ; // Human-like action
352+
346353 requests . queue ( 'https://ac.cnstrc.com/behavior?action=session_start' ) ;
347354 requests . queue ( 'https://ac.cnstrc.com/behavior?action=focus' ) ;
348355 requests . queue ( 'https://ac.cnstrc.com/behavior?action=magic_number_three' ) ;
349356
350357 expect ( RequestQueue . get ( ) ) . to . be . an ( 'array' ) . length ( 3 ) ;
351- helpers . triggerResize ( ) ;
352358 requests . send ( ) ;
353359
354360 setTimeout ( ( ) => {
@@ -359,6 +365,7 @@ describe('ConstructorIO - Utils - Request Queue', function utilsRequestQueue() {
359365 } ) ;
360366
361367 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 ) ;
362369 const requests = new RequestQueue ( requestQueueOptions ) ;
363370
364371 requests . queue ( 'https://ac.cnstrc.com/behavior' , 'POST' , { action : 'session_start' } ) ;
@@ -376,14 +383,26 @@ describe('ConstructorIO - Utils - Request Queue', function utilsRequestQueue() {
376383 } , waitInterval ) ;
377384 } ) ;
378385
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 ) => {
380387 const requests = new RequestQueue ( requestQueueOptions ) ;
381388
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+ ] ) ;
385403
386404 expect ( RequestQueue . get ( ) ) . to . be . an ( 'array' ) . length ( 3 ) ;
405+
387406 requests . send ( ) ;
388407
389408 setTimeout ( ( ) => {
@@ -395,9 +414,20 @@ describe('ConstructorIO - Utils - Request Queue', function utilsRequestQueue() {
395414 it ( 'Should not send tracking requests if queue is populated and user is human and page is unloading' , ( done ) => {
396415 const requests = new RequestQueue ( requestQueueOptions ) ;
397416
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+ ] ) ;
401431
402432 expect ( RequestQueue . get ( ) ) . to . be . an ( 'array' ) . length ( 3 ) ;
403433 helpers . triggerResize ( ) ;
@@ -413,9 +443,20 @@ describe('ConstructorIO - Utils - Request Queue', function utilsRequestQueue() {
413443 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 ) => {
414444 const requests = new RequestQueue ( requestQueueOptions ) ;
415445
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+ ] ) ;
419460
420461 expect ( RequestQueue . get ( ) ) . to . be . an ( 'array' ) . length ( 3 ) ;
421462 helpers . triggerResize ( ) ;
@@ -728,11 +769,28 @@ describe('ConstructorIO - Utils - Request Queue', function utilsRequestQueue() {
728769 const sendSpy1 = sinon . spy ( requests1 , 'send' ) ;
729770 const sendSpy2 = sinon . spy ( requests2 , 'send' ) ;
730771
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+ ] ) ;
736794
737795 helpers . triggerResize ( ) ;
738796 requests1 . send ( ) ;
@@ -754,11 +812,28 @@ describe('ConstructorIO - Utils - Request Queue', function utilsRequestQueue() {
754812 const sendSpy1 = sinon . spy ( requests1 , 'send' ) ;
755813 const sendSpy2 = sinon . spy ( requests2 , 'send' ) ;
756814
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+ ] ) ;
762837
763838 helpers . triggerResize ( ) ;
764839 requests1 . send ( ) ;
0 commit comments