-
Notifications
You must be signed in to change notification settings - Fork 7
/
evaluation_spec.rb
92 lines (76 loc) · 4.04 KB
/
evaluation_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# frozen_string_literal: true
require_relative '../lib/flipt_client'
RSpec.describe Flipt::EvaluationClient do
before(:all) do
url = ENV.fetch('FLIPT_URL', 'http://localhost:8080')
auth_token = ENV.fetch('FLIPT_AUTH_TOKEN', 'secret')
@client = Flipt::EvaluationClient.new('default',
{ url: url,
authentication: Flipt::ClientTokenAuthentication.new(auth_token) })
end
describe '#evaluate_variant' do
it 'returns a variant result' do
resp = @client.evaluate_variant({ flag_key: 'flag1', entity_id: 'someentity', context: { "fizz": 'buzz' } })
expect(resp).to_not be_nil
expect(resp['flag_key']).to eq('flag1')
expect(resp['match']).to eq(true)
expect(resp['reason']).to eq('MATCH_EVALUATION_REASON')
expect(resp['variant_key']).to eq('variant1')
expect(resp['segment_keys']).to eq(['segment1'])
end
end
describe '#evaluate_boolean' do
it 'returns a boolean result' do
resp = @client.evaluate_boolean({ flag_key: 'flag_boolean', entity_id: 'someentity',
context: { "fizz": 'buzz' } })
expect(resp).to_not be_nil
expect(resp['flag_key']).to eq('flag_boolean')
expect(resp['enabled']).to eq(true)
expect(resp['reason']).to eq('MATCH_EVALUATION_REASON')
end
end
describe '#evaluate_batch' do
it 'returns a batch result' do
resp = @client.evaluate_batch([{ flag_key: 'flag1', entity_id: 'someentity', context: { "fizz": 'buzz' } },
{ flag_key: 'flag_boolean', entity_id: 'someentity', context: { "fizz": 'buzz' } }, { flag_key: 'notfound', entity_id: 'someentity', context: { "fizz": 'buzz' } }])
expect(resp).to_not be_nil
expect(resp['responses'].length).to be == 3
variant = resp['responses'][0]
expect(variant['type']).to eq('VARIANT_EVALUATION_RESPONSE_TYPE')
expect(variant['variant_evaluation_response']['flag_key']).to eq('flag1')
expect(variant['variant_evaluation_response']['match']).to eq(true)
expect(variant['variant_evaluation_response']['reason']).to eq('MATCH_EVALUATION_REASON')
expect(variant['variant_evaluation_response']['variant_key']).to eq('variant1')
expect(variant['variant_evaluation_response']['segment_keys']).to eq(['segment1'])
boolean = resp['responses'][1]
expect(boolean['type']).to eq('BOOLEAN_EVALUATION_RESPONSE_TYPE')
expect(boolean['boolean_evaluation_response']['flag_key']).to eq('flag_boolean')
expect(boolean['boolean_evaluation_response']['enabled']).to eq(true)
expect(boolean['boolean_evaluation_response']['reason']).to eq('MATCH_EVALUATION_REASON')
error = resp['responses'][2]
expect(error['type']).to eq('ERROR_EVALUATION_RESPONSE_TYPE')
expect(error['error_evaluation_response']['flag_key']).to eq('notfound')
expect(error['error_evaluation_response']['namespace_key']).to eq('default')
expect(error['error_evaluation_response']['reason']).to eq('NOT_FOUND_ERROR_EVALUATION_REASON')
end
end
describe '#evaluate_variant failure' do
it 'gracefully handles failures for variant flag evaluation' do
expect { @client.evaluate_variant({ flag_key: 'nonexistent', entity_id: 'someentity', context: { "fizz": 'buzz' } }) }
.to raise_error(StandardError, 'invalid request: failed to get flag information default/nonexistent')
end
end
describe '#evaluate_boolean failure' do
it 'gracefully handles failures for boolean flag evaluation' do
expect { @client.evaluate_boolean({ flag_key: 'nonexistent', entity_id: 'someentity', context: { "fizz": 'buzz' } }) }
.to raise_error(StandardError, 'invalid request: failed to get flag information default/nonexistent')
end
end
describe '#list_flags' do
it 'returns a list of flags' do
resp = @client.list_flags
expect(resp).to_not be_nil
expect(resp).to include({ 'enabled' => true, 'key' => 'flag_boolean', 'type' => 'BOOLEAN_FLAG_TYPE' })
end
end
end