1
1
# frozen_string_literal: true
2
2
3
3
#
4
- # Copyright 2016-2019 , Optimizely and contributors
4
+ # Copyright 2016-2020 , Optimizely and contributors
5
5
#
6
6
# Licensed under the Apache License, Version 2.0 (the "License");
7
7
# you may not use this file except in compliance with the License.
@@ -716,8 +716,18 @@ def callback(_args); end
716
716
end
717
717
718
718
describe '.Optimizely with config manager' do
719
+ before ( :example ) do
720
+ stub_request ( :post , impression_log_url )
721
+ stub_request ( :get , 'https://cdn.optimizely.com/datafiles/valid_sdk_key.json' )
722
+ . with (
723
+ headers : {
724
+ 'Content-Type' => 'application/json'
725
+ }
726
+ )
727
+ . to_return ( status : 200 , body : config_body_JSON , headers : { } )
728
+ end
729
+
719
730
it 'should update config, send update notification when url is provided' do
720
- WebMock . allow_net_connect!
721
731
notification_center = Optimizely ::NotificationCenter . new ( spy_logger , error_handler )
722
732
723
733
expect ( notification_center ) . to receive ( :send_notifications ) . with (
@@ -728,23 +738,22 @@ def callback(_args); end
728
738
729
739
expect ( notification_center ) . to receive ( :send_notifications ) . ordered
730
740
http_project_config_manager = Optimizely ::HTTPProjectConfigManager . new (
731
- url : 'https://cdn.optimizely.com/datafiles/QBw9gFM8oTn7ogY9ANCC1z .json' ,
741
+ url : 'https://cdn.optimizely.com/datafiles/valid_sdk_key .json' ,
732
742
notification_center : notification_center
733
743
)
734
744
735
745
project_instance = Optimizely ::Project . new (
736
- config_body_JSON , nil , spy_logger , error_handler ,
746
+ nil , nil , spy_logger , error_handler ,
737
747
false , nil , nil , http_project_config_manager , notification_center
738
748
)
739
749
740
750
until http_project_config_manager . ready? ; end
741
751
742
752
expect ( http_project_config_manager . config ) . not_to eq ( nil )
743
- expect ( project_instance . activate ( 'checkout_flow_experiment ' , 'test_user' ) ) . not_to eq ( nil )
753
+ expect ( project_instance . activate ( 'test_experiment ' , 'test_user' ) ) . not_to eq ( nil )
744
754
end
745
755
746
756
it 'should update config, send update notification when sdk key is provided' do
747
- WebMock . allow_net_connect!
748
757
notification_center = Optimizely ::NotificationCenter . new ( spy_logger , error_handler )
749
758
750
759
expect ( notification_center ) . to receive ( :send_notifications ) . with (
@@ -755,25 +764,34 @@ def callback(_args); end
755
764
expect ( notification_center ) . to receive ( :send_notifications ) . ordered
756
765
757
766
http_project_config_manager = Optimizely ::HTTPProjectConfigManager . new (
758
- sdk_key : 'QBw9gFM8oTn7ogY9ANCC1z ' ,
767
+ sdk_key : 'valid_sdk_key ' ,
759
768
notification_center : notification_center
760
769
)
761
770
762
771
project_instance = Optimizely ::Project . new (
763
- config_body_JSON , nil , spy_logger , error_handler ,
772
+ nil , nil , spy_logger , error_handler ,
764
773
false , nil , nil , http_project_config_manager , notification_center
765
774
)
766
775
767
776
until http_project_config_manager . ready? ; end
768
777
769
778
expect ( http_project_config_manager . config ) . not_to eq ( nil )
770
- expect ( project_instance . activate ( 'checkout_flow_experiment ' , 'test_user' ) ) . not_to eq ( nil )
779
+ expect ( project_instance . activate ( 'test_experiment ' , 'test_user' ) ) . not_to eq ( nil )
771
780
end
772
781
end
773
782
774
783
describe '.Optimizely with sdk key' do
784
+ before ( :example ) do
785
+ stub_request ( :post , impression_log_url )
786
+ stub_request ( :get , 'https://cdn.optimizely.com/datafiles/valid_sdk_key.json' )
787
+ . with (
788
+ headers : {
789
+ 'Content-Type' => 'application/json'
790
+ }
791
+ )
792
+ . to_return ( status : 200 , body : config_body_JSON , headers : { } )
793
+ end
775
794
it 'should update config, send update notification when sdk key is provided' do
776
- WebMock . allow_net_connect!
777
795
notification_center = Optimizely ::NotificationCenter . new ( spy_logger , error_handler )
778
796
779
797
expect ( notification_center ) . to receive ( :send_notifications ) . with (
@@ -785,13 +803,13 @@ def callback(_args); end
785
803
786
804
project_instance = Optimizely ::Project . new (
787
805
nil , nil , spy_logger , error_handler ,
788
- false , nil , 'QBw9gFM8oTn7ogY9ANCC1z ' , nil , notification_center
806
+ false , nil , 'valid_sdk_key ' , nil , notification_center
789
807
)
790
808
791
809
until project_instance . config_manager . ready? ; end
792
810
793
811
expect ( project_instance . is_valid ) . to be true
794
- expect ( project_instance . activate ( 'checkout_flow_experiment ' , 'test_user' ) ) . not_to eq ( nil )
812
+ expect ( project_instance . activate ( 'test_experiment ' , 'test_user' ) ) . not_to eq ( nil )
795
813
end
796
814
end
797
815
end
@@ -2801,9 +2819,20 @@ def callback(_args); end
2801
2819
end
2802
2820
2803
2821
describe '.close' do
2822
+ before ( :example ) do
2823
+ stub_request ( :post , impression_log_url )
2824
+ stub_request ( :get , 'https://cdn.optimizely.com/datafiles/valid_sdk_key.json' )
2825
+ . with (
2826
+ headers : {
2827
+ 'Content-Type' => 'application/json'
2828
+ }
2829
+ )
2830
+ . to_return ( status : 200 , body : config_body_JSON , headers : { } )
2831
+ end
2832
+
2804
2833
it 'should stop config manager and event processor when optimizely close is called' do
2805
2834
config_manager = Optimizely ::HTTPProjectConfigManager . new (
2806
- sdk_key : 'QBw9gFM8oTn7ogY9ANCC1z ' ,
2835
+ sdk_key : 'valid_sdk_key ' ,
2807
2836
start_by_default : true
2808
2837
)
2809
2838
@@ -2827,7 +2856,7 @@ def callback(_args); end
2827
2856
2828
2857
it 'should stop invalid object' do
2829
2858
http_project_config_manager = Optimizely ::HTTPProjectConfigManager . new (
2830
- sdk_key : 'QBw9gFM8oTn7ogY9ANCC1z '
2859
+ sdk_key : 'valid_sdk_key '
2831
2860
)
2832
2861
2833
2862
project_instance = Optimizely ::Project . new (
@@ -2840,9 +2869,8 @@ def callback(_args); end
2840
2869
end
2841
2870
2842
2871
it 'shoud return optimizely as invalid for an API when close is called' do
2843
- WebMock . allow_net_connect!
2844
2872
http_project_config_manager = Optimizely ::HTTPProjectConfigManager . new (
2845
- sdk_key : 'QBw9gFM8oTn7ogY9ANCC1z '
2873
+ sdk_key : 'valid_sdk_key '
2846
2874
)
2847
2875
2848
2876
project_instance = Optimizely ::Project . new (
@@ -2852,13 +2880,13 @@ def callback(_args); end
2852
2880
2853
2881
until http_project_config_manager . ready? ; end
2854
2882
2855
- expect ( project_instance . activate ( 'checkout_flow_experiment ' , 'test_user' ) ) . not_to eq ( nil )
2883
+ expect ( project_instance . activate ( 'test_experiment ' , 'test_user' ) ) . not_to eq ( nil )
2856
2884
expect ( project_instance . is_valid ) . to be true
2857
2885
2858
2886
project_instance . close
2859
2887
2860
2888
expect ( project_instance . is_valid ) . to be false
2861
- expect ( project_instance . activate ( 'checkout_flow_experiment ' , 'test_user' ) ) . to eq ( nil )
2889
+ expect ( project_instance . activate ( 'test_experiment ' , 'test_user' ) ) . to eq ( nil )
2862
2890
end
2863
2891
2864
2892
it 'should not raise exception for static config manager' do
0 commit comments