@@ -703,6 +703,39 @@ class InvalidErrorHandler; end
703
703
end
704
704
end
705
705
706
+ describe '#get_enabled_features' do
707
+ it 'should return empty when called with invalid project config' do
708
+ invalid_project = Optimizely ::Project . new ( 'invalid' , nil , spy_logger )
709
+ expect ( invalid_project . get_enabled_features ( 'test_user' ) ) . to be_empty
710
+ end
711
+
712
+ it 'should return empty when no feature flag is enabled' do
713
+ allow ( project_instance ) . to receive ( :is_feature_enabled ) . and_return ( false )
714
+ expect ( project_instance . get_enabled_features ( 'test_user' ) ) . to be_empty
715
+ end
716
+
717
+ it 'should return only enabled feature flags keys' do
718
+ # Sets all feature-flags keys with randomly assigned status
719
+ features_keys = project_instance . config . feature_flags . map do |item |
720
+ { key : ( item [ 'key' ] ) . to_s , value : [ true , false ] . sample } # '[true, false].sample' generates random boolean
721
+ end
722
+
723
+ enabled_features = features_keys . map { |x | x [ :key ] if x [ :value ] == true } . compact
724
+ disabled_features = features_keys . map { |x | x [ :key ] if x [ :value ] == false } . compact
725
+
726
+ features_keys . each do |feature |
727
+ allow ( project_instance ) . to receive ( :is_feature_enabled ) . with ( feature [ :key ] , 'test_user' , 'browser_type' => 'chrome' ) . and_return ( feature [ :value ] )
728
+ end
729
+
730
+ # Checks enabled features are returned
731
+ expect ( project_instance . get_enabled_features ( 'test_user' , 'browser_type' => 'chrome' ) ) . to include ( *enabled_features )
732
+ expect ( project_instance . get_enabled_features ( 'test_user' , 'browser_type' => 'chrome' ) . length ) . to eq ( enabled_features . length )
733
+
734
+ # Checks prevented features should not return
735
+ expect ( project_instance . get_enabled_features ( 'test_user' , 'browser_type' => 'chrome' ) ) . not_to include ( *disabled_features )
736
+ end
737
+ end
738
+
706
739
describe '#get_feature_variable_string' do
707
740
user_id = 'test_user'
708
741
user_attributes = { }
0 commit comments