Skip to content

Commit 77c300d

Browse files
-unit tests updated
-rubocop autocorrection
1 parent a893749 commit 77c300d

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

lib/optimizely/helpers/validator.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ def inputs_valid?(variables, logger = NoOpLogger.new, level = Logger::ERROR)
122122

123123
return false unless variables.respond_to?(:each) && !variables.empty?
124124

125-
is_valid = true # rubocop:disable Lint/UselessAssignment
125+
is_valid = true
126126
if variables.include? :user_id
127127
# Empty str is a valid user ID.
128128
unless variables[:user_id].is_a?(String)
129-
is_valid = false # rubocop:disable Lint/UselessAssignment
129+
is_valid = false
130130
logger.log(level, "#{Constants::INPUT_VARIABLES['USER_ID']} is invalid")
131131
end
132132
variables.delete :user_id

spec/project_spec.rb

+28-10
Original file line numberDiff line numberDiff line change
@@ -2079,7 +2079,7 @@ def callback(_args); end
20792079
it 'should return only enabled feature flags keys' do
20802080
# Sets all feature-flags keys with randomly assigned status
20812081
features_keys = project_config.feature_flags.map do |item|
2082-
{key: (item['key']).to_s, value: [true, false].sample} # '[true, false].sample' generates random boolean
2082+
{key: item['key'].to_s, value: [true, false].sample} # '[true, false].sample' generates random boolean
20832083
end
20842084

20852085
enabled_features = features_keys.map { |x| x[:key] if x[:value] == true }.compact
@@ -3758,7 +3758,9 @@ def callback(_args); end
37583758
variation_key: 'Fred',
37593759
rule_key: 'test_experiment_multivariate',
37603760
reasons: [],
3761-
decision_event_dispatched: true
3761+
decision_event_dispatched: true,
3762+
experiment_id: experiment_to_return['id'],
3763+
variation_id: variation_to_return['id']
37623764
)
37633765
allow(project_instance.event_dispatcher).to receive(:dispatch_event).with(instance_of(Optimizely::Event))
37643766
decision_to_return = Optimizely::DecisionService::Decision.new(
@@ -3801,7 +3803,9 @@ def callback(_args); end
38013803
variation_key: 'Fred',
38023804
rule_key: 'test_experiment_multivariate',
38033805
reasons: [],
3804-
decision_event_dispatched: true
3806+
decision_event_dispatched: true,
3807+
experiment_id: experiment_to_return['id'],
3808+
variation_id: variation_to_return['id']
38053809
)
38063810
allow(project_instance.event_dispatcher).to receive(:dispatch_event).with(instance_of(Optimizely::Event))
38073811
decision_to_return = Optimizely::DecisionService::Decision.new(
@@ -3883,7 +3887,9 @@ def callback(_args); end
38833887
variation_key: 'Fred',
38843888
rule_key: 'test_experiment_multivariate',
38853889
reasons: [],
3886-
decision_event_dispatched: false
3890+
decision_event_dispatched: false,
3891+
experiment_id: experiment_to_return['id'],
3892+
variation_id: variation_to_return['id']
38873893
)
38883894
allow(project_config).to receive(:send_flag_decisions).and_return(false)
38893895
allow(project_instance.event_dispatcher).to receive(:dispatch_event).with(instance_of(Optimizely::Event))
@@ -3921,7 +3927,9 @@ def callback(_args); end
39213927
variation_key: nil,
39223928
rule_key: nil,
39233929
reasons: [],
3924-
decision_event_dispatched: false
3930+
decision_event_dispatched: false,
3931+
experiment_id: nil,
3932+
variation_id: nil
39253933
)
39263934
allow(project_config).to receive(:send_flag_decisions).and_return(false)
39273935
allow(project_instance.event_dispatcher).to receive(:dispatch_event).with(instance_of(Optimizely::Event))
@@ -3958,7 +3966,9 @@ def callback(_args); end
39583966
variation_key: nil,
39593967
rule_key: nil,
39603968
reasons: [],
3961-
decision_event_dispatched: true
3969+
decision_event_dispatched: true,
3970+
experiment_id: nil,
3971+
variation_id: nil
39623972
)
39633973
allow(project_instance.event_dispatcher).to receive(:dispatch_event).with(instance_of(Optimizely::Event))
39643974
decision_to_return = nil
@@ -4122,7 +4132,9 @@ def callback(_args); end
41224132
"The user 'user1' is not bucketed into any of the experiments on the feature 'multi_variate_feature'.",
41234133
"Feature flag 'multi_variate_feature' is not used in a rollout."
41244134
],
4125-
decision_event_dispatched: true
4135+
decision_event_dispatched: true,
4136+
experiment_id: nil,
4137+
variation_id: nil
41264138
)
41274139
expect(project_instance.notification_center).to receive(:send_notifications)
41284140
.once.with(Optimizely::NotificationCenter::NOTIFICATION_TYPES[:LOG_EVENT], any_args)
@@ -4162,7 +4174,9 @@ def callback(_args); end
41624174
variation_key: nil,
41634175
rule_key: nil,
41644176
reasons: [],
4165-
decision_event_dispatched: true
4177+
decision_event_dispatched: true,
4178+
experiment_id: nil,
4179+
variation_id: nil
41664180
)
41674181
allow(project_instance.event_dispatcher).to receive(:dispatch_event).with(instance_of(Optimizely::Event))
41684182
user_context = project_instance.create_user_context('user1')
@@ -4481,7 +4495,9 @@ def callback(_args); end
44814495
"The user 'user1' is not bucketed into any of the experiments on the feature 'multi_variate_feature'.",
44824496
"Feature flag 'multi_variate_feature' is not used in a rollout."
44834497
],
4484-
decision_event_dispatched: true
4498+
decision_event_dispatched: true,
4499+
experiment_id: nil,
4500+
variation_id: nil
44854501
)
44864502
allow(custom_project_instance.event_dispatcher).to receive(:dispatch_event).with(instance_of(Optimizely::Event))
44874503
user_context = custom_project_instance.create_user_context('user1')
@@ -4521,7 +4537,9 @@ def callback(_args); end
45214537
variation_key: nil,
45224538
rule_key: nil,
45234539
reasons: [],
4524-
decision_event_dispatched: true
4540+
decision_event_dispatched: true,
4541+
experiment_id: nil,
4542+
variation_id: nil
45254543
)
45264544
allow(custom_project_instance.event_dispatcher).to receive(:dispatch_event).with(instance_of(Optimizely::Event))
45274545
user_context = custom_project_instance.create_user_context('user1')

0 commit comments

Comments
 (0)