@@ -1732,6 +1732,53 @@ class InvalidErrorHandler; end
1732
1732
end
1733
1733
end
1734
1734
1735
+ describe '#get_feature_variable_for_type with default variables' do
1736
+ it 'should return default variable type and value, when user in experiment and feature is not enabled' do
1737
+ integer_feature = project_instance . config . feature_flag_key_map [ 'integer_single_variable_feature' ]
1738
+ experiment_to_return = project_instance . config . experiment_id_map [ integer_feature [ 'experimentIds' ] [ 0 ] ]
1739
+ variation_to_return = experiment_to_return [ 'variations' ] [ 0 ]
1740
+ variation_to_return [ 'featureEnabled' ] = false
1741
+ decision_to_return = Optimizely ::DecisionService ::Decision . new (
1742
+ experiment_to_return ,
1743
+ variation_to_return ,
1744
+ Optimizely ::DecisionService ::DECISION_SOURCE_EXPERIMENT
1745
+ )
1746
+
1747
+ allow ( project_instance . decision_service ) . to receive ( :get_variation_for_feature ) . and_return ( decision_to_return )
1748
+
1749
+ expect ( project_instance . send (
1750
+ :get_feature_variable_for_type ,
1751
+ 'integer_single_variable_feature' ,
1752
+ 'integer_variable' ,
1753
+ 'integer' ,
1754
+ 'test_user' ,
1755
+ 'browser_type' => 'firefox'
1756
+ ) ) . to eq ( 7 )
1757
+ end
1758
+
1759
+ it 'should return default variable type and value, when user in rollout and feature is not enabled' do
1760
+ experiment_to_return = config_body [ 'rollouts' ] [ 0 ] [ 'experiments' ] [ 1 ]
1761
+ variation_to_return = experiment_to_return [ 'variations' ] [ 0 ]
1762
+ decision_to_return = Optimizely ::DecisionService ::Decision . new (
1763
+ experiment_to_return ,
1764
+ variation_to_return ,
1765
+ Optimizely ::DecisionService ::DECISION_SOURCE_ROLLOUT
1766
+ )
1767
+ allow ( project_instance . decision_service ) . to receive ( :get_variation_for_feature ) . and_return ( decision_to_return )
1768
+
1769
+ expect ( variation_to_return [ 'featureEnabled' ] ) . to be false
1770
+
1771
+ expect ( project_instance . send (
1772
+ :get_feature_variable_for_type ,
1773
+ 'boolean_single_variable_feature' ,
1774
+ 'boolean_variable' ,
1775
+ 'boolean' ,
1776
+ 'test_user' ,
1777
+ { }
1778
+ ) ) . to eq ( true )
1779
+ end
1780
+ end
1781
+
1735
1782
describe 'when forced variation is used' do
1736
1783
# setForcedVariation on a paused experiment and then call getVariation.
1737
1784
it 'should return null when getVariation is called on a paused experiment after setForcedVariation' do
0 commit comments