stripe-ruby-mock 2.4.0 → 2.5.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.env +2 -0
- data/.travis.yml +8 -4
- data/README.md +12 -5
- data/lib/stripe_mock/api/account_balance.rb +14 -0
- data/lib/stripe_mock/api/client.rb +4 -4
- data/lib/stripe_mock/api/conversion_rate.rb +14 -0
- data/lib/stripe_mock/api/errors.rb +25 -14
- data/lib/stripe_mock/api/instance.rb +6 -6
- data/lib/stripe_mock/api/webhooks.rb +5 -1
- data/lib/stripe_mock/client.rb +18 -2
- data/lib/stripe_mock/data/list.rb +14 -2
- data/lib/stripe_mock/data.rb +217 -56
- data/lib/stripe_mock/instance.rb +93 -8
- data/lib/stripe_mock/request_handlers/accounts.rb +34 -2
- data/lib/stripe_mock/request_handlers/balance.rb +17 -0
- data/lib/stripe_mock/request_handlers/balance_transactions.rb +18 -2
- data/lib/stripe_mock/request_handlers/charges.rb +25 -17
- data/lib/stripe_mock/request_handlers/coupons.rb +5 -4
- data/lib/stripe_mock/request_handlers/customers.rb +26 -8
- data/lib/stripe_mock/request_handlers/ephemeral_key.rb +13 -0
- data/lib/stripe_mock/request_handlers/external_accounts.rb +55 -0
- data/lib/stripe_mock/request_handlers/helpers/bank_account_helpers.rb +1 -1
- data/lib/stripe_mock/request_handlers/helpers/card_helpers.rb +9 -7
- data/lib/stripe_mock/request_handlers/helpers/coupon_helpers.rb +10 -6
- data/lib/stripe_mock/request_handlers/helpers/external_account_helpers.rb +49 -0
- data/lib/stripe_mock/request_handlers/helpers/subscription_helpers.rb +55 -15
- data/lib/stripe_mock/request_handlers/helpers/token_helpers.rb +2 -2
- data/lib/stripe_mock/request_handlers/invoices.rb +93 -14
- data/lib/stripe_mock/request_handlers/orders.rb +5 -5
- data/lib/stripe_mock/request_handlers/payouts.rb +32 -0
- data/lib/stripe_mock/request_handlers/plans.rb +1 -0
- data/lib/stripe_mock/request_handlers/products.rb +43 -0
- data/lib/stripe_mock/request_handlers/refunds.rb +10 -7
- data/lib/stripe_mock/request_handlers/subscription_items.rb +36 -0
- data/lib/stripe_mock/request_handlers/subscriptions.rb +95 -34
- data/lib/stripe_mock/request_handlers/tax_rates.rb +36 -0
- data/lib/stripe_mock/request_handlers/tokens.rb +9 -3
- data/lib/stripe_mock/request_handlers/transfers.rb +11 -5
- data/lib/stripe_mock/request_handlers/validators/param_validators.rb +10 -1
- data/lib/stripe_mock/server.rb +14 -1
- data/lib/stripe_mock/test_strategies/base.rb +7 -5
- data/lib/stripe_mock/test_strategies/live.rb +5 -0
- data/lib/stripe_mock/test_strategies/mock.rb +8 -0
- data/lib/stripe_mock/util.rb +8 -2
- data/lib/stripe_mock/version.rb +1 -1
- data/lib/stripe_mock/webhook_fixtures/account.updated.json +1 -1
- data/lib/stripe_mock/webhook_fixtures/charge.dispute.funds_reinstated.json +88 -0
- data/lib/stripe_mock/webhook_fixtures/charge.dispute.funds_withdrawn.json +88 -0
- data/lib/stripe_mock/webhook_fixtures/charge.updated.json +58 -0
- data/lib/stripe_mock/webhook_fixtures/customer.subscription.created.json +40 -10
- data/lib/stripe_mock/webhook_fixtures/customer.subscription.deleted.json +39 -10
- data/lib/stripe_mock/webhook_fixtures/customer.subscription.trial_will_end.json +39 -10
- data/lib/stripe_mock/webhook_fixtures/customer.subscription.updated.json +40 -11
- data/lib/stripe_mock/webhook_fixtures/invoice.created.json +3 -2
- data/lib/stripe_mock/webhook_fixtures/invoice.payment_failed.json +1 -1
- data/lib/stripe_mock/webhook_fixtures/invoice.payment_succeeded.json +92 -85
- data/lib/stripe_mock/webhook_fixtures/invoice.updated.json +3 -2
- data/lib/stripe_mock/webhook_fixtures/plan.created.json +1 -1
- data/lib/stripe_mock/webhook_fixtures/plan.deleted.json +1 -1
- data/lib/stripe_mock/webhook_fixtures/plan.updated.json +1 -1
- data/lib/stripe_mock.rb +13 -0
- data/spec/instance_spec.rb +54 -4
- data/spec/integration_examples/prepare_error_examples.rb +6 -6
- data/spec/list_spec.rb +16 -3
- data/spec/readme_spec.rb +2 -0
- data/spec/server_spec.rb +6 -2
- data/spec/shared_stripe_examples/account_examples.rb +35 -0
- data/spec/shared_stripe_examples/balance_examples.rb +11 -0
- data/spec/shared_stripe_examples/balance_transaction_examples.rb +28 -0
- data/spec/shared_stripe_examples/bank_examples.rb +28 -1
- data/spec/shared_stripe_examples/card_examples.rb +10 -3
- data/spec/shared_stripe_examples/charge_examples.rb +73 -17
- data/spec/shared_stripe_examples/coupon_examples.rb +8 -2
- data/spec/shared_stripe_examples/customer_examples.rb +54 -2
- data/spec/shared_stripe_examples/dispute_examples.rb +19 -8
- data/spec/shared_stripe_examples/ephemeral_key_examples.rb +17 -0
- data/spec/shared_stripe_examples/error_mock_examples.rb +3 -3
- data/spec/shared_stripe_examples/external_account_examples.rb +170 -0
- data/spec/shared_stripe_examples/extra_features_examples.rb +2 -0
- data/spec/shared_stripe_examples/invoice_examples.rb +314 -51
- data/spec/shared_stripe_examples/payout_examples.rb +68 -0
- data/spec/shared_stripe_examples/plan_examples.rb +37 -5
- data/spec/shared_stripe_examples/product_example.rb +65 -0
- data/spec/shared_stripe_examples/recipient_examples.rb +7 -7
- data/spec/shared_stripe_examples/refund_examples.rb +17 -11
- data/spec/shared_stripe_examples/subscription_examples.rb +463 -33
- data/spec/shared_stripe_examples/subscription_items_examples.rb +75 -0
- data/spec/shared_stripe_examples/tax_rate_examples.rb +42 -0
- data/spec/shared_stripe_examples/transfer_examples.rb +72 -23
- data/spec/shared_stripe_examples/webhook_event_examples.rb +74 -5
- data/spec/spec_helper.rb +7 -6
- data/spec/stripe_mock_spec.rb +16 -3
- data/spec/support/stripe_examples.rb +7 -1
- data/spec/util_spec.rb +35 -1
- data/stripe-ruby-mock.gemspec +1 -1
- metadata +34 -7
- data/ChangeLog.rdoc +0 -4
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
shared_examples 'Product API' do
|
4
|
+
it 'creates a product' do
|
5
|
+
product = Stripe::Product.create(
|
6
|
+
name: 'my awesome product',
|
7
|
+
type: 'service'
|
8
|
+
)
|
9
|
+
|
10
|
+
expect(product.name).to eq 'my awesome product'
|
11
|
+
expect(product.type).to eq 'service'
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'retrieves a product' do
|
15
|
+
Stripe::Product.create(
|
16
|
+
id: 'test_prod_1',
|
17
|
+
name: 'my awesome product',
|
18
|
+
type: 'service'
|
19
|
+
)
|
20
|
+
|
21
|
+
product = Stripe::Product.retrieve('test_prod_1')
|
22
|
+
|
23
|
+
expect(product.name).to eq 'my awesome product'
|
24
|
+
expect(product.type).to eq 'service'
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'updates a product' do
|
28
|
+
Stripe::Product.create(
|
29
|
+
id: 'test_prod_1',
|
30
|
+
name: 'my awesome product',
|
31
|
+
type: 'service'
|
32
|
+
)
|
33
|
+
|
34
|
+
Stripe::Product.update('test_prod_1', name: 'my lame product')
|
35
|
+
|
36
|
+
product = Stripe::Product.retrieve('test_prod_1')
|
37
|
+
|
38
|
+
expect(product.name).to eq 'my lame product'
|
39
|
+
end
|
40
|
+
|
41
|
+
it 'lists all products' do
|
42
|
+
2.times do |n|
|
43
|
+
Stripe::Product.create(
|
44
|
+
name: "product #{n}",
|
45
|
+
type: 'service'
|
46
|
+
)
|
47
|
+
end
|
48
|
+
|
49
|
+
products = Stripe::Product.list
|
50
|
+
|
51
|
+
expect(products.map(&:name)).to match_array ['product 0', 'product 1']
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'destroys a product', live: true do
|
55
|
+
Stripe::Product.create(
|
56
|
+
id: 'test_prod_1',
|
57
|
+
name: 'my awesome product',
|
58
|
+
type: 'service'
|
59
|
+
)
|
60
|
+
|
61
|
+
Stripe::Product.delete('test_prod_1')
|
62
|
+
|
63
|
+
expect { Stripe::Product.retrieve('test_prod_1') }. to raise_error(Stripe::InvalidRequestError)
|
64
|
+
end
|
65
|
+
end
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
shared_examples 'Recipient API' do
|
4
4
|
|
5
|
-
it "creates a stripe recipient with a default bank and card" do
|
5
|
+
it "creates a stripe recipient with a default bank and card", skip: 'Stripe has deprecated Recipients' do
|
6
6
|
recipient = Stripe::Recipient.create({
|
7
7
|
type: "corporation",
|
8
8
|
name: "MyCo",
|
@@ -28,14 +28,14 @@ shared_examples 'Recipient API' do
|
|
28
28
|
expect { recipient.card }.to raise_error
|
29
29
|
end
|
30
30
|
|
31
|
-
it "raises a error if params are invalid" do
|
31
|
+
it "raises a error if params are invalid", skip: 'Stripe has deprecated Recipients' do
|
32
32
|
expect { Stripe::Recipient.create(name: "foo") }.to raise_error
|
33
33
|
expect { Stripe::Recipient.create(type: "individual") }.to raise_error
|
34
34
|
expect { Stripe::Recipient.create(name: "foo", type: "bar") }.to raise_error
|
35
35
|
expect { Stripe::Recipient.create(name: "foo", type: "individual") }.not_to raise_error
|
36
36
|
end
|
37
37
|
|
38
|
-
it "creates a stripe recipient without a card" do
|
38
|
+
it "creates a stripe recipient without a card", skip: 'Stripe has deprecated Recipients' do
|
39
39
|
recipient = Stripe::Recipient.create({
|
40
40
|
type: "corporation",
|
41
41
|
name: "MyCo",
|
@@ -51,7 +51,7 @@ shared_examples 'Recipient API' do
|
|
51
51
|
expect(recipient.default_card).to be_nil
|
52
52
|
end
|
53
53
|
|
54
|
-
it "stores a created stripe recipient in memory" do
|
54
|
+
it "stores a created stripe recipient in memory", skip: 'Stripe has deprecated Recipients' do
|
55
55
|
recipient = Stripe::Recipient.create({
|
56
56
|
type: "individual",
|
57
57
|
name: "Customer One",
|
@@ -76,7 +76,7 @@ shared_examples 'Recipient API' do
|
|
76
76
|
expect(data[recipient2.id][:default_card]).to_not be_nil
|
77
77
|
end
|
78
78
|
|
79
|
-
it "retrieves a stripe recipient" do
|
79
|
+
it "retrieves a stripe recipient", skip: 'Stripe has deprecated Recipients' do
|
80
80
|
original = Stripe::Recipient.create({
|
81
81
|
type: "individual",
|
82
82
|
name: "Bob",
|
@@ -92,7 +92,7 @@ shared_examples 'Recipient API' do
|
|
92
92
|
expect(recipient.default_card).to_not be_nil
|
93
93
|
end
|
94
94
|
|
95
|
-
it "cannot retrieve a recipient that doesn't exist" do
|
95
|
+
it "cannot retrieve a recipient that doesn't exist", skip: 'Stripe has deprecated Recipients' do
|
96
96
|
expect { Stripe::Recipient.retrieve('nope') }.to raise_error {|e|
|
97
97
|
expect(e).to be_a Stripe::InvalidRequestError
|
98
98
|
expect(e.param).to eq('recipient')
|
@@ -100,7 +100,7 @@ shared_examples 'Recipient API' do
|
|
100
100
|
}
|
101
101
|
end
|
102
102
|
|
103
|
-
describe "Errors", :live => true do
|
103
|
+
describe "Errors", :live => true, skip: 'Stripe has deprecated Recipients' do
|
104
104
|
it "throws an error when the customer does not have the retrieving card id" do
|
105
105
|
recipient = Stripe::Recipient.create(:name => "Bob Bobber", :type => "individual")
|
106
106
|
card_id = "card_123"
|
@@ -262,7 +262,7 @@ shared_examples 'Refund API' do
|
|
262
262
|
end
|
263
263
|
|
264
264
|
it "stores all charges in memory" do
|
265
|
-
expect(Stripe::Refund.all.data.map(&:id)).to eq([@
|
265
|
+
expect(Stripe::Refund.all.data.map(&:id)).to eq([@refund2.id, @refund.id])
|
266
266
|
end
|
267
267
|
|
268
268
|
it "defaults count to 10 charges" do
|
@@ -337,26 +337,32 @@ shared_examples 'Refund API' do
|
|
337
337
|
capture: true
|
338
338
|
)
|
339
339
|
end
|
340
|
-
let(:
|
341
|
-
charge: charge.id
|
340
|
+
let(:refund_params) {{
|
341
|
+
charge: charge.id
|
342
|
+
}}
|
343
|
+
|
344
|
+
let(:refund_headers) {{
|
342
345
|
idempotency_key: 'onceisenough'
|
343
346
|
}}
|
344
347
|
|
345
348
|
it "returns the original refund if the same idempotency_key is passed in" do
|
346
|
-
refund1 = Stripe::Refund.create(
|
347
|
-
refund2 = Stripe::Refund.create(
|
349
|
+
refund1 = Stripe::Refund.create(refund_params, refund_headers)
|
350
|
+
refund2 = Stripe::Refund.create(refund_params, refund_headers)
|
348
351
|
|
349
352
|
expect(refund1).to eq(refund2)
|
350
353
|
end
|
351
354
|
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
+
context 'different key' do
|
356
|
+
let(:different_refund_headers) {{
|
357
|
+
idempotency_key: 'thisoneisdifferent'
|
358
|
+
}}
|
355
359
|
|
356
|
-
|
357
|
-
|
360
|
+
it "returns different charges if different idempotency_keys are used for each charge" do
|
361
|
+
refund1 = Stripe::Refund.create(refund_params, refund_headers)
|
362
|
+
refund2 = Stripe::Refund.create(refund_params, different_refund_headers)
|
358
363
|
|
359
|
-
|
364
|
+
expect(refund1).not_to eq(refund2)
|
365
|
+
end
|
360
366
|
end
|
361
367
|
end
|
362
368
|
end
|