|
1 | 1 | # frozen_string_literal: true |
2 | 2 |
|
3 | 3 | # |
4 | | -# Copyright 2016-2017, 2019, Optimizely and contributors |
| 4 | +# Copyright 2016-2017, 2019-2020 Optimizely and contributors |
5 | 5 | # |
6 | 6 | # Licensed under the Apache License, Version 2.0 (the "License"); |
7 | 7 | # you may not use this file except in compliance with the License. |
|
50 | 50 | .with(body: @params, headers: @post_headers)).to have_been_made.once |
51 | 51 | end |
52 | 52 |
|
| 53 | + it 'should properly dispatch V2 (POST) events to http url' do |
| 54 | + http_url = 'http://www.optimizely.com' |
| 55 | + stub_request(:post, http_url) |
| 56 | + event = Optimizely::Event.new(:post, http_url, @params, @post_headers) |
| 57 | + @event_dispatcher.dispatch_event(event) |
| 58 | + |
| 59 | + expect(a_request(:post, http_url) |
| 60 | + .with(body: @params, headers: @post_headers)).to have_been_made.once |
| 61 | + end |
| 62 | + |
53 | 63 | it 'should properly dispatch V2 (POST) events with timeout exception' do |
54 | | - stub_request(:post, @url) |
55 | 64 | event = Optimizely::Event.new(:post, @url, @params, @post_headers) |
56 | 65 | timeout_error = Timeout::Error.new |
57 | | - allow(HTTParty).to receive(:post).with(any_args).and_raise(timeout_error) |
| 66 | + stub_request(:post, @url).to_raise(timeout_error) |
58 | 67 | result = @event_dispatcher.dispatch_event(event) |
59 | 68 |
|
60 | 69 | expect(result).to eq(timeout_error) |
|
71 | 80 |
|
72 | 81 | it 'should properly dispatch V2 (GET) events with timeout exception' do |
73 | 82 | get_url = @url + '?a=111001&g=111028&n=test_event&u=test_user' |
74 | | - stub_request(:get, get_url) |
75 | 83 | event = Optimizely::Event.new(:get, get_url, @params, @post_headers) |
76 | 84 | timeout_error = Timeout::Error.new |
77 | | - allow(HTTParty).to receive(:get).with(any_args).and_raise(timeout_error) |
| 85 | + stub_request(:get, get_url).to_raise(timeout_error) |
| 86 | + |
78 | 87 | result = @event_dispatcher.dispatch_event(event) |
79 | 88 |
|
80 | 89 | expect(result).to eq(timeout_error) |
81 | 90 | end |
82 | 91 |
|
83 | 92 | it 'should log and handle Timeout error' do |
84 | 93 | get_url = @url + '?a=111001&g=111028&n=test_event&u=test_user' |
85 | | - stub_request(:post, get_url) |
86 | 94 | event = Optimizely::Event.new(:post, get_url, @params, @post_headers) |
87 | 95 | timeout_error = Timeout::Error.new |
88 | | - allow(HTTParty).to receive(:post).with(any_args).and_raise(timeout_error) |
| 96 | + stub_request(:post, get_url).to_raise(timeout_error) |
| 97 | + |
89 | 98 | result = @customized_event_dispatcher.dispatch_event(event) |
90 | 99 |
|
91 | 100 | expect(result).to eq(timeout_error) |
|
98 | 107 |
|
99 | 108 | it 'should log and handle any standard error' do |
100 | 109 | get_url = @url + '?a=111001&g=111028&n=test_event&u=test_user' |
101 | | - stub_request(:post, get_url) |
102 | 110 | event = Optimizely::Event.new(:post, get_url, @params, @post_headers) |
103 | | - error = ArgumentError |
104 | | - allow(HTTParty).to receive(:post).with(any_args).and_raise(error) |
| 111 | + stub_request(:post, get_url).to_raise(ArgumentError.new) |
| 112 | + |
105 | 113 | result = @customized_event_dispatcher.dispatch_event(event) |
106 | 114 |
|
107 | 115 | expect(result).to eq(nil) |
|
0 commit comments