|
4 | 4 |
|
5 | 5 | describe SplitIoClient::Engine::Events::EventsDelivery do |
6 | 6 | subject { SplitIoClient::Engine::Events::EventsDelivery } |
7 | | - let(:metadata) { nil } |
8 | | - |
9 | | - it 'test calling handler' do |
10 | | - config = SplitIoClient::SplitConfig.new(logger: Logger.new(StringIO.new)) |
11 | | - delivery = subject.new(config) |
12 | | - |
13 | | - delivery.deliver(SplitIoClient::Engine::Models::SdkInternalEvent::FLAGS_UPDATED, |
14 | | - SplitIoClient::Engine::Models::EventsMetadata.new(SplitIoClient::Engine::Models::SdkEventType::FLAG_UPDATE), |
15 | | - method(:call_back) |
16 | | - ) |
17 | | - sleep 0.5 |
18 | | - expect(@metadata.type).to be(SplitIoClient::Engine::Models::SdkEventType::FLAG_UPDATE) |
19 | | - end |
20 | | - |
21 | | - it 'test exception when calling handler' do |
22 | | - log = StringIO.new |
23 | | - config = SplitIoClient::SplitConfig.new(logger: Logger.new(log)) |
24 | | - delivery = subject.new(config) |
25 | | - |
26 | | - delivery.deliver(SplitIoClient::Engine::Models::SdkInternalEvent::FLAGS_UPDATED, |
27 | | - SplitIoClient::Engine::Models::EventsMetadata.new(SplitIoClient::Engine::Models::SdkEventType::FLAG_UPDATE), |
28 | | - method(:call_with_exception) |
29 | | - ) |
30 | | - sleep 0.5 |
31 | | - expect(log.string).to include 'Exception when calling handler for Sdk Event' \ |
32 | | - end |
33 | | - |
34 | | - def call_back(metadata) |
35 | | - @metadata = metadata |
36 | | - end |
37 | | - |
38 | | - def call_with_exception(metadata) |
39 | | - raise StandardError("call exception") |
40 | | - end |
| 7 | + |
| 8 | + it 'calls handler successfully' do |
| 9 | + config = SplitIoClient::SplitConfig.new(logger: Logger.new(StringIO.new)) |
| 10 | + delivery = subject.new(config) |
| 11 | + |
| 12 | + delivery.deliver( |
| 13 | + SplitIoClient::Engine::Models::SdkInternalEvent::FLAGS_UPDATED, |
| 14 | + SplitIoClient::Engine::Models::EventsMetadata.new(SplitIoClient::Engine::Models::SdkEventType::FLAG_UPDATE), |
| 15 | + method(:call_back) |
| 16 | + ) |
| 17 | + sleep 0.5 |
| 18 | + expect(@metadata.type).to be(SplitIoClient::Engine::Models::SdkEventType::FLAG_UPDATE) |
| 19 | + end |
| 20 | + |
| 21 | + it 'handles exception when calling handler' do |
| 22 | + log = StringIO.new |
| 23 | + config = SplitIoClient::SplitConfig.new(logger: Logger.new(log)) |
| 24 | + delivery = subject.new(config) |
| 25 | + |
| 26 | + delivery.deliver( |
| 27 | + SplitIoClient::Engine::Models::SdkInternalEvent::FLAGS_UPDATED, |
| 28 | + SplitIoClient::Engine::Models::EventsMetadata.new(SplitIoClient::Engine::Models::SdkEventType::FLAG_UPDATE), |
| 29 | + method(:call_with_exception) |
| 30 | + ) |
| 31 | + sleep 0.5 |
| 32 | + expect(log.string).to include('Exception when calling handler for Sdk Event') |
| 33 | + end |
| 34 | + |
| 35 | + it 'logs the sdk event name when handler raises exception' do |
| 36 | + log = StringIO.new |
| 37 | + config = SplitIoClient::SplitConfig.new(logger: Logger.new(log)) |
| 38 | + delivery = subject.new(config) |
| 39 | + |
| 40 | + delivery.deliver( |
| 41 | + SplitIoClient::Engine::Models::SdkInternalEvent::SDK_READY, |
| 42 | + nil, |
| 43 | + method(:call_with_exception) |
| 44 | + ) |
| 45 | + sleep 0.5 |
| 46 | + expect(log.string).to include('Exception when calling handler for Sdk Event') |
| 47 | + expect(log.string).to include(SplitIoClient::Engine::Models::SdkInternalEvent::SDK_READY.to_s) |
| 48 | + end |
| 49 | + |
| 50 | + it 'calls handler with correct metadata' do |
| 51 | + config = SplitIoClient::SplitConfig.new(logger: Logger.new(StringIO.new)) |
| 52 | + delivery = subject.new(config) |
| 53 | + metadata = SplitIoClient::Engine::Models::EventsMetadata.new( |
| 54 | + SplitIoClient::Engine::Models::SdkEventType::FLAG_UPDATE, |
| 55 | + ['feature1', 'feature2'] |
| 56 | + ) |
| 57 | + |
| 58 | + delivery.deliver( |
| 59 | + SplitIoClient::Engine::Models::SdkInternalEvent::FLAGS_UPDATED, |
| 60 | + metadata, |
| 61 | + method(:call_back) |
| 62 | + ) |
| 63 | + sleep 0.5 |
| 64 | + expect(@metadata).to eq(metadata) |
| 65 | + end |
| 66 | + |
| 67 | + def call_back(metadata) |
| 68 | + @metadata = metadata |
| 69 | + end |
| 70 | + |
| 71 | + def call_with_exception(_metadata) |
| 72 | + raise StandardError, 'call exception' |
| 73 | + end |
41 | 74 | end |
0 commit comments