drip-ruby 2.0.0 → 3.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,40 +2,32 @@ require File.dirname(__FILE__) + '/../../test_helper.rb'
2
2
 
3
3
  class Drip::Client::OrdersTest < Drip::TestCase
4
4
  def setup
5
- @stubs = Faraday::Adapter::Test::Stubs.new
6
-
7
- @connection = Faraday.new do |builder|
8
- builder.adapter :test, @stubs
9
- end
10
-
11
5
  @client = Drip::Client.new { |c| c.account_id = "12345" }
12
- @client.expects(:connection).at_least_once.returns(@connection)
13
6
  end
14
7
 
15
8
  context "#create_or_update_order" do
16
9
  setup do
17
10
  @email = "drippy@drip.com"
18
11
  @options = {
19
- "email": @email,
20
- "provider": "shopify",
21
- "upstream_id": "abcdef",
22
- "amount": 4900,
23
- "tax": 100,
24
- "fees": 0,
25
- "discount": 0,
26
- "currency_code": "USD",
27
- "properties": {
28
- "size": "medium",
29
- "color": "red"
12
+ "email" => @email,
13
+ "provider" => "shopify",
14
+ "upstream_id" => "abcdef",
15
+ "amount" => 4900,
16
+ "tax" => 100,
17
+ "fees" => 0,
18
+ "discount" => 0,
19
+ "currency_code" => "USD",
20
+ "properties" => {
21
+ "size" => "medium",
22
+ "color" => "red"
30
23
  }
31
24
  }
32
25
  @payload = { "orders" => [@options] }.to_json
33
26
  @response_status = 202
34
- @response_body = stub
27
+ @response_body = "stub"
35
28
 
36
- @stubs.post "12345/orders", @payload do
37
- [@response_status, {}, @response_body]
38
- end
29
+ stub_request(:post, "https://api.getdrip.com/v2/12345/orders").
30
+ to_return(status: @response_status, body: @response_body, headers: {})
39
31
  end
40
32
 
41
33
  should "send the correct request" do
@@ -48,42 +40,41 @@ class Drip::Client::OrdersTest < Drip::TestCase
48
40
  setup do
49
41
  @orders = [
50
42
  {
51
- "email": "drippy@drip.com",
52
- "provider": "shopify",
53
- "upstream_id": "abcdef",
54
- "amount": 4900,
55
- "tax": 100,
56
- "fees": 0,
57
- "discount": 0,
58
- "currency_code": "USD",
59
- "properties": {
60
- "size": "medium",
61
- "color": "red"
43
+ "email" => "drippy@drip.com",
44
+ "provider" => "shopify",
45
+ "upstream_id" => "abcdef",
46
+ "amount" => 4900,
47
+ "tax" => 100,
48
+ "fees" => 0,
49
+ "discount" => 0,
50
+ "currency_code" => "USD",
51
+ "properties" => {
52
+ "size" => "medium",
53
+ "color" => "red"
62
54
  }
63
55
  },
64
56
  {
65
- "email": "dripster@drip.com",
66
- "provider": "shopify",
67
- "upstream_id": "abcdef",
68
- "amount": 1500,
69
- "tax": 10,
70
- "fees": 0,
71
- "discount": 0,
72
- "currency_code": "SGD",
73
- "properties": {
74
- "size": "medium",
75
- "color": "black"
57
+ "email" => "dripster@drip.com",
58
+ "provider" => "shopify",
59
+ "upstream_id" => "abcdef",
60
+ "amount" => 1500,
61
+ "tax" => 10,
62
+ "fees" => 0,
63
+ "discount" => 0,
64
+ "currency_code" => "SGD",
65
+ "properties" => {
66
+ "size" => "medium",
67
+ "color" => "black"
76
68
  }
77
69
  }
78
70
  ]
79
71
 
80
72
  @payload = { "batches" => [{ "orders" => @orders }] }.to_json
81
73
  @response_status = 202
82
- @response_body = stub
74
+ @response_body = "stub"
83
75
 
84
- @stubs.post "12345/orders/batches", @payload do
85
- [@response_status, {}, @response_body]
86
- end
76
+ stub_request(:post, "https://api.getdrip.com/v2/12345/orders/batches").
77
+ to_return(status: @response_status, body: @response_body, headers: {})
87
78
  end
88
79
 
89
80
  should "send the correct request" do
@@ -95,21 +86,20 @@ class Drip::Client::OrdersTest < Drip::TestCase
95
86
  context "#create_or_update_refund" do
96
87
  setup do
97
88
  @options = {
98
- "provider": "shopify",
99
- "order_upstream_id": "abcdef",
100
- "amount": 4900,
101
- "upstream_id": "tuvwx",
102
- "note": "Incorrect size",
103
- "processed_at": "2013-06-22T10:41:11Z"
89
+ "provider" => "shopify",
90
+ "order_upstream_id" => "abcdef",
91
+ "amount" => 4900,
92
+ "upstream_id" => "tuvwx",
93
+ "note" => "Incorrect size",
94
+ "processed_at" => "2013-06-22T10:41:11Z"
104
95
  }
105
96
 
106
97
  @payload = { "refunds" => [@options] }.to_json
107
98
  @response_status = 202
108
- @response_body = stub
99
+ @response_body = "stub"
109
100
 
110
- @stubs.post "12345/refunds", @payload do
111
- [@response_status, {}, @response_body]
112
- end
101
+ stub_request(:post, "https://api.getdrip.com/v2/12345/refunds").
102
+ to_return(status: @response_status, body: @response_body, headers: {})
113
103
  end
114
104
 
115
105
  should "send the correct request" do
@@ -2,24 +2,16 @@ require File.dirname(__FILE__) + '/../../test_helper.rb'
2
2
 
3
3
  class Drip::Client::SubscribersTest < Drip::TestCase
4
4
  def setup
5
- @stubs = Faraday::Adapter::Test::Stubs.new
6
-
7
- @connection = Faraday.new do |builder|
8
- builder.adapter :test, @stubs
9
- end
10
-
11
5
  @client = Drip::Client.new { |c| c.account_id = "12345" }
12
- @client.expects(:connection).at_least_once.returns(@connection)
13
6
  end
14
7
 
15
8
  context "#subscribers" do
16
9
  setup do
17
10
  @response_status = 200
18
- @response_body = stub
11
+ @response_body = "stub"
19
12
 
20
- @stubs.get "12345/subscribers" do
21
- [@response_status, {}, @response_body]
22
- end
13
+ stub_request(:get, "https://api.getdrip.com/v2/12345/subscribers").
14
+ to_return(status: @response_status, body: @response_body, headers: {})
23
15
  end
24
16
 
25
17
  should "send the right request" do
@@ -32,11 +24,10 @@ class Drip::Client::SubscribersTest < Drip::TestCase
32
24
  setup do
33
25
  @id = "derrick@getdrip.com"
34
26
  @response_status = 201
35
- @response_body = stub
27
+ @response_body = "stub"
36
28
 
37
- @stubs.get "12345/subscribers/#{CGI.escape @id}" do
38
- [@response_status, {}, @response_body]
39
- end
29
+ stub_request(:get, "https://api.getdrip.com/v2/12345/subscribers/#{CGI.escape @id}").
30
+ to_return(status: @response_status, body: @response_body, headers: {})
40
31
  end
41
32
 
42
33
  should "send the right request" do
@@ -49,11 +40,10 @@ class Drip::Client::SubscribersTest < Drip::TestCase
49
40
  setup do
50
41
  @id = "derrick@getdrip.com"
51
42
  @response_status = 204
52
- @response_body = stub
43
+ @response_body = nil
53
44
 
54
- @stubs.delete "12345/subscribers/#{CGI.escape @id}" do
55
- [@response_status, {}, @response_body]
56
- end
45
+ stub_request(:delete, "https://api.getdrip.com/v2/12345/subscribers/#{CGI.escape @id}").
46
+ to_return(status: @response_status, body: @response_body, headers: {})
57
47
  end
58
48
 
59
49
  should "send the right request" do
@@ -69,11 +59,10 @@ class Drip::Client::SubscribersTest < Drip::TestCase
69
59
  @payload = { "subscribers" => [@data.merge(email: @email)] }.to_json
70
60
 
71
61
  @response_status = 201
72
- @response_body = stub
62
+ @response_body = "stub"
73
63
 
74
- @stubs.post "12345/subscribers", @payload do
75
- [@response_status, {}, @response_body]
76
- end
64
+ stub_request(:post, "https://api.getdrip.com/v2/12345/subscribers").
65
+ to_return(status: @response_status, body: @response_body, headers: {})
77
66
  end
78
67
 
79
68
  should "send the right request" do
@@ -97,11 +86,10 @@ class Drip::Client::SubscribersTest < Drip::TestCase
97
86
 
98
87
  @payload = { "batches" => [{ "subscribers" => @subscribers }] }.to_json
99
88
  @response_status = 201
100
- @response_body = stub
89
+ @response_body = "stub"
101
90
 
102
- @stubs.post "12345/subscribers/batches", @payload do
103
- [@response_status, {}, @response_body]
104
- end
91
+ stub_request(:post, "https://api.getdrip.com/v2/12345/subscribers/batches").
92
+ to_return(status: @response_status, body: @response_body, headers: {})
105
93
  end
106
94
 
107
95
  should "send the right request" do
@@ -123,11 +111,10 @@ class Drip::Client::SubscribersTest < Drip::TestCase
123
111
 
124
112
  @payload = { "batches" => [{ "subscribers" => @subscribers }] }.to_json
125
113
  @response_status = 204
126
- @response_body = stub
114
+ @response_body = nil
127
115
 
128
- @stubs.post "12345/unsubscribes/batches", @payload do
129
- [@response_status, {}, @response_body]
130
- end
116
+ stub_request(:post, "https://api.getdrip.com/v2/12345/unsubscribes/batches").
117
+ to_return(status: @response_status, body: @response_body, headers: {})
131
118
  end
132
119
 
133
120
  should "send the right request" do
@@ -144,11 +131,10 @@ class Drip::Client::SubscribersTest < Drip::TestCase
144
131
  @payload = { "subscribers" => [@data.merge(email: @email)] }.to_json
145
132
 
146
133
  @response_status = 201
147
- @response_body = stub
134
+ @response_body = "stub"
148
135
 
149
- @stubs.post "12345/campaigns/#{@campaign_id}/subscribers", @payload do
150
- [@response_status, {}, @response_body]
151
- end
136
+ stub_request(:post, "https://api.getdrip.com/v2/12345/campaigns/#{@campaign_id}/subscribers").
137
+ to_return(status: @response_status, body: @response_body, headers: {})
152
138
  end
153
139
 
154
140
  should "send the right request" do
@@ -163,11 +149,10 @@ class Drip::Client::SubscribersTest < Drip::TestCase
163
149
  @id = "derrick@getdrip.com"
164
150
 
165
151
  @response_status = 201
166
- @response_body = stub
152
+ @response_body = "stub"
167
153
 
168
- @stubs.post "12345/subscribers/#{CGI.escape @id}/remove" do
169
- [@response_status, {}, @response_body]
170
- end
154
+ stub_request(:post, "https://api.getdrip.com/v2/12345/subscribers/#{CGI.escape @id}/remove").
155
+ to_return(status: @response_status, body: @response_body, headers: {})
171
156
  end
172
157
 
173
158
  should "send the right request" do
@@ -182,11 +167,10 @@ class Drip::Client::SubscribersTest < Drip::TestCase
182
167
  @campaign = "12345"
183
168
 
184
169
  @response_status = 201
185
- @response_body = stub
170
+ @response_body = "stub"
186
171
 
187
- @stubs.post "12345/subscribers/#{CGI.escape @id}/remove?campaign_id=#{@campaign}" do
188
- [@response_status, {}, @response_body]
189
- end
172
+ stub_request(:post, "https://api.getdrip.com/v2/12345/subscribers/#{CGI.escape @id}/remove?campaign_id=#{@campaign}").
173
+ to_return(status: @response_status, body: @response_body, headers: {})
190
174
  end
191
175
 
192
176
  should "send the right request" do
@@ -200,11 +184,10 @@ class Drip::Client::SubscribersTest < Drip::TestCase
200
184
  setup do
201
185
  @id = "derrick@getdrip.com"
202
186
  @response_status = 200
203
- @response_body = stub
187
+ @response_body = "stub"
204
188
 
205
- @stubs.post "12345/subscribers/#{CGI.escape @id}/unsubscribe_all" do
206
- [@response_status, {}, @response_body]
207
- end
189
+ stub_request(:post, "https://api.getdrip.com/v2/12345/subscribers/#{CGI.escape @id}/unsubscribe_all").
190
+ to_return(status: @response_status, body: @response_body, headers: {})
208
191
  end
209
192
 
210
193
  should "send the right request" do
@@ -220,11 +203,10 @@ class Drip::Client::SubscribersTest < Drip::TestCase
220
203
  @payload = { "tags" => [{ "email" => @email, "tag" => @tag }] }.to_json
221
204
 
222
205
  @response_status = 201
223
- @response_body = stub
206
+ @response_body = "stub"
224
207
 
225
- @stubs.post "12345/tags", @payload do
226
- [@response_status, {}, @response_body]
227
- end
208
+ stub_request(:post, "https://api.getdrip.com/v2/12345/tags").
209
+ to_return(status: @response_status, body: @response_body, headers: {})
228
210
  end
229
211
 
230
212
  should "send the right request" do
@@ -2,24 +2,16 @@ require File.dirname(__FILE__) + '/../../test_helper.rb'
2
2
 
3
3
  class Drip::Client::TagsTest < Drip::TestCase
4
4
  def setup
5
- @stubs = Faraday::Adapter::Test::Stubs.new
6
-
7
- @connection = Faraday.new do |builder|
8
- builder.adapter :test, @stubs
9
- end
10
-
11
5
  @client = Drip::Client.new { |c| c.account_id = "12345" }
12
- @client.expects(:connection).at_least_once.returns(@connection)
13
6
  end
14
7
 
15
8
  context "#tags" do
16
9
  setup do
17
10
  @response_status = 200
18
- @response_body = stub
11
+ @response_body = "stub"
19
12
 
20
- @stubs.get "12345/tags" do
21
- [@response_status, {}, @response_body]
22
- end
13
+ stub_request(:get, "https://api.getdrip.com/v2/12345/tags").
14
+ to_return(status: @response_status, body: @response_body, headers: {})
23
15
  end
24
16
 
25
17
  should "send the right request" do
@@ -35,11 +27,10 @@ class Drip::Client::TagsTest < Drip::TestCase
35
27
  @payload = { "tags" => [{ "email" => @email, "tag" => @tag }] }.to_json
36
28
 
37
29
  @response_status = 201
38
- @response_body = stub
30
+ @response_body = "stub"
39
31
 
40
- @stubs.post "12345/tags", @payload do
41
- [@response_status, {}, @response_body]
42
- end
32
+ stub_request(:post, "https://api.getdrip.com/v2/12345/tags").
33
+ to_return(status: @response_status, body: @response_body, headers: {})
43
34
  end
44
35
 
45
36
  should "send the right request" do
@@ -54,11 +45,10 @@ class Drip::Client::TagsTest < Drip::TestCase
54
45
  @tag = "Customer"
55
46
 
56
47
  @response_status = 204
57
- @response_body = stub
48
+ @response_body = nil
58
49
 
59
- @stubs.delete "12345/subscribers/#{CGI.escape @email}/tags/#{CGI.escape @tag}" do
60
- [@response_status, {}, @response_body]
61
- end
50
+ stub_request(:delete, "https://api.getdrip.com/v2/12345/subscribers/#{CGI.escape @email}/tags/#{CGI.escape @tag}").
51
+ to_return(status: @response_status, body: @response_body, headers: {})
62
52
  end
63
53
 
64
54
  should "send the right request" do
@@ -2,24 +2,16 @@ require File.dirname(__FILE__) + '/../../test_helper.rb'
2
2
 
3
3
  class Drip::Client::WebhooksTest < Drip::TestCase
4
4
  def setup
5
- @stubs = Faraday::Adapter::Test::Stubs.new
6
-
7
- @connection = Faraday.new do |builder|
8
- builder.adapter :test, @stubs
9
- end
10
-
11
5
  @client = Drip::Client.new { |c| c.account_id = "12345" }
12
- @client.expects(:connection).at_least_once.returns(@connection)
13
6
  end
14
7
 
15
8
  context "#webhooks" do
16
9
  setup do
17
10
  @response_status = 200
18
- @response_body = stub
11
+ @response_body = "stub"
19
12
 
20
- @stubs.get "12345/webhooks" do
21
- [@response_status, {}, @response_body]
22
- end
13
+ stub_request(:get, "https://api.getdrip.com/v2/12345/webhooks").
14
+ to_return(status: @response_status, body: @response_body, headers: {})
23
15
  end
24
16
 
25
17
  should "send the right request" do
@@ -31,12 +23,11 @@ class Drip::Client::WebhooksTest < Drip::TestCase
31
23
  context "#webhook" do
32
24
  setup do
33
25
  @response_status = 200
34
- @response_body = stub
26
+ @response_body = "stub"
35
27
  @id = 1234
36
28
 
37
- @stubs.get "12345/webhooks/#{@id}" do
38
- [@response_status, {}, @response_body]
39
- end
29
+ stub_request(:get, "https://api.getdrip.com/v2/12345/webhooks/#{@id}").
30
+ to_return(status: @response_status, body: @response_body, headers: {})
40
31
  end
41
32
 
42
33
  should "send the right request" do
@@ -59,11 +50,10 @@ class Drip::Client::WebhooksTest < Drip::TestCase
59
50
 
60
51
  @payload = { "webhooks" => [@options] }.to_json
61
52
  @response_status = 201
62
- @response_body = stub
53
+ @response_body = "stub"
63
54
 
64
- @stubs.post "12345/webhooks", @payload do
65
- [@response_status, {}, @response_body]
66
- end
55
+ stub_request(:post, "https://api.getdrip.com/v2/12345/webhooks").
56
+ to_return(status: @response_status, body: @response_body, headers: {})
67
57
  end
68
58
 
69
59
  should "send the right request" do
@@ -75,12 +65,11 @@ class Drip::Client::WebhooksTest < Drip::TestCase
75
65
  context "#delete_webhook" do
76
66
  setup do
77
67
  @response_status = 200
78
- @response_body = stub
68
+ @response_body = "stub"
79
69
  @id = 1234
80
70
 
81
- @stubs.delete "12345/webhooks/#{@id}" do
82
- [@response_status, {}, @response_body]
83
- end
71
+ stub_request(:delete, "https://api.getdrip.com/v2/12345/webhooks/#{@id}").
72
+ to_return(status: @response_status, body: @response_body, headers: {})
84
73
  end
85
74
 
86
75
  should "send the right request" do