|
1199 | 1199 | result = client1.get_treatments_with_config_by_flag_sets('nico_test', ['set_2', 'set_3']) |
1200 | 1200 | expect(result[:FACUNDO_TEST]).to eq({:config=>"{\"color\":\"green\"}", :treatment=>"on"}) |
1201 | 1201 | end |
| 1202 | + end |
1202 | 1203 |
|
| 1204 | + context 'impressions toggle' do |
| 1205 | + it 'optimized mode' do |
| 1206 | + splits_imp_toggle = File.read(File.join(SplitIoClient.root, 'spec/test_data/splits/imp-toggle.json')) |
| 1207 | + stub_request(:get, 'https://sdk.split.io/api/splitChanges?s=1.1&since=-1') |
| 1208 | + .to_return(status: 200, body: splits_imp_toggle) |
| 1209 | + factory_imp_toggle = |
| 1210 | + SplitIoClient::SplitFactory.new('test_api_key', |
| 1211 | + impressions_mode: :optimized, |
| 1212 | + features_refresh_rate: 9999, |
| 1213 | + telemetry_refresh_rate: 99999, |
| 1214 | + impressions_refresh_rate: 99999, |
| 1215 | + streaming_enabled: false) |
| 1216 | + |
| 1217 | + client_imp_toggle = factory_imp_toggle.client |
| 1218 | + client_imp_toggle.block_until_ready |
| 1219 | + |
| 1220 | + expect(client_imp_toggle.get_treatment('key1', 'with_track_disabled')).to eq('off') |
| 1221 | + expect(client_imp_toggle.get_treatment('key2', 'with_track_enabled')).to eq('off') |
| 1222 | + expect(client_imp_toggle.get_treatment('key3', 'without_track')).to eq('off') |
| 1223 | + |
| 1224 | + impressions_repository = client_imp_toggle.instance_variable_get(:@impressions_repository) |
| 1225 | + imps = impressions_repository.batch |
| 1226 | + expect(imps.length()).to eq(2) |
| 1227 | + expect(imps[0][:i][:f]).to eq('with_track_enabled') |
| 1228 | + expect(imps[1][:i][:f]).to eq('without_track') |
| 1229 | + |
| 1230 | + unique_keys_tracker = factory_imp_toggle.instance_variable_get(:@unique_keys_tracker) |
| 1231 | + unique_keys = unique_keys_tracker.instance_variable_get(:@cache) |
| 1232 | + expect(unique_keys.key?('with_track_disabled')).to eq(true) |
| 1233 | + expect(unique_keys.length).to eq(1) |
| 1234 | + impression_counter = factory_imp_toggle.instance_variable_get(:@impression_counter) |
| 1235 | + imp_count = impression_counter.pop_all |
| 1236 | + expect(imp_count.keys()[0].include? ('with_track_disabled')).to eq(true) |
| 1237 | + expect(imp_count.length).to eq(1) |
| 1238 | + client_imp_toggle.destroy |
| 1239 | + sleep 1 |
| 1240 | + end |
| 1241 | + it 'debug mode' do |
| 1242 | + splits_imp_toggle = File.read(File.join(SplitIoClient.root, 'spec/test_data/splits/imp-toggle.json')) |
| 1243 | + stub_request(:get, 'https://sdk.split.io/api/splitChanges?s=1.1&since=-1') |
| 1244 | + .to_return(status: 200, body: splits_imp_toggle) |
| 1245 | + factory_imp_toggle = |
| 1246 | + SplitIoClient::SplitFactory.new('test_api_key', |
| 1247 | + impressions_mode: :debug, |
| 1248 | + features_refresh_rate: 9999, |
| 1249 | + telemetry_refresh_rate: 99999, |
| 1250 | + impressions_refresh_rate: 99999, |
| 1251 | + streaming_enabled: false) |
| 1252 | + |
| 1253 | + client_imp_toggle = factory_imp_toggle.client |
| 1254 | + client_imp_toggle.block_until_ready |
| 1255 | + |
| 1256 | + expect(client_imp_toggle.get_treatment('key1', 'with_track_disabled')).to eq('off') |
| 1257 | + expect(client_imp_toggle.get_treatment('key2', 'with_track_enabled')).to eq('off') |
| 1258 | + expect(client_imp_toggle.get_treatment('key3', 'without_track')).to eq('off') |
| 1259 | + |
| 1260 | + impressions_repository = client_imp_toggle.instance_variable_get(:@impressions_repository) |
| 1261 | + imps = impressions_repository.batch |
| 1262 | + expect(imps.length()).to eq(2) |
| 1263 | + expect(imps[0][:i][:f]).to eq('with_track_enabled') |
| 1264 | + expect(imps[1][:i][:f]).to eq('without_track') |
| 1265 | + |
| 1266 | + unique_keys_tracker = factory_imp_toggle.instance_variable_get(:@unique_keys_tracker) |
| 1267 | + unique_keys = unique_keys_tracker.instance_variable_get(:@cache) |
| 1268 | + expect(unique_keys.key?('with_track_disabled')).to eq(true) |
| 1269 | + expect(unique_keys.length).to eq(1) |
| 1270 | + impression_counter = factory_imp_toggle.instance_variable_get(:@impression_counter) |
| 1271 | + imp_count = impression_counter.pop_all |
| 1272 | + expect(imp_count.keys()[0].include? ('with_track_disabled')).to eq(true) |
| 1273 | + expect(imp_count.length).to eq(1) |
| 1274 | + client_imp_toggle.destroy |
| 1275 | + sleep 1 |
| 1276 | + end |
| 1277 | + it 'debug mode' do |
| 1278 | + splits_imp_toggle = File.read(File.join(SplitIoClient.root, 'spec/test_data/splits/imp-toggle.json')) |
| 1279 | + stub_request(:get, 'https://sdk.split.io/api/splitChanges?s=1.1&since=-1') |
| 1280 | + .to_return(status: 200, body: splits_imp_toggle) |
| 1281 | + factory_imp_toggle = |
| 1282 | + SplitIoClient::SplitFactory.new('test_api_key', |
| 1283 | + impressions_mode: :none, |
| 1284 | + features_refresh_rate: 9999, |
| 1285 | + telemetry_refresh_rate: 99999, |
| 1286 | + impressions_refresh_rate: 99999, |
| 1287 | + streaming_enabled: false) |
| 1288 | + |
| 1289 | + client_imp_toggle = factory_imp_toggle.client |
| 1290 | + client_imp_toggle.block_until_ready |
| 1291 | + expect(client_imp_toggle.get_treatment('key1', 'with_track_disabled')).to eq('off') |
| 1292 | + expect(client_imp_toggle.get_treatment('key2', 'with_track_enabled')).to eq('off') |
| 1293 | + expect(client_imp_toggle.get_treatment('key3', 'without_track')).to eq('off') |
| 1294 | + |
| 1295 | + impressions_repository = client_imp_toggle.instance_variable_get(:@impressions_repository) |
| 1296 | + imps = impressions_repository.batch |
| 1297 | + expect(imps.length()).to eq(0) |
| 1298 | + |
| 1299 | + unique_keys_tracker = factory_imp_toggle.instance_variable_get(:@unique_keys_tracker) |
| 1300 | + unique_keys = unique_keys_tracker.instance_variable_get(:@cache) |
| 1301 | + expect(unique_keys.key?('with_track_disabled')).to eq(true) |
| 1302 | + expect(unique_keys.key?('with_track_enabled')).to eq(true) |
| 1303 | + expect(unique_keys.key?('without_track')).to eq(true) |
| 1304 | + expect(unique_keys.length).to eq(3) |
| 1305 | + impression_counter = factory_imp_toggle.instance_variable_get(:@impression_counter) |
| 1306 | + imp_count = impression_counter.pop_all |
| 1307 | + expect(imp_count.keys()[0].include? ('with_track_disabled')).to eq(true) |
| 1308 | + expect(imp_count.keys()[1].include? ('with_track_enabled')).to eq(true) |
| 1309 | + expect(imp_count.keys()[2].include? ('without_track')).to eq(true) |
| 1310 | + expect(imp_count.length).to eq(3) |
| 1311 | + client_imp_toggle.destroy |
| 1312 | + sleep 1 |
| 1313 | + end |
1203 | 1314 | end |
1204 | 1315 | end |
1205 | 1316 |
|
|
0 commit comments