@@ -850,5 +850,81 @@ describe('ConstructorIO - Utils - Request Queue', function utilsRequestQueue() {
850
850
} ) ;
851
851
} ) ;
852
852
} ) ;
853
+
854
+ describe ( 'domless' , ( ) => {
855
+ let fetchSpy = null ;
856
+
857
+ before ( ( ) => {
858
+ helpers . clearStorage ( ) ;
859
+ } ) ;
860
+
861
+ beforeEach ( ( ) => {
862
+ global . CLIENT_VERSION = 'cio-mocha' ;
863
+ fetchSpy = sinon . spy ( fetch ) ;
864
+
865
+ requestQueueOptions = {
866
+ fetch : fetchSpy ,
867
+ sendTrackingEvents : true ,
868
+ trackingSendDelay : 1 ,
869
+ } ;
870
+ } ) ;
871
+
872
+ afterEach ( ( ) => {
873
+ requestQueueOptions = { } ;
874
+ helpers . clearStorage ( ) ;
875
+ } ) ;
876
+
877
+ it ( 'Should add url requests to the queue if the user is domless' , async ( ) => {
878
+ const requests = new RequestQueue ( requestQueueOptions ) ;
879
+
880
+ requests . queue ( 'https://ac.cnstrc.com/behavior?action=session_start' ) ;
881
+ requests . queue ( 'https://ac.cnstrc.com/behavior?action=focus' ) ;
882
+ requests . queue ( 'https://ac.cnstrc.com/behavior?action=magic_number_three' ) ;
883
+
884
+ expect ( RequestQueue . get ( ) ) . to . be . an ( 'array' ) . length ( 3 ) ;
885
+ } ) ;
886
+
887
+ it ( 'Should send requests from the queue if the user is domless' , ( done ) => {
888
+ const requests1 = new RequestQueue ( requestQueueOptions ) ;
889
+ const requests2 = new RequestQueue ( requestQueueOptions ) ;
890
+ const sendSpy1 = sinon . spy ( requests1 , 'send' ) ;
891
+ const sendSpy2 = sinon . spy ( requests2 , 'send' ) ;
892
+
893
+ store . local . set ( storageKey , [
894
+ {
895
+ url : 'https://ac.cnstrc.com/behavior?action=session_start' ,
896
+ method : 'GET' ,
897
+ } ,
898
+ {
899
+ url : 'https://ac.cnstrc.com/behavior?action=focus' ,
900
+ method : 'GET' ,
901
+ } ,
902
+ {
903
+ url : 'https://ac.cnstrc.com/behavior?action=magic_number_three' ,
904
+ method : 'GET' ,
905
+ } ,
906
+ {
907
+ url : 'https://ac.cnstrc.com/behavior?action=magic_number_four' ,
908
+ method : 'GET' ,
909
+ } ,
910
+ {
911
+ url : 'https://ac.cnstrc.com/behavior?action=magic_number_five' ,
912
+ method : 'GET' ,
913
+ } ,
914
+ ] ) ;
915
+
916
+ requests1 . send ( ) ;
917
+ requests2 . send ( ) ;
918
+
919
+ setTimeout ( ( ) => {
920
+ expect ( sendSpy1 . callCount ) . to . be . at . least ( 2 + 1 ) ; // 2 min sent + 1 finally
921
+ expect ( sendSpy2 . callCount ) . to . be . at . least ( 2 + 1 ) ; // 2 min sent + 1 finally
922
+ expect ( sendSpy1 . callCount + sendSpy2 . callCount ) . to . equal ( 5 + 2 ) ; // 5 sent + 2 finally
923
+ expect ( RequestQueue . get ( ) ) . to . be . an ( 'array' ) . length ( 0 ) ;
924
+ expect ( store . local . get ( storageKey ) ) . to . be . null ;
925
+ done ( ) ;
926
+ } , waitInterval ) ;
927
+ } ) ;
928
+ } ) ;
853
929
}
854
930
} ) ;
0 commit comments