|
19 | 19 | require 'spec_helper'
|
20 | 20 |
|
21 | 21 | describe Optimizely::OptimizelyConfig do
|
| 22 | + let(:config_body) { OptimizelySpec::VALID_CONFIG_BODY } |
22 | 23 | let(:config_body_JSON) { OptimizelySpec::VALID_CONFIG_BODY_JSON }
|
23 | 24 | let(:similar_exp_keys_JSON) { OptimizelySpec::SIMILAR_EXP_KEYS_JSON }
|
24 | 25 | let(:typed_audiences_JSON) { OptimizelySpec::CONFIG_DICT_WITH_TYPED_AUDIENCES_JSON }
|
|
768 | 769 | '',
|
769 | 770 | '"exactString" OR "999999999"'
|
770 | 771 | ]
|
771 |
| - optimizely_config = Optimizely::OptimizelyConfig.new(project_instance_typed_audiences.send(:project_config)) |
| 772 | + optimizely_config = Optimizely::OptimizelyConfig.new(project_instance_typed_audiences.send(:project_config), spy_logger) |
772 | 773 | audiences_map = optimizely_config.send(:audiences_map)
|
773 | 774 | audience_conditions.each_with_index do |audience_condition, index|
|
774 | 775 | result = optimizely_config.send(:replace_ids_with_names, audience_condition, audiences_map)
|
|
796 | 797 | expect(optimizely_config_similar_rule_keys['sdkKey']).to eq('')
|
797 | 798 | expect(optimizely_config_similar_rule_keys['environmentKey']).to eq('')
|
798 | 799 | end
|
| 800 | + |
| 801 | + it 'should use the newest of duplicate experiment keys' do |
| 802 | + duplicate_experiment_key = 'test_experiment' |
| 803 | + new_experiment = { |
| 804 | + 'key': duplicate_experiment_key, |
| 805 | + 'status': 'Running', |
| 806 | + 'layerId': '8', |
| 807 | + "audienceConditions": %w[ |
| 808 | + or |
| 809 | + 11160 |
| 810 | + ], |
| 811 | + 'audienceIds': ['11160'], |
| 812 | + 'id': '111137', |
| 813 | + 'forcedVariations': {}, |
| 814 | + 'trafficAllocation': [ |
| 815 | + {'entityId': '222242', 'endOfRange': 8000}, |
| 816 | + {'entityId': '', 'endOfRange': 10_000} |
| 817 | + ], |
| 818 | + 'variations': [ |
| 819 | + { |
| 820 | + 'id': '222242', |
| 821 | + 'key': 'control', |
| 822 | + 'variables': [] |
| 823 | + } |
| 824 | + ] |
| 825 | + } |
| 826 | + |
| 827 | + new_feature = { |
| 828 | + 'id': '91117', |
| 829 | + 'key': 'new_feature', |
| 830 | + 'experimentIds': ['111137'], |
| 831 | + 'rolloutId': '', |
| 832 | + 'variables': [ |
| 833 | + {'id': '127', 'key': 'is_working', 'defaultValue': 'true', 'type': 'boolean'}, |
| 834 | + {'id': '128', 'key': 'environment', 'defaultValue': 'devel', 'type': 'string'}, |
| 835 | + {'id': '129', 'key': 'cost', 'defaultValue': '10.99', 'type': 'double'}, |
| 836 | + {'id': '130', 'key': 'count', 'defaultValue': '999', 'type': 'integer'}, |
| 837 | + {'id': '131', 'key': 'variable_without_usage', 'defaultValue': '45', 'type': 'integer'}, |
| 838 | + {'id': '132', 'key': 'object', 'defaultValue': '{"test": 12}', 'type': 'string', 'subType': 'json'}, |
| 839 | + {'id': '133', 'key': 'true_object', 'defaultValue': '{"true_test": 23.54}', 'type': 'json'} |
| 840 | + ] |
| 841 | + } |
| 842 | + |
| 843 | + config = OptimizelySpec.deep_clone(config_body) |
| 844 | + |
| 845 | + config['experiments'].push(new_experiment) |
| 846 | + config['featureFlags'].push(new_feature) |
| 847 | + project_config = Optimizely::DatafileProjectConfig.new(JSON.dump(config), spy_logger, error_handler) |
| 848 | + |
| 849 | + opti_config = Optimizely::OptimizelyConfig.new(project_config, spy_logger) |
| 850 | + |
| 851 | + key_map = opti_config.config['experimentsMap'] |
| 852 | + id_map = opti_config.send(:experiments_id_map) |
| 853 | + |
| 854 | + expected_warning_message = "Duplicate experiment keys found in datafile: #{duplicate_experiment_key}" |
| 855 | + expect(spy_logger).to have_received(:log).once.with(Logger::WARN, expected_warning_message) |
| 856 | + |
| 857 | + expect(key_map[duplicate_experiment_key]['id']).to eq(new_experiment[:id]) |
| 858 | + expect(id_map.values.count { |exp| exp['key'] == duplicate_experiment_key }).to eq(2) |
| 859 | + end |
799 | 860 | end
|
0 commit comments