vero 0.7.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGES.md +11 -8
- data/Gemfile +15 -1
- data/Gemfile.lock +142 -81
- data/README.markdown +148 -119
- data/lib/generators/vero_generator.rb +18 -19
- data/lib/vero.rb +10 -3
- data/lib/vero/api.rb +24 -8
- data/lib/vero/api/base_api.rb +12 -11
- data/lib/vero/api/events/track_api.rb +5 -3
- data/lib/vero/api/users/delete_api.rb +21 -0
- data/lib/vero/api/users/edit_api.rb +5 -3
- data/lib/vero/api/users/edit_tags_api.rb +7 -5
- data/lib/vero/api/users/reidentify_api.rb +5 -3
- data/lib/vero/api/users/resubscribe_api.rb +23 -0
- data/lib/vero/api/users/track_api.rb +5 -3
- data/lib/vero/api/users/unsubscribe_api.rb +3 -1
- data/lib/vero/app.rb +4 -2
- data/lib/vero/config.rb +14 -19
- data/lib/vero/context.rb +9 -11
- data/lib/vero/context/api.rb +9 -7
- data/lib/vero/dsl.rb +3 -1
- data/lib/vero/railtie.rb +5 -3
- data/lib/vero/sender.rb +12 -30
- data/lib/vero/senders/base.rb +3 -1
- data/lib/vero/senders/delayed_job.rb +7 -7
- data/lib/vero/senders/invalid.rb +5 -3
- data/lib/vero/senders/resque.rb +8 -8
- data/lib/vero/senders/sidekiq.rb +25 -0
- data/lib/vero/senders/{thread.rb → sucker_punch.rb} +5 -3
- data/lib/vero/trackable.rb +4 -2
- data/lib/vero/trackable/base.rb +10 -9
- data/lib/vero/trackable/interface.rb +3 -1
- data/lib/vero/utility/ext.rb +3 -1
- data/lib/vero/utility/logger.rb +4 -6
- data/lib/vero/version.rb +3 -1
- data/lib/vero/view_helpers/javascript.rb +20 -20
- data/spec/lib/api/base_api_spec.rb +11 -9
- data/spec/lib/api/events/track_api_spec.rb +30 -30
- data/spec/lib/api/users/delete_api_spec.rb +33 -0
- data/spec/lib/api/users/edit_api_spec.rb +14 -16
- data/spec/lib/api/users/edit_tags_api_spec.rb +28 -31
- data/spec/lib/api/users/reidentify_spec.rb +20 -22
- data/spec/lib/api/users/resubscribe_api_spec.rb +35 -0
- data/spec/lib/api/users/track_api_spec.rb +26 -28
- data/spec/lib/api/users/unsubscribe_api_spec.rb +14 -16
- data/spec/lib/api_spec.rb +59 -57
- data/spec/lib/app_spec.rb +21 -19
- data/spec/lib/config_spec.rb +77 -59
- data/spec/lib/context_spec.rb +27 -25
- data/spec/lib/dsl_spec.rb +4 -2
- data/spec/lib/sender_spec.rb +12 -23
- data/spec/lib/senders/sidekiq_spec.rb +32 -0
- data/spec/lib/trackable_spec.rb +125 -151
- data/spec/lib/view_helpers_spec.rb +13 -9
- data/spec/spec_helper.rb +10 -4
- data/spec/support/base_config_shared_examples.rb +11 -0
- data/spec/support/user_support.rb +15 -7
- data/spec/support/vero_user_support.rb +4 -2
- data/vero.gemspec +14 -29
- metadata +47 -138
@@ -1,17 +1,19 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Vero::Api::Workers::BaseAPI do
|
4
|
-
let
|
6
|
+
let(:subject) { Vero::Api::Workers::BaseAPI.new('http://www.getvero.com', {}) }
|
5
7
|
|
6
8
|
describe :options_with_symbolized_keys do
|
7
|
-
it
|
8
|
-
subject.options.
|
9
|
+
it 'should create a new options Hash with symbol keys (much like Hash#symbolize_keys in rails)' do
|
10
|
+
expect(subject.options).to eq({})
|
9
11
|
|
10
|
-
subject.options = {:
|
11
|
-
subject.options.
|
12
|
+
subject.options = { abc: 123 }
|
13
|
+
expect(subject.options).to eq({ abc: 123 })
|
12
14
|
|
13
|
-
subject.options = {
|
14
|
-
subject.options.
|
15
|
+
subject.options = { 'abc' => 123 }
|
16
|
+
expect(subject.options).to eq({ abc: 123 })
|
15
17
|
end
|
16
18
|
end
|
17
|
-
end
|
19
|
+
end
|
@@ -1,67 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Vero::Api::Workers::Events::TrackAPI do
|
6
|
+
subject { Vero::Api::Workers::Events::TrackAPI.new('https://api.getvero.com', { auth_token: 'abcd', identity: { email: 'test@test.com' }, event_name: 'test_event' }) }
|
4
7
|
|
5
|
-
|
6
|
-
|
7
|
-
it "should inherit from Vero::Api::Workers::BaseCaller" do
|
8
|
-
subject.should be_a(Vero::Api::Workers::BaseAPI)
|
9
|
-
end
|
10
|
-
|
11
|
-
it "should map to current version of Vero API" do
|
12
|
-
subject.send(:url).should == "https://api.getvero.com/api/v2/events/track.json"
|
13
|
-
end
|
8
|
+
it_behaves_like 'a Vero wrapper' do
|
9
|
+
let(:end_point) { '/api/v2/events/track.json' }
|
14
10
|
end
|
15
11
|
|
16
|
-
context
|
17
|
-
subject { Vero::Api::Workers::Events::TrackAPI.new('https://api.getvero.com', {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :event_name => 'test_event'}) }
|
12
|
+
context 'request with properties' do
|
18
13
|
describe :validate! do
|
19
|
-
it
|
20
|
-
options = {:
|
14
|
+
it 'should raise an error if event_name is a blank String' do
|
15
|
+
options = { auth_token: 'abcd', identity: { email: 'test@test.com' }, event_name: nil }
|
21
16
|
subject.options = options
|
22
|
-
expect { subject.send(:validate!) }.to raise_error
|
17
|
+
expect { subject.send(:validate!) }.to raise_error(ArgumentError)
|
23
18
|
|
24
|
-
options = {:
|
19
|
+
options = { auth_token: 'abcd', identity: { email: 'test@test.com' }, event_name: 'test_event' }
|
25
20
|
subject.options = options
|
26
21
|
expect { subject.send(:validate!) }.to_not raise_error
|
27
22
|
end
|
28
23
|
|
29
|
-
it
|
30
|
-
options = {:
|
24
|
+
it 'should raise an error if data is not either nil or a Hash' do
|
25
|
+
options = { auth_token: 'abcd', identity: { email: 'test@test.com' }, event_name: 'test_event', data: [] }
|
31
26
|
subject.options = options
|
32
|
-
expect { subject.send(:validate!) }.to raise_error
|
27
|
+
expect { subject.send(:validate!) }.to raise_error(ArgumentError)
|
33
28
|
|
34
|
-
options = {:
|
29
|
+
options = { auth_token: 'abcd', identity: { email: 'test@test.com' }, event_name: 'test_event', data: nil }
|
35
30
|
subject.options = options
|
36
31
|
expect { subject.send(:validate!) }.to_not raise_error
|
37
32
|
|
38
|
-
options = {:
|
33
|
+
options = { auth_token: 'abcd', identity: { email: 'test@test.com' }, event_name: 'test_event', data: {} }
|
39
34
|
subject.options = options
|
40
35
|
expect { subject.send(:validate!) }.to_not raise_error
|
41
36
|
end
|
42
37
|
|
43
|
-
it
|
44
|
-
options = {
|
38
|
+
it 'should not raise an error when the keys are Strings' do
|
39
|
+
options = { 'auth_token' => 'abcd', 'identity' => { 'email' => 'test@test.com' }, 'event_name' => 'test_event', 'data' => {} }
|
45
40
|
subject.options = options
|
46
41
|
expect { subject.send(:validate!) }.to_not raise_error
|
47
42
|
end
|
43
|
+
|
44
|
+
it 'should not raise an error when keys are Strings for initialization' do
|
45
|
+
options = { 'auth_token' => 'abcd', 'identity' => { 'email' => 'test@test.com' }, 'event_name' => 'test_event', 'data' => {} }
|
46
|
+
expect { Vero::Api::Workers::Events::TrackAPI.new('https://api.getvero.com', options).send(:validate!) }.to_not raise_error
|
47
|
+
end
|
48
48
|
end
|
49
49
|
|
50
50
|
describe :request do
|
51
|
-
it
|
52
|
-
RestClient.
|
53
|
-
RestClient.
|
51
|
+
it 'should send a JSON request to the Vero API' do
|
52
|
+
expect(RestClient).to receive(:post).with('https://api.getvero.com/api/v2/events/track.json', { auth_token: 'abcd', identity: { email: 'test@test.com' }, event_name: 'test_event' }.to_json, { content_type: :json, accept: :json })
|
53
|
+
allow(RestClient).to receive(:post).and_return(200)
|
54
54
|
subject.send(:request)
|
55
55
|
end
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
-
describe
|
60
|
-
it
|
61
|
-
obj = Vero::Api::Workers::Events::TrackAPI.new('https://api.getvero.com', {:
|
59
|
+
describe 'integration test' do
|
60
|
+
it 'should not raise any errors' do
|
61
|
+
obj = Vero::Api::Workers::Events::TrackAPI.new('https://api.getvero.com', { auth_token: 'abcd', identity: { email: 'test@test.com' }, event_name: 'test_event' })
|
62
62
|
|
63
|
-
RestClient.
|
63
|
+
allow(RestClient).to receive(:post).and_return(200)
|
64
64
|
expect { obj.perform }.to_not raise_error
|
65
65
|
end
|
66
66
|
end
|
67
|
-
end
|
67
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Vero::Api::Workers::Users::DeleteAPI do
|
4
|
+
subject { Vero::Api::Workers::Users::DeleteAPI.new('https://api.getvero.com', {:auth_token => 'abcd', :id => '1234'}) }
|
5
|
+
|
6
|
+
it_behaves_like "a Vero wrapper" do
|
7
|
+
let(:end_point) { "/api/v2/users/delete.json" }
|
8
|
+
end
|
9
|
+
|
10
|
+
it_behaves_like "a Vero wrapper" do
|
11
|
+
let(:end_point) { "/api/v2/users/delete.json" }
|
12
|
+
end
|
13
|
+
|
14
|
+
describe :validate! do
|
15
|
+
it "should not raise an error when the keys are Strings" do
|
16
|
+
subject.options = {"auth_token" => 'abcd', "id" => '1234'}
|
17
|
+
expect { subject.send(:validate!) }.to_not raise_error
|
18
|
+
end
|
19
|
+
|
20
|
+
it "should raise an error for missing keys" do
|
21
|
+
subject.options = {"auth_token" => 'abcd'}
|
22
|
+
expect { subject.send(:validate!) }.to raise_error(ArgumentError)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe :request do
|
27
|
+
it "should send a request to the Vero API" do
|
28
|
+
RestClient.should_receive(:post).with("https://api.getvero.com/api/v2/users/delete.json", {:auth_token => 'abcd', :id => '1234'})
|
29
|
+
RestClient.stub(:post).and_return(200)
|
30
|
+
subject.send(:request)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -1,36 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Vero::Api::Workers::Users::EditAPI do
|
4
|
-
subject { Vero::Api::Workers::Users::EditAPI.new('https://api.getvero.com', {}) }
|
5
|
-
it "should inherit from Vero::Api::Workers::BaseCaller" do
|
6
|
-
subject.should be_a(Vero::Api::Workers::BaseAPI)
|
7
|
-
end
|
6
|
+
subject { Vero::Api::Workers::Users::EditAPI.new('https://api.getvero.com', { auth_token: 'abcd', email: 'test@test.com', changes: { email: 'test@test.com' } }) }
|
8
7
|
|
9
|
-
|
10
|
-
|
8
|
+
it_behaves_like 'a Vero wrapper' do
|
9
|
+
let(:end_point) { '/api/v2/users/edit.json' }
|
11
10
|
end
|
12
11
|
|
13
|
-
subject { Vero::Api::Workers::Users::EditAPI.new('https://api.getvero.com', {:auth_token => 'abcd', :email => 'test@test.com', :changes => { :email => 'test@test.com' }}) }
|
14
12
|
describe :validate! do
|
15
|
-
it
|
16
|
-
options = {
|
13
|
+
it 'should not raise an error when the keys are Strings' do
|
14
|
+
options = { 'auth_token' => 'abcd', 'email' => 'test@test.com', 'changes' => { 'email' => 'test@test.com' } }
|
17
15
|
subject.options = options
|
18
16
|
expect { subject.send(:validate!) }.to_not raise_error
|
19
17
|
end
|
20
18
|
end
|
21
19
|
|
22
20
|
describe :request do
|
23
|
-
it
|
24
|
-
RestClient.
|
25
|
-
RestClient.
|
21
|
+
it 'should send a request to the Vero API' do
|
22
|
+
expect(RestClient).to receive(:put).with('https://api.getvero.com/api/v2/users/edit.json', { auth_token: 'abcd', email: 'test@test.com', changes: { email: 'test@test.com' } }.to_json, { content_type: :json, accept: :json })
|
23
|
+
allow(RestClient).to receive(:put).and_return(200)
|
26
24
|
subject.send(:request)
|
27
25
|
end
|
28
26
|
end
|
29
27
|
|
30
|
-
describe
|
31
|
-
it
|
32
|
-
RestClient.
|
28
|
+
describe 'integration test' do
|
29
|
+
it 'should not raise any errors' do
|
30
|
+
allow(RestClient).to receive(:put).and_return(200)
|
33
31
|
expect { subject.perform }.to_not raise_error
|
34
32
|
end
|
35
33
|
end
|
36
|
-
end
|
34
|
+
end
|
@@ -1,74 +1,71 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Vero::Api::Workers::Users::EditTagsAPI do
|
4
|
-
subject { Vero::Api::Workers::Users::EditTagsAPI.new('https://api.getvero.com', {}) }
|
5
|
-
it "should inherit from Vero::Api::Workers::BaseCaller" do
|
6
|
-
subject.should be_a(Vero::Api::Workers::BaseAPI)
|
7
|
-
end
|
6
|
+
subject { Vero::Api::Workers::Users::EditTagsAPI.new('https://api.getvero.com', { auth_token: 'abcd', email: 'test@test.com', add: ['test'] }) }
|
8
7
|
|
9
|
-
|
10
|
-
|
8
|
+
it_behaves_like 'a Vero wrapper' do
|
9
|
+
let(:end_point) { '/api/v2/users/tags/edit.json' }
|
11
10
|
end
|
12
11
|
|
13
|
-
subject { Vero::Api::Workers::Users::EditTagsAPI.new('https://api.getvero.com', {:auth_token => 'abcd', :email => 'test@test.com', :add => ["test"]}) }
|
14
|
-
|
15
12
|
describe :validate! do
|
16
|
-
it
|
17
|
-
options = {:
|
13
|
+
it 'should raise an error if email is a blank String' do
|
14
|
+
options = { auth_token: 'abcd', identity: { email: 'test@test.com' }, email: nil, add: [] }
|
18
15
|
subject.options = options
|
19
|
-
expect { subject.send(:validate!) }.to raise_error
|
16
|
+
expect { subject.send(:validate!) }.to raise_error(ArgumentError)
|
20
17
|
|
21
|
-
options = {:
|
18
|
+
options = { auth_token: 'abcd', identity: { email: 'test@test.com' }, email: 'test@test.com', add: [] }
|
22
19
|
subject.options = options
|
23
20
|
expect { subject.send(:validate!) }.to_not raise_error
|
24
21
|
end
|
25
22
|
|
26
|
-
it
|
27
|
-
options = {:
|
23
|
+
it 'should raise an error if add is not an Array or missing' do
|
24
|
+
options = { auth_token: 'abcd', identity: { email: 'test@test.com' }, email: 'test@test.com', add: 'foo' }
|
28
25
|
|
29
26
|
subject.options = options
|
30
|
-
expect { subject.send(:validate!) }.to raise_error
|
27
|
+
expect { subject.send(:validate!) }.to raise_error(ArgumentError)
|
31
28
|
end
|
32
29
|
|
33
|
-
it
|
34
|
-
options = {:
|
30
|
+
it 'should raise an error if remove is not an Array or missing' do
|
31
|
+
options = { auth_token: 'abcd', identity: { email: 'test@test.com' }, email: 'test@test.com', remove: 'foo' }
|
35
32
|
|
36
33
|
subject.options = options
|
37
|
-
expect { subject.send(:validate!) }.to raise_error
|
34
|
+
expect { subject.send(:validate!) }.to raise_error(ArgumentError)
|
38
35
|
end
|
39
36
|
|
40
|
-
it
|
41
|
-
options = {:
|
37
|
+
it 'should raise an error if botha add and remove are missing' do
|
38
|
+
options = { auth_token: 'abcd', identity: { email: 'test@test.com' }, email: 'test@test.com' }
|
42
39
|
|
43
40
|
subject.options = options
|
44
|
-
expect { subject.send(:validate!) }.to raise_error
|
41
|
+
expect { subject.send(:validate!) }.to raise_error(ArgumentError)
|
45
42
|
end
|
46
43
|
|
47
|
-
it
|
48
|
-
options = {:
|
44
|
+
it 'should not raise an error if the correct arguments are passed' do
|
45
|
+
options = { auth_token: 'abcd', identity: { email: 'test@test.com' }, email: 'test@test.com', remove: ['Hi'] }
|
49
46
|
|
50
47
|
subject.options = options
|
51
48
|
expect { subject.send(:validate!) }.to_not raise_error
|
52
49
|
end
|
53
50
|
|
54
|
-
it
|
55
|
-
options = {
|
51
|
+
it 'should not raise an error when the keys are Strings' do
|
52
|
+
options = { 'auth_token' => 'abcd', 'identity' => { 'email' => 'test@test.com' }, 'email' => 'test@test.com', 'remove' => ['Hi'] }
|
56
53
|
subject.options = options
|
57
54
|
expect { subject.send(:validate!) }.to_not raise_error
|
58
55
|
end
|
59
56
|
end
|
60
57
|
|
61
58
|
describe :request do
|
62
|
-
it
|
63
|
-
RestClient.
|
64
|
-
RestClient.
|
59
|
+
it 'should send a request to the Vero API' do
|
60
|
+
expect(RestClient).to receive(:put).with('https://api.getvero.com/api/v2/users/tags/edit.json', { auth_token: 'abcd', email: 'test@test.com', add: ['test'] }.to_json, { content_type: :json, accept: :json })
|
61
|
+
allow(RestClient).to receive(:put).and_return(200)
|
65
62
|
subject.send(:request)
|
66
63
|
end
|
67
64
|
end
|
68
65
|
|
69
|
-
describe
|
70
|
-
it
|
71
|
-
RestClient.
|
66
|
+
describe 'integration test' do
|
67
|
+
it 'should not raise any errors' do
|
68
|
+
allow(RestClient).to receive(:put).and_return(200)
|
72
69
|
expect { subject.perform }.to_not raise_error
|
73
70
|
end
|
74
71
|
end
|
@@ -1,46 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Vero::Api::Workers::Users::ReidentifyAPI do
|
4
|
-
subject { Vero::Api::Workers::Users::ReidentifyAPI.new('https://api.getvero.com', {}) }
|
5
|
-
it "should inherit from Vero::Api::Workers::BaseCaller" do
|
6
|
-
subject.should be_a(Vero::Api::Workers::BaseAPI)
|
7
|
-
end
|
6
|
+
subject { Vero::Api::Workers::Users::ReidentifyAPI.new('https://api.getvero.com', { auth_token: 'abcd', id: 'test@test.com', new_id: 'test2@test.com' }) }
|
8
7
|
|
9
|
-
|
10
|
-
|
8
|
+
it_behaves_like 'a Vero wrapper' do
|
9
|
+
let(:end_point) { '/api/v2/users/reidentify.json' }
|
11
10
|
end
|
12
11
|
|
13
|
-
subject { Vero::Api::Workers::Users::ReidentifyAPI.new('https://api.getvero.com', {:auth_token => 'abcd', :id => 'test@test.com', :new_id => 'test2@test.com'}) }
|
14
12
|
describe :validate! do
|
15
|
-
it
|
16
|
-
options = {
|
13
|
+
it 'should not raise an error when the keys are Strings' do
|
14
|
+
options = { 'auth_token' => 'abcd', 'id' => 'test@test.com', 'new_id' => 'test2@test.com' }
|
17
15
|
subject.options = options
|
18
16
|
expect { subject.send(:validate!) }.to_not raise_error
|
19
17
|
end
|
20
18
|
|
21
|
-
it
|
22
|
-
subject.options = {:
|
23
|
-
expect { subject.send(:validate!) }.to raise_error
|
19
|
+
it 'should raise an error if id is missing' do
|
20
|
+
subject.options = { auth_token: 'abcd', new_id: 'test2@test.com' }
|
21
|
+
expect { subject.send(:validate!) }.to raise_error(ArgumentError)
|
24
22
|
end
|
25
23
|
|
26
|
-
it
|
27
|
-
subject.options = {:
|
28
|
-
expect { subject.send(:validate!) }.to raise_error
|
24
|
+
it 'should raise an error if new_id is missing' do
|
25
|
+
subject.options = { auth_token: 'abcd', id: 'test@test.com' }
|
26
|
+
expect { subject.send(:validate!) }.to raise_error(ArgumentError)
|
29
27
|
end
|
30
28
|
end
|
31
29
|
|
32
30
|
describe :request do
|
33
|
-
it
|
34
|
-
RestClient.
|
35
|
-
RestClient.
|
31
|
+
it 'should send a request to the Vero API' do
|
32
|
+
expect(RestClient).to receive(:put).with('https://api.getvero.com/api/v2/users/reidentify.json', { auth_token: 'abcd', id: 'test@test.com', new_id: 'test2@test.com' }.to_json, { content_type: :json, accept: :json })
|
33
|
+
allow(RestClient).to receive(:put).and_return(200)
|
36
34
|
subject.send(:request)
|
37
35
|
end
|
38
36
|
end
|
39
37
|
|
40
|
-
describe
|
41
|
-
it
|
42
|
-
RestClient.
|
38
|
+
describe 'integration test' do
|
39
|
+
it 'should not raise any errors' do
|
40
|
+
allow(RestClient).to receive(:put).and_return(200)
|
43
41
|
expect { subject.perform }.to_not raise_error
|
44
42
|
end
|
45
43
|
end
|
46
|
-
end
|
44
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Vero::Api::Workers::Users::ResubscribeAPI do
|
6
|
+
subject { Vero::Api::Workers::Users::ResubscribeAPI.new('https://api.getvero.com', { auth_token: 'abcd', id: '1234' }) }
|
7
|
+
|
8
|
+
it_behaves_like 'a Vero wrapper' do
|
9
|
+
let(:end_point) { '/api/v2/users/resubscribe.json' }
|
10
|
+
end
|
11
|
+
|
12
|
+
describe :validate! do
|
13
|
+
it 'should not raise an error when the keys are Strings' do
|
14
|
+
subject.options = { 'auth_token' => 'abcd', 'id' => '1234' }
|
15
|
+
expect { subject.send(:validate!) }.to_not raise_error
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'should raise an error for missing keys' do
|
19
|
+
subject.options = { 'auth_token' => 'abcd' }
|
20
|
+
expect { subject.send(:validate!) }.to raise_error(ArgumentError)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
describe :request do
|
25
|
+
it 'should send a request to the Vero API' do
|
26
|
+
expect(RestClient).to(
|
27
|
+
receive(:post)
|
28
|
+
.with('https://api.getvero.com/api/v2/users/resubscribe.json', { auth_token: 'abcd', id: '1234' })
|
29
|
+
)
|
30
|
+
allow(RestClient).to receive(:post).and_return(200)
|
31
|
+
|
32
|
+
subject.send(:request)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -1,68 +1,66 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'spec_helper'
|
2
4
|
|
3
5
|
describe Vero::Api::Workers::Users::TrackAPI do
|
4
|
-
subject { Vero::Api::Workers::Users::TrackAPI.new('https://api.getvero.com', {}) }
|
5
|
-
it "should inherit from Vero::Api::Workers::BaseCaller" do
|
6
|
-
subject.should be_a(Vero::Api::Workers::BaseAPI)
|
7
|
-
end
|
6
|
+
subject { Vero::Api::Workers::Users::TrackAPI.new('https://api.getvero.com', { auth_token: 'abcd', identity: { email: 'test@test.com' }, email: 'test@test.com' }) }
|
8
7
|
|
9
|
-
|
10
|
-
|
8
|
+
it_behaves_like 'a Vero wrapper' do
|
9
|
+
let(:end_point) { '/api/v2/users/track.json' }
|
11
10
|
end
|
12
11
|
|
13
|
-
subject { Vero::Api::Workers::Users::TrackAPI.new('https://api.getvero.com', {:auth_token => 'abcd', :identity => {:email => 'test@test.com'}, :email => 'test@test.com'}) }
|
14
12
|
describe :validate! do
|
15
|
-
it
|
16
|
-
options = {:
|
13
|
+
it 'should raise an error if email and id are are blank String' do
|
14
|
+
options = { auth_token: 'abcd', identity: { email: 'test@test.com' }, id: nil, email: nil }
|
17
15
|
subject.options = options
|
18
|
-
expect { subject.send(:validate!) }.to raise_error
|
16
|
+
expect { subject.send(:validate!) }.to raise_error(ArgumentError)
|
19
17
|
|
20
|
-
options = {:
|
18
|
+
options = { auth_token: 'abcd', identity: { email: 'test@test.com' }, id: nil, email: 'test@test.com' }
|
21
19
|
subject.options = options
|
22
20
|
expect { subject.send(:validate!) }.to_not raise_error
|
23
21
|
|
24
|
-
options = {:
|
22
|
+
options = { auth_token: 'abcd', identity: { email: 'test@test.com' }, id: '', email: nil }
|
25
23
|
subject.options = options
|
26
|
-
expect { subject.send(:validate!) }.to raise_error
|
24
|
+
expect { subject.send(:validate!) }.to raise_error(ArgumentError)
|
27
25
|
|
28
|
-
options = {:
|
26
|
+
options = { auth_token: 'abcd', identity: { email: 'test@test.com' }, id: 'user123', email: nil }
|
29
27
|
subject.options = options
|
30
28
|
expect { subject.send(:validate!) }.to_not raise_error
|
31
29
|
end
|
32
30
|
|
33
|
-
it
|
34
|
-
options = {:
|
31
|
+
it 'should raise an error if data is not either nil or a Hash' do
|
32
|
+
options = { auth_token: 'abcd', identity: { email: 'test@test.com' }, email: 'test@test.com', data: [] }
|
35
33
|
subject.options = options
|
36
|
-
expect { subject.send(:validate!) }.to raise_error
|
34
|
+
expect { subject.send(:validate!) }.to raise_error(ArgumentError)
|
37
35
|
|
38
|
-
options = {:
|
36
|
+
options = { auth_token: 'abcd', identity: { email: 'test@test.com' }, email: 'test@test.com', data: nil }
|
39
37
|
subject.options = options
|
40
38
|
expect { subject.send(:validate!) }.to_not raise_error
|
41
39
|
|
42
|
-
options = {:
|
40
|
+
options = { auth_token: 'abcd', identity: { email: 'test@test.com' }, email: 'test@test.com', data: {} }
|
43
41
|
subject.options = options
|
44
42
|
expect { subject.send(:validate!) }.to_not raise_error
|
45
43
|
end
|
46
44
|
|
47
|
-
it
|
48
|
-
options = {
|
45
|
+
it 'should not raise an error when the keys are Strings' do
|
46
|
+
options = { 'auth_token' => 'abcd', 'identity' => { 'email' => 'test@test.com' }, 'email' => 'test@test.com', 'data' => {} }
|
49
47
|
subject.options = options
|
50
48
|
expect { subject.send(:validate!) }.to_not raise_error
|
51
49
|
end
|
52
50
|
end
|
53
51
|
|
54
52
|
describe :request do
|
55
|
-
it
|
56
|
-
RestClient.
|
57
|
-
RestClient.
|
53
|
+
it 'should send a request to the Vero API' do
|
54
|
+
expect(RestClient).to receive(:post).with('https://api.getvero.com/api/v2/users/track.json', { auth_token: 'abcd', identity: { email: 'test@test.com' }, email: 'test@test.com' }.to_json, { content_type: :json, accept: :json })
|
55
|
+
allow(RestClient).to receive(:post).and_return(200)
|
58
56
|
subject.send(:request)
|
59
57
|
end
|
60
58
|
end
|
61
59
|
|
62
|
-
describe
|
63
|
-
it
|
64
|
-
RestClient.
|
60
|
+
describe 'integration test' do
|
61
|
+
it 'should not raise any errors' do
|
62
|
+
allow(RestClient).to receive(:post).and_return(200)
|
65
63
|
expect { subject.perform }.to_not raise_error
|
66
64
|
end
|
67
65
|
end
|
68
|
-
end
|
66
|
+
end
|