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,3 +1,3 @@
1
1
  module ConnectClient
2
- VERSION = "0.1.1"
3
- end
2
+ VERSION = "0.1.3"
3
+ end
@@ -1,48 +1,48 @@
1
- require 'minitest/spec'
2
- require 'minitest/autorun'
3
- require 'webmock/minitest'
4
- require 'connect_client/client'
5
- require 'connect_client/event_push_response'
6
- require 'connect_client/configuration'
7
- require 'securerandom'
8
-
9
- describe ConnectClient::Client do
10
- before do
11
- @client = ConnectClient::Client.new (ConnectClient::Configuration.new)
12
- @async_client = ConnectClient::Client.new (ConnectClient::Configuration.new '', '', true)
13
- @sample_event = { id: SecureRandom.uuid, timestamp: Time.now.utc.iso8601, name: 'sample' }
14
- @sample_events = [@sample_event]
15
- @sample_events_reponse = '{"sample": [{"success": true}]}'
16
- @sample_collection = 'sample'
17
- end
18
-
19
- it "should get a push response back when pushing a single event to a collection" do
20
- stub_request(:post, "https://api.getconnect.io/events/#{@sample_collection}").
21
- with(:body => @sample_event).
22
- to_return(:status => 200, :body => "", :headers => { 'Content-Type'=>'application/json' })
23
-
24
- response = @client.push @sample_collection, @sample_event
25
-
26
- response.must_be_instance_of ConnectClient::EventPushResponse
27
- end
28
-
29
- it "should get a push response back when pushing multiple events to a collection" do
30
- stub_request(:post, "https://api.getconnect.io/events").
31
- with(:body => { @sample_collection.to_sym => @sample_events }).
32
- to_return(:status => 200, :body => @sample_events_reponse, :headers => { 'Content-Type'=>'application/json' })
33
-
34
- response = @client.push @sample_collection, @sample_events
35
-
36
- response.must_be_instance_of ConnectClient::EventPushResponse
37
- end
38
-
39
- it "should get a push response back when pushing batches" do
40
- batch = { @sample_collection.to_sym => @sample_events }
41
- stub_request(:post, "https://api.getconnect.io/events").
42
- with(:body => batch).
43
- to_return(:status => 200, :body => @sample_events_reponse, :headers => { 'Content-Type'=>'application/json' })
44
-
45
- response = @client.push batch
46
- response.must_be_instance_of ConnectClient::EventPushResponse
47
- end
1
+ require 'minitest/spec'
2
+ require 'minitest/autorun'
3
+ require 'webmock/minitest'
4
+ require 'connect_client/client'
5
+ require 'connect_client/event_push_response'
6
+ require 'connect_client/configuration'
7
+ require 'securerandom'
8
+
9
+ describe ConnectClient::Client do
10
+ before do
11
+ @client = ConnectClient::Client.new (ConnectClient::Configuration.new)
12
+ @async_client = ConnectClient::Client.new (ConnectClient::Configuration.new '', '', true)
13
+ @sample_event = { id: SecureRandom.uuid, timestamp: Time.now.utc.iso8601, name: 'sample' }
14
+ @sample_events = [@sample_event]
15
+ @sample_events_reponse = '{"sample": [{"success": true}]}'
16
+ @sample_collection = 'sample'
17
+ end
18
+
19
+ it "should get a push response back when pushing a single event to a collection" do
20
+ stub_request(:post, "https://api.getconnect.io/events/#{@sample_collection}").
21
+ with(:body => @sample_event).
22
+ to_return(:status => 200, :body => "", :headers => { 'Content-Type'=>'application/json' })
23
+
24
+ response = @client.push @sample_collection, @sample_event
25
+
26
+ response.must_be_instance_of ConnectClient::EventPushResponse
27
+ end
28
+
29
+ it "should get a push response back when pushing multiple events to a collection" do
30
+ stub_request(:post, "https://api.getconnect.io/events").
31
+ with(:body => { @sample_collection.to_sym => @sample_events }).
32
+ to_return(:status => 200, :body => @sample_events_reponse, :headers => { 'Content-Type'=>'application/json' })
33
+
34
+ response = @client.push @sample_collection, @sample_events
35
+
36
+ response.must_be_instance_of ConnectClient::EventPushResponse
37
+ end
38
+
39
+ it "should get a push response back when pushing batches" do
40
+ batch = { @sample_collection.to_sym => @sample_events }
41
+ stub_request(:post, "https://api.getconnect.io/events").
42
+ with(:body => batch).
43
+ to_return(:status => 200, :body => @sample_events_reponse, :headers => { 'Content-Type'=>'application/json' })
44
+
45
+ response = @client.push batch
46
+ response.must_be_instance_of ConnectClient::EventPushResponse
47
+ end
48
48
  end
@@ -1,55 +1,55 @@
1
- require 'minitest/spec'
2
- require 'minitest/autorun'
3
- require 'connect_client/configuration'
4
-
5
- describe ConnectClient::Configuration do
6
-
7
- it "should default the base_url to production" do
8
- config = ConnectClient::Configuration.new
9
-
10
- config.base_url.must_equal 'https://api.getconnect.io'
11
- end
12
-
13
- it "should default async to false" do
14
- config = ConnectClient::Configuration.new
15
-
16
- config.async.must_equal false
17
- end
18
-
19
- it "should support setting the project id" do
20
- config = ConnectClient::Configuration.new
21
- id = 'id'
22
-
23
- config.project_id = id
24
-
25
- config.project_id.must_equal id
26
- end
27
-
28
- it "should support setting the push key" do
29
- config = ConnectClient::Configuration.new
30
- key = 'key'
31
-
32
- config.api_key = key
33
-
34
- config.api_key.must_equal key
35
- end
36
-
37
- it "should support setting whether requests are async" do
38
- config = ConnectClient::Configuration.new
39
- async = true
40
-
41
- config.async = async
42
-
43
- config.async.must_equal async
44
- end
45
-
46
- it "should support setting the base url" do
47
- config = ConnectClient::Configuration.new
48
- url = 'url'
49
-
50
- config.base_url = url
51
-
52
- config.base_url.must_equal url
53
- end
54
-
1
+ require 'minitest/spec'
2
+ require 'minitest/autorun'
3
+ require 'connect_client/configuration'
4
+
5
+ describe ConnectClient::Configuration do
6
+
7
+ it "should default the base_url to production" do
8
+ config = ConnectClient::Configuration.new
9
+
10
+ config.base_url.must_equal 'https://api.getconnect.io'
11
+ end
12
+
13
+ it "should default async to false" do
14
+ config = ConnectClient::Configuration.new
15
+
16
+ config.async.must_equal false
17
+ end
18
+
19
+ it "should support setting the project id" do
20
+ config = ConnectClient::Configuration.new
21
+ id = 'id'
22
+
23
+ config.project_id = id
24
+
25
+ config.project_id.must_equal id
26
+ end
27
+
28
+ it "should support setting the push key" do
29
+ config = ConnectClient::Configuration.new
30
+ key = 'key'
31
+
32
+ config.api_key = key
33
+
34
+ config.api_key.must_equal key
35
+ end
36
+
37
+ it "should support setting whether requests are async" do
38
+ config = ConnectClient::Configuration.new
39
+ async = true
40
+
41
+ config.async = async
42
+
43
+ config.async.must_equal async
44
+ end
45
+
46
+ it "should support setting the base url" do
47
+ config = ConnectClient::Configuration.new
48
+ url = 'url'
49
+
50
+ config.base_url = url
51
+
52
+ config.base_url.must_equal url
53
+ end
54
+
55
55
  end
@@ -1,150 +1,150 @@
1
- require 'minitest/spec'
2
- require 'minitest/autorun'
3
- require 'connect_client/event'
4
- require 'connect_client/event_push_response'
5
-
6
-
7
- describe ConnectClient::EventPushResponse do
8
- before do
9
- @json_content_type = 'application/json; charset=utf-8'
10
- @sample_event = ConnectClient::Event.new({name: 'test'})
11
- @sample_event_data = @sample_event.data
12
- end
13
-
14
- it "should be successful when status code is 201" do
15
-
16
- body = ''
17
- code = 201
18
-
19
- event_response = ConnectClient::EventPushResponse.new code, @json_content_type, body, @sample_event
20
-
21
- event_response.success?.must_equal true
22
- end
23
-
24
- it "should pass through string body if content type is not json" do
25
-
26
- body = ''
27
- code = 500
28
-
29
- event_response = ConnectClient::EventPushResponse.new code, @json_content_type, body, @sample_event
30
-
31
- event_response.success?.must_equal false
32
- end
33
-
34
- it "should not be successful when status code is 500" do
35
-
36
- body = ''
37
- code = 500
38
-
39
- event_response = ConnectClient::EventPushResponse.new code, @json_content_type, body, @sample_event
40
-
41
- event_response.success?.must_equal false
42
- end
43
-
44
- it "should not parse body that is not json content" do
45
-
46
- content_type = 'text/html'
47
- body = '<html><html>'
48
- code = 500
49
-
50
- event_response = ConnectClient::EventPushResponse.new code, content_type, body, @sample_event
51
-
52
- event_response.data.must_equal body
53
- end
54
-
55
- it "should set status code even if body is not json content" do
56
-
57
- content_type = 'text/html'
58
- body = '<html><html>'
59
- code = 500
60
-
61
- event_response = ConnectClient::EventPushResponse.new code, content_type, body, @sample_event
62
-
63
- event_response.http_status_code.must_equal '500'
64
- end
65
-
66
-
67
- it "should pass through error message in data" do
68
-
69
- body = '{ "errorMessage": "something went wrong" }'
70
- code = 500
71
-
72
- event_response = ConnectClient::EventPushResponse.new code, @json_content_type, body, @sample_event
73
-
74
- event_response.data[:errorMessage].must_equal 'something went wrong'
75
- end
76
-
77
- it "should pass back event in response when successful" do
78
-
79
- body = ''
80
- code = 200
81
-
82
- event_response = ConnectClient::EventPushResponse.new code, @json_content_type, body, @sample_event
83
-
84
- event_response.data[:event].must_be_same_as @sample_event_data
85
- end
86
-
87
- it "should pass through original event with error" do
88
-
89
-
90
- body = '{ "errorMessage": "something went wrong" }'
91
- code = 500
92
-
93
- event_response = ConnectClient::EventPushResponse.new code, @json_content_type, body, @sample_event
94
-
95
- event_response.data[:event].must_be_same_as @sample_event_data
96
- end
97
-
98
- it "should pass through success status under collection name for batch" do
99
-
100
-
101
- body = %@
102
- {
103
- "collectionName": [{
104
- "success": true
105
- }]
106
- }
107
- @
108
- code = 200
109
-
110
- events = { :collectionName => [@sample_event] }
111
- event_response = ConnectClient::EventPushResponse.new code, @json_content_type, body, events
112
-
113
- event_response.data[:collectionName][0][:success].must_equal true
114
- end
115
-
116
- it "should pass through duplicate status under collection name for batch" do
117
-
118
-
119
- body = %@
120
- {
121
- "collectionName": [{
122
- "duplicate": true
123
- }]
124
- }
125
- @
126
- code = 200
127
-
128
- events = { :collectionName => [@sample_event] }
129
- event_response = ConnectClient::EventPushResponse.new code, @json_content_type, body, events
130
-
131
- event_response.data[:collectionName][0][:duplicate].must_equal true
132
- end
133
-
134
- it "should show event under collection name for batch" do
135
-
136
- body = %@
137
- {
138
- "collectionName": [{
139
- "success": true
140
- }]
141
- }
142
- @
143
- code = 200
144
-
145
- events = { :collectionName => [@sample_event] }
146
- event_response = ConnectClient::EventPushResponse.new code, @json_content_type, body, events
147
-
148
- event_response.data[:collectionName][0][:event].must_be_same_as @sample_event_data
149
- end
1
+ require 'minitest/spec'
2
+ require 'minitest/autorun'
3
+ require 'connect_client/event'
4
+ require 'connect_client/event_push_response'
5
+
6
+
7
+ describe ConnectClient::EventPushResponse do
8
+ before do
9
+ @json_content_type = 'application/json; charset=utf-8'
10
+ @sample_event = ConnectClient::Event.new({name: 'test'})
11
+ @sample_event_data = @sample_event.data
12
+ end
13
+
14
+ it "should be successful when status code is 201" do
15
+
16
+ body = ''
17
+ code = 201
18
+
19
+ event_response = ConnectClient::EventPushResponse.new code, @json_content_type, body, @sample_event
20
+
21
+ event_response.success?.must_equal true
22
+ end
23
+
24
+ it "should pass through string body if content type is not json" do
25
+
26
+ body = ''
27
+ code = 500
28
+
29
+ event_response = ConnectClient::EventPushResponse.new code, @json_content_type, body, @sample_event
30
+
31
+ event_response.success?.must_equal false
32
+ end
33
+
34
+ it "should not be successful when status code is 500" do
35
+
36
+ body = ''
37
+ code = 500
38
+
39
+ event_response = ConnectClient::EventPushResponse.new code, @json_content_type, body, @sample_event
40
+
41
+ event_response.success?.must_equal false
42
+ end
43
+
44
+ it "should not parse body that is not json content" do
45
+
46
+ content_type = 'text/html'
47
+ body = '<html><html>'
48
+ code = 500
49
+
50
+ event_response = ConnectClient::EventPushResponse.new code, content_type, body, @sample_event
51
+
52
+ event_response.data.must_equal body
53
+ end
54
+
55
+ it "should set status code even if body is not json content" do
56
+
57
+ content_type = 'text/html'
58
+ body = '<html><html>'
59
+ code = 500
60
+
61
+ event_response = ConnectClient::EventPushResponse.new code, content_type, body, @sample_event
62
+
63
+ event_response.http_status_code.must_equal '500'
64
+ end
65
+
66
+
67
+ it "should pass through error message in data" do
68
+
69
+ body = '{ "errorMessage": "something went wrong" }'
70
+ code = 500
71
+
72
+ event_response = ConnectClient::EventPushResponse.new code, @json_content_type, body, @sample_event
73
+
74
+ event_response.data[:errorMessage].must_equal 'something went wrong'
75
+ end
76
+
77
+ it "should pass back event in response when successful" do
78
+
79
+ body = ''
80
+ code = 200
81
+
82
+ event_response = ConnectClient::EventPushResponse.new code, @json_content_type, body, @sample_event
83
+
84
+ event_response.data[:event].must_be_same_as @sample_event_data
85
+ end
86
+
87
+ it "should pass through original event with error" do
88
+
89
+
90
+ body = '{ "errorMessage": "something went wrong" }'
91
+ code = 500
92
+
93
+ event_response = ConnectClient::EventPushResponse.new code, @json_content_type, body, @sample_event
94
+
95
+ event_response.data[:event].must_be_same_as @sample_event_data
96
+ end
97
+
98
+ it "should pass through success status under collection name for batch" do
99
+
100
+
101
+ body = %@
102
+ {
103
+ "collectionName": [{
104
+ "success": true
105
+ }]
106
+ }
107
+ @
108
+ code = 200
109
+
110
+ events = { :collectionName => [@sample_event] }
111
+ event_response = ConnectClient::EventPushResponse.new code, @json_content_type, body, events
112
+
113
+ event_response.data[:collectionName][0][:success].must_equal true
114
+ end
115
+
116
+ it "should pass through duplicate status under collection name for batch" do
117
+
118
+
119
+ body = %@
120
+ {
121
+ "collectionName": [{
122
+ "duplicate": true
123
+ }]
124
+ }
125
+ @
126
+ code = 200
127
+
128
+ events = { :collectionName => [@sample_event] }
129
+ event_response = ConnectClient::EventPushResponse.new code, @json_content_type, body, events
130
+
131
+ event_response.data[:collectionName][0][:duplicate].must_equal true
132
+ end
133
+
134
+ it "should show event under collection name for batch" do
135
+
136
+ body = %@
137
+ {
138
+ "collectionName": [{
139
+ "success": true
140
+ }]
141
+ }
142
+ @
143
+ code = 200
144
+
145
+ events = { :collectionName => [@sample_event] }
146
+ event_response = ConnectClient::EventPushResponse.new code, @json_content_type, body, events
147
+
148
+ event_response.data[:collectionName][0][:event].must_be_same_as @sample_event_data
149
+ end
150
150
  end