Skip to content

Commit ba3e6be

Browse files
[AI-FSSDK] [FSSDK-12337] Add EXPERIMENT_TYPES constant with enum validation
- Define EXPERIMENT_TYPES constant with valid experiment type values (ab, mab, cmab, td, fr) in Constants module - Use enum constraint in JSON schema to validate the type field - Reference constant in injection check instead of raw string literal - Add flag_variation_map assertion to variation maps test
1 parent ef4116d commit ba3e6be

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

lib/optimizely/config/datafile_project_config.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ def initialize(datafile, logger, error_handler)
212212

213213
feature_flag['experimentIds'].each do |exp_id|
214214
experiment = @experiment_id_map[exp_id]
215-
next unless experiment && experiment['type'] == 'feature_rollout'
215+
next unless experiment && experiment['type'] == Helpers::Constants::EXPERIMENT_TYPES['fr']
216216

217217
experiment['variations'].push(everyone_else_variation)
218218
experiment['trafficAllocation'].push(

lib/optimizely/helpers/constants.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@
1818
module Optimizely
1919
module Helpers
2020
module Constants
21+
EXPERIMENT_TYPES = {
22+
'ab' => 'a/b',
23+
'mab' => 'mab',
24+
'cmab' => 'cmab',
25+
'td' => 'targeted_delivery',
26+
'fr' => 'feature_rollout'
27+
}.freeze
28+
2129
JSON_SCHEMA_V2 = {
2230
'type' => 'object',
2331
'properties' => {
@@ -206,7 +214,8 @@ module Constants
206214
'type' => 'object'
207215
},
208216
'type' => {
209-
'type' => 'string'
217+
'type' => %w[string null],
218+
'enum' => EXPERIMENT_TYPES.values + [nil]
210219
},
211220
'holdouts' => {
212221
'type' => 'array'

spec/config/datafile_project_config_spec.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,6 +2008,11 @@ def build_datafile(experiments: [], rollouts: [], feature_flags: [])
20082008
expect(config.variation_id_map['feature_rollout_exp']).to have_key('everyone_else_var')
20092009
expect(config.variation_id_map_by_experiment_id['exp_fr']).to have_key('everyone_else_var')
20102010
expect(config.variation_key_map_by_experiment_id['exp_fr']).to have_key('everyone_else_var')
2011+
2012+
# flag_variation_map should also include the injected variation
2013+
flag_variations = config.flag_variation_map['test_flag']
2014+
injected_ids = flag_variations.map { |v| v['id'] }
2015+
expect(injected_ids).to include('everyone_else_var')
20112016
end
20122017

20132018
it 'should not modify non-feature_rollout experiments' do

0 commit comments

Comments
 (0)