apruve 0.11.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile +2 -0
- data/Gemfile.lock +33 -1
- data/README.md +26 -29
- data/lib/apruve.rb +6 -2
- data/lib/apruve/client.rb +2 -2
- data/lib/apruve/error.rb +4 -3
- data/lib/apruve/resources.rb +7 -5
- data/lib/apruve/resources/invoice.rb +69 -0
- data/lib/apruve/resources/invoice_item.rb +7 -0
- data/lib/apruve/resources/merchant.rb +11 -0
- data/lib/apruve/resources/order.rb +81 -0
- data/lib/apruve/resources/{line_item.rb → order_item.rb} +1 -1
- data/lib/apruve/resources/subscription.rb +1 -1
- data/lib/apruve/resources/webhook_endpoint.rb +33 -0
- data/lib/apruve/version.rb +1 -1
- data/spec/apruve/apruve_spec.rb +5 -5
- data/spec/apruve/resources/{payment_item_spec.rb → invoice_item_spec.rb} +5 -4
- data/spec/apruve/resources/invoice_spec.rb +291 -0
- data/spec/apruve/resources/merchant_spec.rb +56 -0
- data/spec/apruve/resources/{line_item_spec.rb → order_item_spec.rb} +2 -2
- data/spec/apruve/resources/order_spec.rb +220 -0
- data/spec/apruve/resources/payment_request_spec.rb +19 -0
- data/spec/apruve/resources/subscription_adjustment_spec.rb +10 -10
- data/spec/apruve/resources/subscription_spec.rb +6 -6
- data/spec/apruve/resources/webhook_endpoint_spec.rb +137 -0
- data/spec/spec_helper.rb +3 -0
- metadata +21 -14
- data/lib/apruve/resources/payment.rb +0 -43
- data/lib/apruve/resources/payment_item.rb +0 -7
- data/lib/apruve/resources/payment_request.rb +0 -59
- data/spec/apruve/resources/payment_spec.rb +0 -129
@@ -0,0 +1,220 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Apruve::Order do
|
4
|
+
before :each do
|
5
|
+
Apruve.configure('f5fbe71d68772d1f562ed6f598b995b3', 'local')
|
6
|
+
end
|
7
|
+
|
8
|
+
let (:order_items) do
|
9
|
+
[
|
10
|
+
Apruve::OrderItem.new(
|
11
|
+
title: 'line 1',
|
12
|
+
amount_cents: '1230',
|
13
|
+
price_ea_cents: '123',
|
14
|
+
quantity: 10,
|
15
|
+
description: 'A line item',
|
16
|
+
variant_info: 'small',
|
17
|
+
sku: 'LINE1SKU',
|
18
|
+
vendor: 'acme, inc.',
|
19
|
+
view_product_url: 'http://www.apruve.com/doc'
|
20
|
+
),
|
21
|
+
Apruve::OrderItem.new(
|
22
|
+
title: 'line 2',
|
23
|
+
amount_cents: '40'
|
24
|
+
)
|
25
|
+
]
|
26
|
+
end
|
27
|
+
|
28
|
+
let (:payment_request) do
|
29
|
+
Apruve::Order.new(
|
30
|
+
merchant_id: '9999',
|
31
|
+
merchant_order_id: 'ABC',
|
32
|
+
amount_cents: 12340,
|
33
|
+
tax_cents: 0,
|
34
|
+
shipping_cents: 0,
|
35
|
+
expire_at: '2014-07-22T00:00:00+00:00',
|
36
|
+
order_items: order_items,
|
37
|
+
finalize_on_create: false,
|
38
|
+
invoice_on_create: false
|
39
|
+
)
|
40
|
+
end
|
41
|
+
subject { payment_request }
|
42
|
+
|
43
|
+
it { should respond_to(:merchant_id) }
|
44
|
+
it { should respond_to(:merchant_order_id) }
|
45
|
+
it { should respond_to(:amount_cents) }
|
46
|
+
it { should respond_to(:tax_cents) }
|
47
|
+
it { should respond_to(:shipping_cents) }
|
48
|
+
it { should respond_to(:order_items) }
|
49
|
+
it { should respond_to(:links) }
|
50
|
+
it { should respond_to(:created_at) }
|
51
|
+
it { should respond_to(:updated_at) }
|
52
|
+
it { should respond_to(:accepts_payment_terms) }
|
53
|
+
it { should respond_to(:finalize_on_create) }
|
54
|
+
it { should respond_to(:invoice_on_create) }
|
55
|
+
|
56
|
+
describe '#to_json' do
|
57
|
+
let(:expected) do
|
58
|
+
"{\"merchant_id\":\"9999\",\"merchant_order_id\":\"ABC\",\"amount_cents\":12340,\"tax_cents\":0,"\
|
59
|
+
"\"shipping_cents\":0,\"expire_at\":\"2014-07-22T00:00:00+00:00\",\"order_items\":[{\"title\":\"line 1\",\"amount_cents\":\"1230\","\
|
60
|
+
"\"price_ea_cents\":\"123\",\"quantity\":10,\"description\":\"A line item\",\"variant_info\":\"small\","\
|
61
|
+
"\"sku\":\"LINE1SKU\",\"vendor\":\"acme, inc.\",\"view_product_url\":\"http://www.apruve.com/doc\"},"\
|
62
|
+
"{\"title\":\"line 2\",\"amount_cents\":\"40\"}],\"finalize_on_create\":false,\"invoice_on_create\":false}"
|
63
|
+
end
|
64
|
+
its(:to_json) { should eq expected }
|
65
|
+
end
|
66
|
+
|
67
|
+
describe '#value_string' do
|
68
|
+
let(:expected) do
|
69
|
+
'9999ABC12340002014-07-22T00:00:00+00:00falsefalseline 1123012310A line itemsmallLINE1SKUacme, inc.http://www.apruve.com/docline 240'
|
70
|
+
end
|
71
|
+
its(:value_string) { should eq expected }
|
72
|
+
end
|
73
|
+
|
74
|
+
describe '#secure_hash' do
|
75
|
+
describe 'no api_key' do
|
76
|
+
let (:error) { 'api_key has not been set. Set it with Apruve.configure(api_key, environment, options)' }
|
77
|
+
before :each do
|
78
|
+
Apruve.configure
|
79
|
+
end
|
80
|
+
it 'should raise' do
|
81
|
+
expect { payment_request.secure_hash }.to raise_error(error)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
describe 'with api_key' do
|
85
|
+
let (:hash) { '9aa1dda31ecd611ed759e132c2c4afec810409e49866db0090d8fa51fe4ad597' }
|
86
|
+
let (:api_key) { 'an_api_key' }
|
87
|
+
before :each do
|
88
|
+
Apruve.configure(api_key)
|
89
|
+
end
|
90
|
+
it 'should hash' do
|
91
|
+
expect(payment_request.secure_hash).to eq hash
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
describe '#validate' do
|
97
|
+
describe 'no errors' do
|
98
|
+
it 'should not raise' do
|
99
|
+
expect { payment_request.validate }.not_to raise_error
|
100
|
+
end
|
101
|
+
end
|
102
|
+
describe 'errors' do
|
103
|
+
before :each do
|
104
|
+
payment_request.merchant_id = nil
|
105
|
+
end
|
106
|
+
it 'should raise on no merchant_id' do
|
107
|
+
expect { payment_request.validate }.to raise_error(Apruve::ValidationError, '["merchant_id must be set"]')
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe '#find' do
|
113
|
+
let (:id) { '89ea2488fe0a5c7bb38aa7f9b088874a' }
|
114
|
+
describe 'success' do
|
115
|
+
let! (:stubs) do
|
116
|
+
faraday_stubs do |stub|
|
117
|
+
stub.get("/api/v4/orders/#{id}") { [200, {}, '{}'] }
|
118
|
+
end
|
119
|
+
end
|
120
|
+
it 'should do a get' do
|
121
|
+
Apruve::Order.find(id)
|
122
|
+
stubs.verify_stubbed_calls
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
describe 'not found' do
|
127
|
+
let! (:stubs) do
|
128
|
+
faraday_stubs do |stub|
|
129
|
+
stub.get("/api/v4/orders/#{id}") { [404, {}, 'Not Found'] }
|
130
|
+
end
|
131
|
+
end
|
132
|
+
it 'should raise' do
|
133
|
+
expect { Apruve::Order.find(id) }.to raise_error(Apruve::NotFound)
|
134
|
+
stubs.verify_stubbed_calls
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
describe '#finalize' do
|
140
|
+
let (:id) { '89ea2488fe0a5c7bb38aa7f9b088874a' }
|
141
|
+
describe 'success' do
|
142
|
+
let! (:stubs) do
|
143
|
+
faraday_stubs do |stub|
|
144
|
+
stub.post("/api/v4/orders/#{id}/finalize") { [200, {}, '{}'] }
|
145
|
+
end
|
146
|
+
end
|
147
|
+
it 'should do a get' do
|
148
|
+
Apruve::Order.finalize!(id)
|
149
|
+
stubs.verify_stubbed_calls
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
describe 'not found' do
|
154
|
+
let! (:stubs) do
|
155
|
+
faraday_stubs do |stub|
|
156
|
+
stub.post("/api/v4/orders/#{id}/finalize") { [404, {}, 'Not Found'] }
|
157
|
+
end
|
158
|
+
end
|
159
|
+
it 'should raise' do
|
160
|
+
expect { Apruve::Order.finalize!(id) }.to raise_error(Apruve::NotFound)
|
161
|
+
stubs.verify_stubbed_calls
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
describe '#cancel' do
|
167
|
+
let (:id) { '89ea2488fe0a5c7bb38aa7f9b088874a' }
|
168
|
+
describe 'success' do
|
169
|
+
let! (:stubs) do
|
170
|
+
faraday_stubs do |stub|
|
171
|
+
stub.post("/api/v4/orders/#{id}/cancel") { [200, {}, '{}'] }
|
172
|
+
end
|
173
|
+
end
|
174
|
+
it 'should do a get' do
|
175
|
+
Apruve::Order.cancel!(id)
|
176
|
+
stubs.verify_stubbed_calls
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
describe 'not found' do
|
181
|
+
let! (:stubs) do
|
182
|
+
faraday_stubs do |stub|
|
183
|
+
stub.post("/api/v4/orders/#{id}/cancel") { [404, {}, 'Not Found'] }
|
184
|
+
end
|
185
|
+
end
|
186
|
+
it 'should raise' do
|
187
|
+
expect { Apruve::Order.cancel!(id) }.to raise_error(Apruve::NotFound)
|
188
|
+
stubs.verify_stubbed_calls
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
describe '#update' do
|
194
|
+
let (:id) { '89ea2488fe0a5c7bb38aa7f9b088874a' }
|
195
|
+
let (:order) { Apruve::Order.new id: id, merchant_id: 9999 }
|
196
|
+
describe 'success' do
|
197
|
+
let! (:stubs) do
|
198
|
+
faraday_stubs do |stub|
|
199
|
+
stub.patch("/api/v4/orders/#{id}", {order: order}.to_json) { [200, {}, '{}'] }
|
200
|
+
end
|
201
|
+
end
|
202
|
+
it 'should do a get' do
|
203
|
+
order.update!
|
204
|
+
stubs.verify_stubbed_calls
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
describe 'not found' do
|
209
|
+
let! (:stubs) do
|
210
|
+
faraday_stubs do |stub|
|
211
|
+
stub.patch("/api/v4/orders/#{id}", {order: order}.to_json) { [404, {}, 'Not Found'] }
|
212
|
+
end
|
213
|
+
end
|
214
|
+
it 'should raise' do
|
215
|
+
expect { order.update! }.to raise_error(Apruve::NotFound)
|
216
|
+
stubs.verify_stubbed_calls
|
217
|
+
end
|
218
|
+
end
|
219
|
+
end
|
220
|
+
end
|
@@ -89,6 +89,25 @@ describe Apruve::PaymentRequest do
|
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
|
+
describe '#finalize!' do
|
93
|
+
let (:id) { '89ea2488fe0a5c7bb38aa7f9b088874a' }
|
94
|
+
describe 'success' do
|
95
|
+
# stub out a successful post
|
96
|
+
let! (:stubs) do
|
97
|
+
faraday_stubs do |stub|
|
98
|
+
stub.post("/api/v3/payment_requests/#{id}/finalize") { [201, {}, '{}'] }
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
it 'should do a post' do
|
103
|
+
Apruve::PaymentRequest.finalize!(id)
|
104
|
+
stubs.verify_stubbed_calls
|
105
|
+
end
|
106
|
+
end
|
107
|
+
# stub out a failed post
|
108
|
+
|
109
|
+
end
|
110
|
+
|
92
111
|
describe '#validate' do
|
93
112
|
describe 'no errors' do
|
94
113
|
it 'should not raise' do
|
@@ -53,7 +53,7 @@ describe Apruve::SubscriptionAdjustment do
|
|
53
53
|
describe 'success' do
|
54
54
|
let! (:stubs) do
|
55
55
|
faraday_stubs do |stub|
|
56
|
-
stub.get("/api/
|
56
|
+
stub.get("/api/v4/subscriptions/#{subscription_id}/adjustments/#{id}") { [200, {}, '{}'] }
|
57
57
|
end
|
58
58
|
end
|
59
59
|
it 'should do a get' do
|
@@ -64,7 +64,7 @@ describe Apruve::SubscriptionAdjustment do
|
|
64
64
|
describe 'not found' do
|
65
65
|
let! (:stubs) do
|
66
66
|
faraday_stubs do |stub|
|
67
|
-
stub.get("/api/
|
67
|
+
stub.get("/api/v4/subscriptions/#{subscription_id}/adjustments/#{id}") { [404, {}, 'Not Found'] }
|
68
68
|
end
|
69
69
|
end
|
70
70
|
it 'should raise' do
|
@@ -78,7 +78,7 @@ describe Apruve::SubscriptionAdjustment do
|
|
78
78
|
describe 'success' do
|
79
79
|
let! (:stubs) do
|
80
80
|
faraday_stubs do |stub|
|
81
|
-
stub.delete("/api/
|
81
|
+
stub.delete("/api/v4/subscriptions/#{subscription_id}/adjustments/#{id}") { [200, {}, '{}'] }
|
82
82
|
end
|
83
83
|
end
|
84
84
|
it 'should do a delete' do
|
@@ -89,7 +89,7 @@ describe Apruve::SubscriptionAdjustment do
|
|
89
89
|
describe 'not found' do
|
90
90
|
let! (:stubs) do
|
91
91
|
faraday_stubs do |stub|
|
92
|
-
stub.delete("/api/
|
92
|
+
stub.delete("/api/v4/subscriptions/#{subscription_id}/adjustments/#{id}") { [404, {}, 'Not Found'] }
|
93
93
|
end
|
94
94
|
end
|
95
95
|
it 'should raise' do
|
@@ -103,7 +103,7 @@ describe Apruve::SubscriptionAdjustment do
|
|
103
103
|
describe 'success' do
|
104
104
|
let! (:stubs) do
|
105
105
|
faraday_stubs do |stub|
|
106
|
-
stub.delete("/api/
|
106
|
+
stub.delete("/api/v4/subscriptions/#{adjustment.subscription_id}/adjustments/#{adjustment.id}") { [200, {}, '{}'] }
|
107
107
|
end
|
108
108
|
end
|
109
109
|
it 'should do a delete' do
|
@@ -114,7 +114,7 @@ describe Apruve::SubscriptionAdjustment do
|
|
114
114
|
describe 'not found' do
|
115
115
|
let! (:stubs) do
|
116
116
|
faraday_stubs do |stub|
|
117
|
-
stub.delete("/api/
|
117
|
+
stub.delete("/api/v4/subscriptions/#{adjustment.subscription_id}/adjustments/#{adjustment.id}") { [404, {}, 'Not Found'] }
|
118
118
|
end
|
119
119
|
end
|
120
120
|
it 'should raise' do
|
@@ -134,7 +134,7 @@ describe Apruve::SubscriptionAdjustment do
|
|
134
134
|
describe 'success' do
|
135
135
|
let! (:stubs) do
|
136
136
|
faraday_stubs do |stub|
|
137
|
-
stub.get("/api/
|
137
|
+
stub.get("/api/v4/subscriptions/#{subscription_id}/adjustments") { [200, {}, '{}'] }
|
138
138
|
end
|
139
139
|
end
|
140
140
|
it 'should do a get' do
|
@@ -145,7 +145,7 @@ describe Apruve::SubscriptionAdjustment do
|
|
145
145
|
describe 'not found' do
|
146
146
|
let! (:stubs) do
|
147
147
|
faraday_stubs do |stub|
|
148
|
-
stub.get("/api/
|
148
|
+
stub.get("/api/v4/subscriptions/#{subscription_id}/adjustments") { [404, {}, 'Not Found'] }
|
149
149
|
end
|
150
150
|
end
|
151
151
|
it 'should raise' do
|
@@ -175,7 +175,7 @@ describe Apruve::SubscriptionAdjustment do
|
|
175
175
|
let! (:stubs) do
|
176
176
|
faraday_stubs do |stub|
|
177
177
|
stub.post(
|
178
|
-
"/api/
|
178
|
+
"/api/v4/subscriptions/#{subscription_id}/adjustments", adjustment.to_json) { [200, {}, response.to_json] }
|
179
179
|
end
|
180
180
|
end
|
181
181
|
it 'should do a post' do
|
@@ -187,7 +187,7 @@ describe Apruve::SubscriptionAdjustment do
|
|
187
187
|
let! (:stubs) do
|
188
188
|
faraday_stubs do |stub|
|
189
189
|
stub.post(
|
190
|
-
"/api/
|
190
|
+
"/api/v4/subscriptions/#{subscription_id}/adjustments", adjustment.to_json) { [404, {}, 'Not Found'] }
|
191
191
|
end
|
192
192
|
end
|
193
193
|
it 'should raise' do
|
@@ -41,7 +41,7 @@ describe Apruve::Subscription do
|
|
41
41
|
describe 'success' do
|
42
42
|
let! (:stubs) do
|
43
43
|
faraday_stubs do |stub|
|
44
|
-
stub.get("/api/
|
44
|
+
stub.get("/api/v4/subscriptions/#{id}") { [200, {}, '{}'] }
|
45
45
|
end
|
46
46
|
end
|
47
47
|
it 'should do a get' do
|
@@ -53,7 +53,7 @@ describe Apruve::Subscription do
|
|
53
53
|
describe 'not found' do
|
54
54
|
let! (:stubs) do
|
55
55
|
faraday_stubs do |stub|
|
56
|
-
stub.get("/api/
|
56
|
+
stub.get("/api/v4/subscriptions/#{id}") { [404, {}, 'Not Found'] }
|
57
57
|
end
|
58
58
|
end
|
59
59
|
it 'should raise' do
|
@@ -74,7 +74,7 @@ describe Apruve::Subscription do
|
|
74
74
|
let! (:stubs) do
|
75
75
|
faraday_stubs do |stub|
|
76
76
|
stub.put(
|
77
|
-
"/api/
|
77
|
+
"/api/v4/subscriptions/#{id}",
|
78
78
|
subscription.to_json,
|
79
79
|
) { [200, {}, response.to_json] }
|
80
80
|
end
|
@@ -89,7 +89,7 @@ describe Apruve::Subscription do
|
|
89
89
|
let! (:stubs) do
|
90
90
|
faraday_stubs do |stub|
|
91
91
|
stub.put(
|
92
|
-
"/api/
|
92
|
+
"/api/v4/subscriptions/#{id}",
|
93
93
|
subscription.to_json,
|
94
94
|
) { [404, {}, 'Not Found'] }
|
95
95
|
end
|
@@ -115,7 +115,7 @@ describe Apruve::Subscription do
|
|
115
115
|
describe 'success' do
|
116
116
|
let! (:stubs) do
|
117
117
|
faraday_stubs do |stub|
|
118
|
-
stub.post("/api/
|
118
|
+
stub.post("/api/v4/subscriptions/#{id}/cancel") { [200, {}, response.to_json] }
|
119
119
|
end
|
120
120
|
end
|
121
121
|
it 'should do a post' do
|
@@ -129,7 +129,7 @@ describe Apruve::Subscription do
|
|
129
129
|
describe 'subscription not found' do
|
130
130
|
let! (:stubs) do
|
131
131
|
faraday_stubs do |stub|
|
132
|
-
stub.post("/api/
|
132
|
+
stub.post("/api/v4/subscriptions/#{id}/cancel") { [404, {}, 'Not Found'] }
|
133
133
|
end
|
134
134
|
end
|
135
135
|
it 'should raise' do
|
@@ -0,0 +1,137 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Apruve::WebhookEndpoint do
|
4
|
+
before :each do
|
5
|
+
Apruve.configure('f5fbe71d68772d1f562ed6f598b995b3', 'local')
|
6
|
+
end
|
7
|
+
|
8
|
+
let (:id) { 1234 }
|
9
|
+
let (:version) { 'A title' }
|
10
|
+
let (:url) { Faker::Internet.url }
|
11
|
+
let (:merchant_id) { 'f5fbe71d68772d1f562ed6f598b995b3' }
|
12
|
+
let (:webhook_endpoint) do
|
13
|
+
Apruve::WebhookEndpoint.new(
|
14
|
+
id: id,
|
15
|
+
version: version,
|
16
|
+
url: url,
|
17
|
+
merchant_id: merchant_id,
|
18
|
+
)
|
19
|
+
end
|
20
|
+
let (:json) { {id: id, version: version, url: url} }
|
21
|
+
subject { webhook_endpoint }
|
22
|
+
|
23
|
+
it { should respond_to(:id) }
|
24
|
+
it { should respond_to(:version) }
|
25
|
+
it { should respond_to(:url) }
|
26
|
+
it { should respond_to(:merchant_id) }
|
27
|
+
|
28
|
+
describe '#where' do
|
29
|
+
describe 'success' do
|
30
|
+
let! (:stubs) do
|
31
|
+
faraday_stubs do |stub|
|
32
|
+
stub.get("/api/v4/merchants/#{merchant_id}/webhook_endpoints") { [200, {}, [json,json].to_json] }
|
33
|
+
end
|
34
|
+
end
|
35
|
+
it 'should do a get' do
|
36
|
+
endpoints = Apruve::WebhookEndpoint.where(merchant_id)
|
37
|
+
stubs.verify_stubbed_calls
|
38
|
+
endpoints.each do |endpoint|
|
39
|
+
expect(endpoint.merchant_id).to eq merchant_id
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'not found' do
|
45
|
+
let! (:stubs) do
|
46
|
+
faraday_stubs do |stub|
|
47
|
+
stub.get("/api/v4/merchants/#{merchant_id}/webhook_endpoints") { [404, {}, 'Not Found'] }
|
48
|
+
end
|
49
|
+
end
|
50
|
+
it 'should raise' do
|
51
|
+
expect { Apruve::WebhookEndpoint.where(merchant_id) }.to raise_error(Apruve::NotFound)
|
52
|
+
stubs.verify_stubbed_calls
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe '#find' do
|
58
|
+
describe 'success' do
|
59
|
+
let! (:stubs) do
|
60
|
+
faraday_stubs do |stub|
|
61
|
+
stub.get("/api/v4/merchants/#{merchant_id}/webhook_endpoints/#{id}") { [200, {}, json.to_json] }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
it 'should do a get' do
|
65
|
+
endpoint = Apruve::WebhookEndpoint.find(merchant_id, id)
|
66
|
+
stubs.verify_stubbed_calls
|
67
|
+
expect(endpoint.merchant_id).to eq merchant_id
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
describe 'not found' do
|
72
|
+
let! (:stubs) do
|
73
|
+
faraday_stubs do |stub|
|
74
|
+
stub.get("/api/v4/merchants/#{merchant_id}/webhook_endpoints/#{id}") { [404, {}, 'Not Found'] }
|
75
|
+
end
|
76
|
+
end
|
77
|
+
it 'should raise' do
|
78
|
+
expect { Apruve::WebhookEndpoint.find(merchant_id, id) }.to raise_error(Apruve::NotFound)
|
79
|
+
stubs.verify_stubbed_calls
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
describe '#destroy!' do
|
85
|
+
let(:webhook_endpoint) { Apruve::WebhookEndpoint.new merchant_id: merchant_id, id: id }
|
86
|
+
describe 'success' do
|
87
|
+
let! (:stubs) do
|
88
|
+
faraday_stubs do |stub|
|
89
|
+
stub.delete("/api/v4/merchants/#{merchant_id}/webhook_endpoints/#{id}") { [200, {}, '{}'] }
|
90
|
+
end
|
91
|
+
end
|
92
|
+
it 'should do a delete' do
|
93
|
+
webhook_endpoint.destroy!
|
94
|
+
stubs.verify_stubbed_calls
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
98
|
+
describe 'not found' do
|
99
|
+
let! (:stubs) do
|
100
|
+
faraday_stubs do |stub|
|
101
|
+
stub.delete("/api/v4/merchants/#{merchant_id}/webhook_endpoints/#{id}") { [404, {}, 'Not Found'] }
|
102
|
+
end
|
103
|
+
end
|
104
|
+
it 'should raise' do
|
105
|
+
expect { webhook_endpoint.destroy! }.to raise_error(Apruve::NotFound)
|
106
|
+
stubs.verify_stubbed_calls
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
describe '#create' do
|
112
|
+
let(:webhook_endpoint) { Apruve::WebhookEndpoint.new(merchant_id: merchant_id) }
|
113
|
+
describe 'success' do
|
114
|
+
let! (:stubs) do
|
115
|
+
faraday_stubs do |stub|
|
116
|
+
stub.post("/api/v4/merchants/#{merchant_id}/webhook_endpoints", {webhook_endpoint: webhook_endpoint}.to_json) { [201, {}, '{}'] }
|
117
|
+
end
|
118
|
+
end
|
119
|
+
it 'should do a create' do
|
120
|
+
webhook_endpoint.create!
|
121
|
+
stubs.verify_stubbed_calls
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
describe 'not found' do
|
126
|
+
let! (:stubs) do
|
127
|
+
faraday_stubs do |stub|
|
128
|
+
stub.post("/api/v4/merchants/#{merchant_id}/webhook_endpoints", {webhook_endpoint: webhook_endpoint}.to_json) { [404, {}, 'Not Found'] }
|
129
|
+
end
|
130
|
+
end
|
131
|
+
it 'should raise' do
|
132
|
+
expect { webhook_endpoint.create! }.to raise_error(Apruve::NotFound)
|
133
|
+
stubs.verify_stubbed_calls
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|