|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | 3 | require 'spec_helper' |
| 4 | +require 'open_feature/sdk' |
4 | 5 |
|
5 | 6 | context 'user_from_openfeature_context' do |
6 | 7 | context 'user_id' do |
|
73 | 74 | expect(user.customData).to eq({ 'randomField' => 'value' }) |
74 | 75 | end |
75 | 76 | end |
| 77 | + |
| 78 | + context 'create provider expect defaults' do |
| 79 | + before(:all) do |
| 80 | + @dvc = DevCycle::Client.new('dvc_server_token_hash') |
| 81 | + OpenFeature::SDK.configure do |config| |
| 82 | + config.set_provider(@dvc.open_feature_provider) |
| 83 | + end |
| 84 | + @client = OpenFeature::SDK.build_client |
| 85 | + |
| 86 | + end |
| 87 | + it 'returns a provider with a valid client' do |
| 88 | + provider = @dvc.open_feature_provider |
| 89 | + expect(provider).to be_instance_of(DevCycle::Provider) |
| 90 | + end |
| 91 | + it 'responds properly to fetch_boolean_value' do |
| 92 | + expect(@client.fetch_boolean_value(flag_key: 'flag_key', default_value: false, evaluation_context: OpenFeature::SDK::EvaluationContext.new(user_id:'user_id'))).to be(false) |
| 93 | + end |
| 94 | + it 'responds properly to fetch_string_value' do |
| 95 | + expect(@client.fetch_string_value(flag_key: 'flag_key', default_value: 'default', evaluation_context: OpenFeature::SDK::EvaluationContext.new(user_id:'user_id'))).to eq('default') |
| 96 | + end |
| 97 | + it 'responds properly to fetch_number_value' do |
| 98 | + expect(@client.fetch_number_value(flag_key: 'flag_key', default_value: 1, evaluation_context: OpenFeature::SDK::EvaluationContext.new(user_id:'user_id'))).to eq(1) |
| 99 | + end |
| 100 | + it 'responds properly to fetch_integer_value' do |
| 101 | + expect(@client.fetch_integer_value(flag_key: 'flag_key', default_value: 1, evaluation_context: OpenFeature::SDK::EvaluationContext.new(user_id:'user_id'))).to eq(1) |
| 102 | + end |
| 103 | + it 'responds properly to fetch_float_value' do |
| 104 | + expect(@client.fetch_float_value(flag_key: 'flag_key', default_value: 1.0, evaluation_context: OpenFeature::SDK::EvaluationContext.new(user_id:'user_id'))).to eq(1.0) |
| 105 | + end |
| 106 | + it 'responds properly to fetch_object_value' do |
| 107 | + expect(@client.fetch_object_value(flag_key: 'flag_key', default_value: { 'key' => 'value' }, evaluation_context: OpenFeature::SDK::EvaluationContext.new(user_id:'user_id'))).to eq({ 'key' => 'value' }) |
| 108 | + end |
| 109 | + end |
| 110 | + |
| 111 | + context 'create provider expect real values' do |
| 112 | + before(:all) do |
| 113 | + @dvc = DevCycle::Client.new('dvc_server_token_hash') |
| 114 | + OpenFeature::SDK.configure do |config| |
| 115 | + config.set_provider(@dvc.open_feature_provider) |
| 116 | + end |
| 117 | + @client = OpenFeature::SDK.build_client |
| 118 | + sleep(3) |
| 119 | + |
| 120 | + end |
| 121 | + it 'returns a provider with a valid client' do |
| 122 | + provider = @dvc.open_feature_provider |
| 123 | + expect(provider).to be_instance_of(DevCycle::Provider) |
| 124 | + end |
| 125 | + it 'responds properly to fetch_boolean_value' do |
| 126 | + expect(@client.fetch_boolean_value(flag_key: 'test', default_value: false, evaluation_context: OpenFeature::SDK::EvaluationContext.new(user_id:'test'))).to be(true) |
| 127 | + end |
| 128 | + it 'responds properly to fetch_string_value' do |
| 129 | + expect(@client.fetch_string_value(flag_key: 'test-string-variable', default_value: 'default', evaluation_context: OpenFeature::SDK::EvaluationContext.new(user_id:'test'))).not_to eq('default') |
| 130 | + end |
| 131 | + it 'responds properly to fetch_number_value' do |
| 132 | + expect(@client.fetch_number_value(flag_key: 'test-number-variable', default_value: 1, evaluation_context: OpenFeature::SDK::EvaluationContext.new(user_id:'test'))).not_to eq(1) |
| 133 | + end |
| 134 | + it 'responds properly to fetch_integer_value' do |
| 135 | + expect(@client.fetch_integer_value(flag_key: 'test-number-variable', default_value: 1, evaluation_context: OpenFeature::SDK::EvaluationContext.new(user_id:'test'))).not_to eq(1) |
| 136 | + end |
| 137 | + it 'responds properly to fetch_float_value' do |
| 138 | + expect(@client.fetch_float_value(flag_key: 'test-float-variable', default_value: 1.0, evaluation_context: OpenFeature::SDK::EvaluationContext.new(user_id:'test'))).not_to eq(1.0) |
| 139 | + end |
| 140 | + it 'responds properly to fetch_object_value' do |
| 141 | + expect(@client.fetch_object_value(flag_key: 'test-json-variable', default_value: { 'key' => 'value' }, evaluation_context: OpenFeature::SDK::EvaluationContext.new(user_id:'test'))).not_to eq({ 'key' => 'value' }) |
| 142 | + end |
| 143 | + end |
76 | 144 | end |
0 commit comments