-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improve: Add http_timeout for RestClient
- Loading branch information
Showing
20 changed files
with
269 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,15 @@ | |
require 'spec_helper' | ||
|
||
describe Vero::Api::Workers::Events::TrackAPI do | ||
subject { Vero::Api::Workers::Events::TrackAPI.new('https://api.getvero.com', { auth_token: 'abcd', identity: { email: '[email protected]' }, event_name: 'test_event' }) } | ||
let(:payload) do | ||
{ | ||
auth_token: 'abcd', | ||
identity: { email: '[email protected]' }, | ||
event_name: 'test_event' | ||
} | ||
end | ||
|
||
subject { Vero::Api::Workers::Events::TrackAPI.new('https://api.getvero.com', payload) } | ||
|
||
it_behaves_like 'a Vero wrapper' do | ||
let(:end_point) { '/api/v2/events/track.json' } | ||
|
@@ -16,22 +24,21 @@ | |
subject.options = options | ||
expect { subject.send(:validate!) }.to raise_error(ArgumentError) | ||
|
||
options = { auth_token: 'abcd', identity: { email: '[email protected]' }, event_name: 'test_event' } | ||
subject.options = options | ||
subject.options = payload | ||
expect { subject.send(:validate!) }.to_not raise_error | ||
end | ||
|
||
it 'should raise an error if data is not either nil or a Hash' do | ||
options = { auth_token: 'abcd', identity: { email: '[email protected]' }, event_name: 'test_event', data: [] } | ||
subject.options = options | ||
payload[:data] = [] | ||
subject.options = payload | ||
expect { subject.send(:validate!) }.to raise_error(ArgumentError) | ||
|
||
options = { auth_token: 'abcd', identity: { email: '[email protected]' }, event_name: 'test_event', data: nil } | ||
subject.options = options | ||
payload[:data] = nil | ||
subject.options = payload | ||
expect { subject.send(:validate!) }.to_not raise_error | ||
|
||
options = { auth_token: 'abcd', identity: { email: '[email protected]' }, event_name: 'test_event', data: {} } | ||
subject.options = options | ||
payload[:data] = {} | ||
subject.options = payload | ||
expect { subject.send(:validate!) }.to_not raise_error | ||
end | ||
|
||
|
@@ -49,18 +56,40 @@ | |
|
||
describe :request do | ||
it 'should send a JSON request to the Vero API' do | ||
expect(RestClient).to receive(:post).with('https://api.getvero.com/api/v2/events/track.json', { auth_token: 'abcd', identity: { email: '[email protected]' }, event_name: 'test_event' }.to_json, { content_type: :json, accept: :json }) | ||
allow(RestClient).to receive(:post).and_return(200) | ||
expect(RestClient::Request).to( | ||
receive(:execute).with( | ||
method: :post, | ||
url: 'https://api.getvero.com/api/v2/events/track.json', | ||
payload: { auth_token: 'abcd', identity: { email: '[email protected]' }, event_name: 'test_event' }.to_json, | ||
headers: { content_type: :json, accept: :json }, | ||
timeout: 60 | ||
) | ||
) | ||
allow(RestClient::Request).to receive(:execute).and_return(200) | ||
subject.send(:request) | ||
end | ||
|
||
it 'should allow configurable timeout' do | ||
expect(RestClient::Request).to( | ||
receive(:execute).with( | ||
method: :post, | ||
url: 'https://api.getvero.com/api/v2/events/track.json', | ||
payload: { auth_token: 'abcd', identity: { email: '[email protected]' }, event_name: 'test_event' }.to_json, | ||
headers: { content_type: :json, accept: :json }, | ||
timeout: 30 | ||
) | ||
) | ||
allow(RestClient::Request).to receive(:execute).and_return(200) | ||
Vero::Api::Workers::Events::TrackAPI.new('https://api.getvero.com', payload.merge(_config: { http_timeout: 30 })).send(:request) | ||
end | ||
end | ||
end | ||
|
||
describe 'integration test' do | ||
it 'should not raise any errors' do | ||
obj = Vero::Api::Workers::Events::TrackAPI.new('https://api.getvero.com', { auth_token: 'abcd', identity: { email: '[email protected]' }, event_name: 'test_event' }) | ||
obj = Vero::Api::Workers::Events::TrackAPI.new('https://api.getvero.com', payload) | ||
|
||
allow(RestClient).to receive(:post).and_return(200) | ||
allow(RestClient::Request).to receive(:execute).and_return(200) | ||
expect { obj.perform }.to_not raise_error | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,15 @@ | |
require 'spec_helper' | ||
|
||
describe Vero::Api::Workers::Users::EditAPI do | ||
subject { Vero::Api::Workers::Users::EditAPI.new('https://api.getvero.com', { auth_token: 'abcd', email: '[email protected]', changes: { email: '[email protected]' } }) } | ||
let(:payload) do | ||
{ | ||
auth_token: 'abcd', | ||
email: '[email protected]', | ||
changes: { email: '[email protected]' } | ||
} | ||
end | ||
|
||
subject { Vero::Api::Workers::Users::EditAPI.new('https://api.getvero.com', payload) } | ||
|
||
it_behaves_like 'a Vero wrapper' do | ||
let(:end_point) { '/api/v2/users/edit.json' } | ||
|
@@ -19,15 +27,23 @@ | |
|
||
describe :request do | ||
it 'should send a request to the Vero API' do | ||
expect(RestClient).to receive(:put).with('https://api.getvero.com/api/v2/users/edit.json', { auth_token: 'abcd', email: '[email protected]', changes: { email: '[email protected]' } }.to_json, { content_type: :json, accept: :json }) | ||
allow(RestClient).to receive(:put).and_return(200) | ||
expect(RestClient::Request).to( | ||
receive(:execute).with( | ||
method: :put, | ||
url: 'https://api.getvero.com/api/v2/users/edit.json', | ||
payload: { auth_token: 'abcd', email: '[email protected]', changes: { email: '[email protected]' } }.to_json, | ||
headers: { content_type: :json, accept: :json }, | ||
timeout: 60 | ||
) | ||
) | ||
allow(RestClient::Request).to receive(:execute).and_return(200) | ||
subject.send(:request) | ||
end | ||
end | ||
|
||
describe 'integration test' do | ||
it 'should not raise any errors' do | ||
allow(RestClient).to receive(:put).and_return(200) | ||
allow(RestClient::Request).to receive(:execute).and_return(200) | ||
expect { subject.perform }.to_not raise_error | ||
end | ||
end | ||
|
Oops, something went wrong.