connect_client 0.1.1 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,47 +1,47 @@
1
- require 'minitest/spec'
2
- require 'minitest/autorun'
3
- require 'connect_client/event'
4
-
5
- describe ConnectClient::Event do
6
- it "should throw a validation exception if a property starts with tp_" do
7
- connect_event = proc { ConnectClient::Event.new({tp_foo: 'bar'}) }.must_raise ConnectClient::EventDataValidationError
8
- end
9
-
10
- it "should supply an id if none present" do
11
- connect_event = ConnectClient::Event.new({foo: 'bar'})
12
- uuid_regex = /[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12}/
13
-
14
- connect_event.data[:id].must_match uuid_regex
15
- end
16
-
17
- it "should pass through id supplied" do
18
- connect_event = ConnectClient::Event.new({id: :bar})
19
-
20
- connect_event.data[:id].must_equal :bar
21
- end
22
-
23
- it "should supply timestamp if none present" do
24
- iso_date = '2015-07-01T04:07:57Z'
25
- a_time = Time.parse(iso_date);
26
-
27
- Time.stub :now, a_time do
28
- connect_event = ConnectClient::Event.new({foo: 'bar'})
29
- connect_event.data[:timestamp].must_equal iso_date
30
- end
31
- end
32
-
33
- it "should turn timestamp into iso string" do
34
- iso_date = '2015-07-01T04:07:57Z'
35
- a_time = Time.parse(iso_date);
36
-
37
- connect_event = ConnectClient::Event.new({foo: 'bar', timestamp: a_time})
38
- connect_event.data[:timestamp].must_equal iso_date
39
- end
40
-
41
- it "should pass through timestamp string if supplied" do
42
- iso_date = '2015-07-01T04:07:57Z'
43
-
44
- connect_event = ConnectClient::Event.new({foo: 'bar', timestamp: iso_date})
45
- connect_event.data[:timestamp].must_equal iso_date
46
- end
1
+ require 'minitest/spec'
2
+ require 'minitest/autorun'
3
+ require 'connect_client/event'
4
+
5
+ describe ConnectClient::Event do
6
+ it "should throw a validation exception if a property starts with tp_" do
7
+ connect_event = proc { ConnectClient::Event.new({tp_foo: 'bar'}) }.must_raise ConnectClient::EventDataValidationError
8
+ end
9
+
10
+ it "should supply an id if none present" do
11
+ connect_event = ConnectClient::Event.new({foo: 'bar'})
12
+ uuid_regex = /[a-f0-9]{8}-[a-f0-9]{4}-4[a-f0-9]{3}-[89aAbB][a-f0-9]{3}-[a-f0-9]{12}/
13
+
14
+ connect_event.data[:id].must_match uuid_regex
15
+ end
16
+
17
+ it "should pass through id supplied" do
18
+ connect_event = ConnectClient::Event.new({id: :bar})
19
+
20
+ connect_event.data[:id].must_equal :bar
21
+ end
22
+
23
+ it "should supply timestamp if none present" do
24
+ iso_date = '2015-07-01T04:07:57Z'
25
+ a_time = Time.parse(iso_date);
26
+
27
+ Time.stub :now, a_time do
28
+ connect_event = ConnectClient::Event.new({foo: 'bar'})
29
+ connect_event.data[:timestamp].must_equal iso_date
30
+ end
31
+ end
32
+
33
+ it "should turn timestamp into iso string" do
34
+ iso_date = '2015-07-01T04:07:57Z'
35
+ a_time = Time.parse(iso_date);
36
+
37
+ connect_event = ConnectClient::Event.new({foo: 'bar', timestamp: a_time})
38
+ connect_event.data[:timestamp].must_equal iso_date
39
+ end
40
+
41
+ it "should pass through timestamp string if supplied" do
42
+ iso_date = '2015-07-01T04:07:57Z'
43
+
44
+ connect_event = ConnectClient::Event.new({foo: 'bar', timestamp: iso_date})
45
+ connect_event.data[:timestamp].must_equal iso_date
46
+ end
47
47
  end
@@ -1,121 +1,121 @@
1
- require 'minitest/spec'
2
- require 'minitest/autorun'
3
- require 'webmock/minitest'
4
- require 'connect_client/http/event_endpoint'
5
- require 'connect_client/event_push_response'
6
- require 'connect_client/event'
7
- require 'connect_client/configuration'
8
- require 'securerandom'
9
-
10
- describe ConnectClient::Http::EventEndpoint do
11
- before do
12
- @endpoint = ConnectClient::Http::EventEndpoint.new (ConnectClient::Configuration.new)
13
- @async_endpoint = ConnectClient::Http::EventEndpoint.new (ConnectClient::Configuration.new '', '', true)
14
- @sample_event_data = { id: SecureRandom.uuid, timestamp: Time.now.utc.iso8601, name: 'sample' }
15
- @sample_event = ConnectClient::Event.new(@sample_event_data)
16
- @sample_events_reponse = '{"sample": [{"success": true}]}'
17
- @sample_collection = 'sample'
18
- @sample_batch_data = { @sample_collection.to_sym => [@sample_event_data] }
19
- @sample_batch = { @sample_collection.to_sym => [@sample_event] }
20
- end
21
-
22
- it "should get a push response back when pushing a single event to a collection" do
23
- stub_request(:post, "https://api.getconnect.io/events/#{@sample_collection}").
24
- with(:body => @sample_event_data, :headers => { 'Accept' => 'application/json' }).
25
- to_return(:status => 200, :body => "", :headers => { 'Content-Type'=>'application/json' })
26
-
27
- response = @endpoint.push @sample_collection, @sample_event
28
-
29
- response.must_be_instance_of ConnectClient::EventPushResponse
30
- end
31
-
32
- it "should get push to overriden base_url" do
33
- overriden_url_config = ConnectClient::Configuration.new '', '', false, 'https://whatever.test'
34
- endpoint = ConnectClient::Http::EventEndpoint.new overriden_url_config
35
- stub_request(:post, "https://whatever.test/events/#{@sample_collection}").
36
- with(:body => @sample_event_data, :headers => { 'Accept' => 'application/json' }).
37
- to_return(:status => 200, :body => "", :headers => { 'Content-Type'=>'application/json' })
38
-
39
- response = endpoint.push @sample_collection, @sample_event
40
-
41
- response.must_be_instance_of ConnectClient::EventPushResponse
42
- end
43
-
44
- it "should get push response for a non sucessful error code" do
45
- overriden_url_config = ConnectClient::Configuration.new '', '', false, 'https://whatever.test'
46
- endpoint = ConnectClient::Http::EventEndpoint.new overriden_url_config
47
- stub_request(:post, "https://whatever.test/events/#{@sample_collection}").
48
- with(:body => @sample_event_data, :headers => { 'Accept' => 'application/json' }).
49
- to_return(:status => 500, :body => "", :headers => { 'Content-Type'=>'application/json' })
50
-
51
- response = endpoint.push @sample_collection, @sample_event
52
-
53
- response.http_status_code.to_s.must_equal '500'
54
- end
55
-
56
- it "should get a push response back when pushing batches" do
57
- stub_request(:post, "https://api.getconnect.io/events").
58
- with(:body => @sample_batch_data, :headers => { 'Accept' => 'application/json' }).
59
- to_return(:status => 200, :body => @sample_events_reponse, :headers => { 'Content-Type'=>'application/json' })
60
-
61
- response = @endpoint.push_batch @sample_batch
62
- response.must_be_instance_of ConnectClient::EventPushResponse
63
- end
64
-
65
- it "should get a push response back when pushing a single event to a collection async" do
66
- stub_request(:post, "https://api.getconnect.io/events/#{@sample_collection}").
67
- with(:body => @sample_event_data, :headers => { 'Accept' => 'application/json' }).
68
- to_return(:status => 200, :body => "", :headers => { 'Content-Type'=>'application/json' })
69
-
70
- EM.run do
71
- @async_endpoint.push(@sample_collection, @sample_event).response_received { |response|
72
- begin
73
- response.must_be_instance_of ConnectClient::EventPushResponse
74
- ensure
75
- EM.stop
76
- end
77
- }.error_occured { |error|
78
- EM.stop
79
- raise error
80
- }
81
- end
82
- end
83
-
84
- it "should get push response for a non sucessful error code async" do
85
- stub_request(:post, "https://api.getconnect.io/events/#{@sample_collection}").
86
- with(:body => @sample_event_data, :headers => { 'Accept' => 'application/json' }).
87
- to_return(:status => 500, :body => "", :headers => { 'Content-Type'=>'application/json' })
88
-
89
- EM.run do
90
- @async_endpoint.push(@sample_collection, @sample_event).response_received { |response|
91
- begin
92
- response.http_status_code.to_s.must_equal '500'
93
- ensure
94
- EM.stop
95
- end
96
- }.error_occured { |error|
97
- EM.stop
98
- raise error
99
- }
100
- end
101
- end
102
-
103
- it "should get a push response back when pushing batches" do
104
- stub_request(:post, "https://api.getconnect.io/events").
105
- with(:body => @sample_batch_data, :headers => { 'Accept' => 'application/json' }).
106
- to_return(:status => 200, :body => @sample_events_reponse, :headers => { 'Content-Type'=>'application/json' })
107
-
108
- EM.run do
109
- @async_endpoint.push_batch(@sample_batch).response_received { |response|
110
- begin
111
- response.must_be_instance_of ConnectClient::EventPushResponse
112
- ensure
113
- EM.stop
114
- end
115
- }.error_occured { |error|
116
- EM.stop
117
- raise error
118
- }
119
- end
120
- end
1
+ require 'minitest/spec'
2
+ require 'minitest/autorun'
3
+ require 'webmock/minitest'
4
+ require 'connect_client/http/event_endpoint'
5
+ require 'connect_client/event_push_response'
6
+ require 'connect_client/event'
7
+ require 'connect_client/configuration'
8
+ require 'securerandom'
9
+
10
+ describe ConnectClient::Http::EventEndpoint do
11
+ before do
12
+ @endpoint = ConnectClient::Http::EventEndpoint.new (ConnectClient::Configuration.new)
13
+ @async_endpoint = ConnectClient::Http::EventEndpoint.new (ConnectClient::Configuration.new '', '', true)
14
+ @sample_event_data = { id: SecureRandom.uuid, timestamp: Time.now.utc.iso8601, name: 'sample' }
15
+ @sample_event = ConnectClient::Event.new(@sample_event_data)
16
+ @sample_events_reponse = '{"sample": [{"success": true}]}'
17
+ @sample_collection = 'sample'
18
+ @sample_batch_data = { @sample_collection.to_sym => [@sample_event_data] }
19
+ @sample_batch = { @sample_collection.to_sym => [@sample_event] }
20
+ end
21
+
22
+ it "should get a push response back when pushing a single event to a collection" do
23
+ stub_request(:post, "https://api.getconnect.io/events/#{@sample_collection}").
24
+ with(:body => @sample_event_data, :headers => { 'Accept' => 'application/json' }).
25
+ to_return(:status => 200, :body => "", :headers => { 'Content-Type'=>'application/json' })
26
+
27
+ response = @endpoint.push @sample_collection, @sample_event
28
+
29
+ response.must_be_instance_of ConnectClient::EventPushResponse
30
+ end
31
+
32
+ it "should get push to overriden base_url" do
33
+ overriden_url_config = ConnectClient::Configuration.new '', '', false, 'https://whatever.test'
34
+ endpoint = ConnectClient::Http::EventEndpoint.new overriden_url_config
35
+ stub_request(:post, "https://whatever.test/events/#{@sample_collection}").
36
+ with(:body => @sample_event_data, :headers => { 'Accept' => 'application/json' }).
37
+ to_return(:status => 200, :body => "", :headers => { 'Content-Type'=>'application/json' })
38
+
39
+ response = endpoint.push @sample_collection, @sample_event
40
+
41
+ response.must_be_instance_of ConnectClient::EventPushResponse
42
+ end
43
+
44
+ it "should get push response for a non sucessful error code" do
45
+ overriden_url_config = ConnectClient::Configuration.new '', '', false, 'https://whatever.test'
46
+ endpoint = ConnectClient::Http::EventEndpoint.new overriden_url_config
47
+ stub_request(:post, "https://whatever.test/events/#{@sample_collection}").
48
+ with(:body => @sample_event_data, :headers => { 'Accept' => 'application/json' }).
49
+ to_return(:status => 500, :body => "", :headers => { 'Content-Type'=>'application/json' })
50
+
51
+ response = endpoint.push @sample_collection, @sample_event
52
+
53
+ response.http_status_code.to_s.must_equal '500'
54
+ end
55
+
56
+ it "should get a push response back when pushing batches" do
57
+ stub_request(:post, "https://api.getconnect.io/events").
58
+ with(:body => @sample_batch_data, :headers => { 'Accept' => 'application/json' }).
59
+ to_return(:status => 200, :body => @sample_events_reponse, :headers => { 'Content-Type'=>'application/json' })
60
+
61
+ response = @endpoint.push_batch @sample_batch
62
+ response.must_be_instance_of ConnectClient::EventPushResponse
63
+ end
64
+
65
+ it "should get a push response back when pushing a single event to a collection async" do
66
+ stub_request(:post, "https://api.getconnect.io/events/#{@sample_collection}").
67
+ with(:body => @sample_event_data, :headers => { 'Accept' => 'application/json' }).
68
+ to_return(:status => 200, :body => "", :headers => { 'Content-Type'=>'application/json' })
69
+
70
+ EM.run do
71
+ @async_endpoint.push(@sample_collection, @sample_event).response_received { |response|
72
+ begin
73
+ response.must_be_instance_of ConnectClient::EventPushResponse
74
+ ensure
75
+ EM.stop
76
+ end
77
+ }.error_occured { |error|
78
+ EM.stop
79
+ raise error
80
+ }
81
+ end
82
+ end
83
+
84
+ it "should get push response for a non sucessful error code async" do
85
+ stub_request(:post, "https://api.getconnect.io/events/#{@sample_collection}").
86
+ with(:body => @sample_event_data, :headers => { 'Accept' => 'application/json' }).
87
+ to_return(:status => 500, :body => "", :headers => { 'Content-Type'=>'application/json' })
88
+
89
+ EM.run do
90
+ @async_endpoint.push(@sample_collection, @sample_event).response_received { |response|
91
+ begin
92
+ response.http_status_code.to_s.must_equal '500'
93
+ ensure
94
+ EM.stop
95
+ end
96
+ }.error_occured { |error|
97
+ EM.stop
98
+ raise error
99
+ }
100
+ end
101
+ end
102
+
103
+ it "should get a push response back when pushing batches" do
104
+ stub_request(:post, "https://api.getconnect.io/events").
105
+ with(:body => @sample_batch_data, :headers => { 'Accept' => 'application/json' }).
106
+ to_return(:status => 200, :body => @sample_events_reponse, :headers => { 'Content-Type'=>'application/json' })
107
+
108
+ EM.run do
109
+ @async_endpoint.push_batch(@sample_batch).response_received { |response|
110
+ begin
111
+ response.must_be_instance_of ConnectClient::EventPushResponse
112
+ ensure
113
+ EM.stop
114
+ end
115
+ }.error_occured { |error|
116
+ EM.stop
117
+ raise error
118
+ }
119
+ end
120
+ end
121
121
  end
@@ -1,60 +1,60 @@
1
- require 'minitest/spec'
2
- require 'minitest/autorun'
3
- require 'webmock/minitest'
4
- require 'connect_client/client'
5
- require 'connect_client/configuration'
6
- require 'connect_client/event_push_response'
7
- require 'securerandom'
8
- require 'em-synchrony'
9
- require 'em-synchrony/em-http'
10
-
11
- describe ConnectClient::Http::EventEndpoint, "Test with syncrony defined" do
12
- before do
13
- @async_endpoint = ConnectClient::Http::EventEndpoint.new (ConnectClient::Configuration.new '', '', true)
14
- @sample_event_data = { id: SecureRandom.uuid, timestamp: Time.now.utc.iso8601, name: 'sample' }
15
- @sample_event = ConnectClient::Event.new(@sample_event_data)
16
- @sample_events_reponse = '{"sample": [{"success": true}]}'
17
- @sample_collection = 'sample'
18
- @sample_batch_data = { @sample_collection.to_sym => [@sample_event_data] }
19
- @sample_batch = { @sample_collection.to_sym => [@sample_event] }
20
- end
21
-
22
- it "should get a push response back when pushing a single event to a collection" do
23
- stub_request(:post, "https://api.getconnect.io/events/#{@sample_collection}").
24
- with(:body => @sample_event_data).
25
- to_return(:status => 200, :body => "", :headers => { 'Content-Type'=>'application/json' })
26
-
27
- response = nil
28
- EM.synchrony do
29
- response = @async_endpoint.push @sample_collection, @sample_event
30
- EM.stop
31
- end
32
- response.must_be_instance_of ConnectClient::EventPushResponse
33
- end
34
-
35
- it "should get push response for a non sucessful error code" do
36
- stub_request(:post, "https://api.getconnect.io/events/#{@sample_collection}").
37
- with(:body => @sample_event_data).
38
- to_return(:status => 500, :body => "", :headers => { 'Content-Type'=>'application/json' })
39
-
40
- response = nil
41
- EM.synchrony do
42
- response = @async_endpoint.push @sample_collection, @sample_event
43
- EM.stop
44
- end
45
- response.http_status_code.to_s.must_equal '500'
46
- end
47
-
48
- it "should get a push response back when pushing batches" do
49
- stub_request(:post, "https://api.getconnect.io/events").
50
- with(:body => @sample_batch_data).
51
- to_return(:status => 200, :body => @sample_events_reponse, :headers => { 'Content-Type'=>'application/json' })
52
-
53
- response = nil
54
- EM.synchrony do
55
- response = @async_endpoint.push_batch @sample_batch
56
- EM.stop
57
- end
58
- response.must_be_instance_of ConnectClient::EventPushResponse
59
- end
1
+ require 'minitest/spec'
2
+ require 'minitest/autorun'
3
+ require 'webmock/minitest'
4
+ require 'connect_client/client'
5
+ require 'connect_client/configuration'
6
+ require 'connect_client/event_push_response'
7
+ require 'securerandom'
8
+ require 'em-synchrony'
9
+ require 'em-synchrony/em-http'
10
+
11
+ describe ConnectClient::Http::EventEndpoint, "Test with syncrony defined" do
12
+ before do
13
+ @async_endpoint = ConnectClient::Http::EventEndpoint.new (ConnectClient::Configuration.new '', '', true)
14
+ @sample_event_data = { id: SecureRandom.uuid, timestamp: Time.now.utc.iso8601, name: 'sample' }
15
+ @sample_event = ConnectClient::Event.new(@sample_event_data)
16
+ @sample_events_reponse = '{"sample": [{"success": true}]}'
17
+ @sample_collection = 'sample'
18
+ @sample_batch_data = { @sample_collection.to_sym => [@sample_event_data] }
19
+ @sample_batch = { @sample_collection.to_sym => [@sample_event] }
20
+ end
21
+
22
+ it "should get a push response back when pushing a single event to a collection" do
23
+ stub_request(:post, "https://api.getconnect.io/events/#{@sample_collection}").
24
+ with(:body => @sample_event_data).
25
+ to_return(:status => 200, :body => "", :headers => { 'Content-Type'=>'application/json' })
26
+
27
+ response = nil
28
+ EM.synchrony do
29
+ response = @async_endpoint.push @sample_collection, @sample_event
30
+ EM.stop
31
+ end
32
+ response.must_be_instance_of ConnectClient::EventPushResponse
33
+ end
34
+
35
+ it "should get push response for a non sucessful error code" do
36
+ stub_request(:post, "https://api.getconnect.io/events/#{@sample_collection}").
37
+ with(:body => @sample_event_data).
38
+ to_return(:status => 500, :body => "", :headers => { 'Content-Type'=>'application/json' })
39
+
40
+ response = nil
41
+ EM.synchrony do
42
+ response = @async_endpoint.push @sample_collection, @sample_event
43
+ EM.stop
44
+ end
45
+ response.http_status_code.to_s.must_equal '500'
46
+ end
47
+
48
+ it "should get a push response back when pushing batches" do
49
+ stub_request(:post, "https://api.getconnect.io/events").
50
+ with(:body => @sample_batch_data).
51
+ to_return(:status => 200, :body => @sample_events_reponse, :headers => { 'Content-Type'=>'application/json' })
52
+
53
+ response = nil
54
+ EM.synchrony do
55
+ response = @async_endpoint.push_batch @sample_batch
56
+ EM.stop
57
+ end
58
+ response.must_be_instance_of ConnectClient::EventPushResponse
59
+ end
60
60
  end