stripe-ruby-mock 2.3.1 → 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 -13
- data/lib/stripe_mock/api/instance.rb +16 -6
- data/lib/stripe_mock/api/webhooks.rb +8 -1
- data/lib/stripe_mock/client.rb +18 -2
- data/lib/stripe_mock/data/list.rb +14 -2
- data/lib/stripe_mock/data.rb +398 -58
- data/lib/stripe_mock/instance.rb +105 -9
- data/lib/stripe_mock/request_handlers/accounts.rb +41 -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 +44 -33
- data/lib/stripe_mock/request_handlers/country_spec.rb +22 -0
- data/lib/stripe_mock/request_handlers/coupons.rb +5 -4
- data/lib/stripe_mock/request_handlers/customers.rb +29 -11
- 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 +59 -16
- data/lib/stripe_mock/request_handlers/helpers/token_helpers.rb +3 -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/recipients.rb +12 -0
- data/lib/stripe_mock/request_handlers/refunds.rb +91 -0
- data/lib/stripe_mock/request_handlers/subscription_items.rb +36 -0
- data/lib/stripe_mock/request_handlers/subscriptions.rb +101 -39
- 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 +15 -1
- data/lib/stripe_mock/server.rb +14 -1
- data/lib/stripe_mock/test_strategies/base.rb +10 -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.external_account.created.json +27 -0
- data/lib/stripe_mock/webhook_fixtures/account.external_account.deleted.json +27 -0
- data/lib/stripe_mock/webhook_fixtures/account.external_account.updated.json +27 -0
- 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 +15 -0
- data/spec/api/instance_spec.rb +30 -0
- data/spec/instance_spec.rb +54 -4
- data/spec/integration_examples/prepare_error_examples.rb +6 -6
- data/spec/list_spec.rb +27 -10
- data/spec/readme_spec.rb +2 -0
- data/spec/server_spec.rb +7 -3
- data/spec/shared_stripe_examples/account_examples.rb +46 -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 +23 -5
- data/spec/shared_stripe_examples/card_token_examples.rb +1 -0
- data/spec/shared_stripe_examples/charge_examples.rb +131 -26
- data/spec/shared_stripe_examples/country_specs_examples.rb +18 -0
- data/spec/shared_stripe_examples/coupon_examples.rb +8 -2
- data/spec/shared_stripe_examples/customer_examples.rb +90 -0
- 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 +15 -5
- 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 +47 -4
- data/spec/shared_stripe_examples/product_example.rb +65 -0
- data/spec/shared_stripe_examples/recipient_examples.rb +13 -7
- data/spec/shared_stripe_examples/refund_examples.rb +453 -84
- data/spec/shared_stripe_examples/subscription_examples.rb +477 -32
- 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 +8 -1
- data/spec/util_spec.rb +35 -1
- data/stripe-ruby-mock.gemspec +1 -1
- metadata +44 -8
- data/ChangeLog.rdoc +0 -4
@@ -6,100 +6,107 @@
|
|
6
6
|
"object": "event",
|
7
7
|
"data": {
|
8
8
|
"object": {
|
9
|
-
"date": 1394018368,
|
10
9
|
"id": "in_00000000000000",
|
11
|
-
"
|
12
|
-
"
|
10
|
+
"object": "invoice",
|
11
|
+
"amount_due": 999,
|
12
|
+
"application_fee": null,
|
13
|
+
"attempt_count": 1,
|
14
|
+
"attempted": true,
|
15
|
+
"charge": "ch_18EcOcLrgDIZ7iq8TaNlErVv",
|
16
|
+
"closed": true,
|
17
|
+
"currency": "eur",
|
18
|
+
"customer": "cus_00000000000000",
|
19
|
+
"created": 1464084258,
|
20
|
+
"description": null,
|
21
|
+
"discount": null,
|
22
|
+
"ending_balance": 0,
|
23
|
+
"forgiven": false,
|
13
24
|
"lines": {
|
14
|
-
"
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
"
|
25
|
-
"
|
26
|
-
"period": {
|
27
|
-
"start": 1393765661,
|
28
|
-
"end": 1393765661
|
29
|
-
},
|
30
|
-
"quantity": null,
|
31
|
-
"plan": null,
|
32
|
-
"description": "Remaining time on Platinum after 02 Mar 2014",
|
33
|
-
"metadata": {}
|
25
|
+
"data": [{
|
26
|
+
"id": "sub_00000000000000",
|
27
|
+
"object": "line_item",
|
28
|
+
"amount": 50,
|
29
|
+
"currency": "eur",
|
30
|
+
"description": null,
|
31
|
+
"discountable": true,
|
32
|
+
"livemode": true,
|
33
|
+
"metadata": {},
|
34
|
+
"period": {
|
35
|
+
"start": 1500637196,
|
36
|
+
"end": 1532173196
|
34
37
|
},
|
35
|
-
{
|
36
|
-
"id": "
|
37
|
-
"object": "
|
38
|
-
"
|
38
|
+
"plan": {
|
39
|
+
"id": "platinum",
|
40
|
+
"object": "plan",
|
41
|
+
"amount": 500,
|
42
|
+
"created": 1499943145,
|
43
|
+
"currency": "eur",
|
44
|
+
"interval": "month",
|
45
|
+
"interval_count": 1,
|
39
46
|
"livemode": false,
|
40
|
-
"
|
41
|
-
"
|
42
|
-
"
|
43
|
-
"
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
47
|
+
"metadata": {},
|
48
|
+
"name": "New Plan Test",
|
49
|
+
"statement_descriptor": null,
|
50
|
+
"trial_period_days": null
|
51
|
+
},
|
52
|
+
"proration": false,
|
53
|
+
"quantity": 1,
|
54
|
+
"subscription": null,
|
55
|
+
"subscription_item": "si_18ZfWyLrgDIZ7iq8fSlSNGIV",
|
56
|
+
"type": "subscription"
|
57
|
+
},
|
58
|
+
{
|
59
|
+
"id": "sub_00000000000000",
|
60
|
+
"object": "line_item",
|
61
|
+
"amount": 50,
|
62
|
+
"currency": "eur",
|
63
|
+
"description": null,
|
64
|
+
"discountable": true,
|
65
|
+
"livemode": true,
|
66
|
+
"metadata": {},
|
67
|
+
"period": {
|
68
|
+
"start": 1500637196,
|
69
|
+
"end": 1532173196
|
51
70
|
},
|
52
|
-
{
|
53
|
-
"id": "
|
54
|
-
"object": "
|
55
|
-
"
|
71
|
+
"plan": {
|
72
|
+
"id": "gold",
|
73
|
+
"object": "plan",
|
74
|
+
"amount": 300,
|
75
|
+
"created": 1499943155,
|
76
|
+
"currency": "eur",
|
77
|
+
"interval": "month",
|
78
|
+
"interval_count": 1,
|
56
79
|
"livemode": false,
|
57
|
-
"
|
58
|
-
"
|
59
|
-
"
|
60
|
-
"
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
"id": "platinum",
|
72
|
-
"object": "plan",
|
73
|
-
"livemode": false,
|
74
|
-
"interval_count": 1,
|
75
|
-
"trial_period_days": null,
|
76
|
-
"metadata": {}
|
77
|
-
},
|
78
|
-
"description": null,
|
79
|
-
"metadata": null
|
80
|
-
}
|
81
|
-
]
|
80
|
+
"metadata": {},
|
81
|
+
"name": "New gold Plan Test",
|
82
|
+
"statement_descriptor": null,
|
83
|
+
"trial_period_days": null
|
84
|
+
},
|
85
|
+
"proration": false,
|
86
|
+
"quantity": 1,
|
87
|
+
"subscription": null,
|
88
|
+
"subscription_item": "si_18ZfWyLrgDIZ7iq8fSlSNGIV",
|
89
|
+
"type": "subscription"
|
90
|
+
}],
|
91
|
+
"total_count": 1,
|
92
|
+
"object": "list",
|
93
|
+
"url": "/v1/invoices/in_18EcOcLrgDIZ7iq8zsDkunZ0/lines"
|
82
94
|
},
|
83
|
-
"subtotal": 30000,
|
84
|
-
"total": 30000,
|
85
|
-
"customer": "cus_00000000000000",
|
86
|
-
"object": "invoice",
|
87
|
-
"attempted": true,
|
88
|
-
"closed": true,
|
89
|
-
"paid": true,
|
90
95
|
"livemode": false,
|
91
|
-
"attempt_count": 1,
|
92
|
-
"amount_due": 0,
|
93
|
-
"currency": "usd",
|
94
|
-
"starting_balance": 0,
|
95
|
-
"ending_balance": 0,
|
96
|
-
"next_payment_attempt": null,
|
97
|
-
"charge": "ch_00000000000000",
|
98
|
-
"discount": null,
|
99
|
-
"application_fee": null,
|
100
|
-
"subscription": "su_00000000000000",
|
101
96
|
"metadata": {},
|
102
|
-
"
|
97
|
+
"next_payment_attempt": null,
|
98
|
+
"paid": true,
|
99
|
+
"period_end": 1464084258,
|
100
|
+
"period_start": 1464084258,
|
101
|
+
"receipt_number": null,
|
102
|
+
"starting_balance": 0,
|
103
|
+
"statement_descriptor": null,
|
104
|
+
"subscription": "sub_00000000000000",
|
105
|
+
"subtotal": 999,
|
106
|
+
"tax": null,
|
107
|
+
"tax_percent": null,
|
108
|
+
"total": 999,
|
109
|
+
"webhooks_delivered_at": 1464084258
|
103
110
|
}
|
104
111
|
}
|
105
112
|
}
|
@@ -3,10 +3,11 @@
|
|
3
3
|
"livemode": false,
|
4
4
|
"id": "evt_00000000000000",
|
5
5
|
"type": "invoice.updated",
|
6
|
+
"status": "paid",
|
6
7
|
"object": "event",
|
7
8
|
"data": {
|
8
9
|
"object": {
|
9
|
-
"
|
10
|
+
"created": 1380674206,
|
10
11
|
"id": "in_00000000000000",
|
11
12
|
"period_start": 1378082075,
|
12
13
|
"period_end": 1380674075,
|
@@ -30,7 +31,7 @@
|
|
30
31
|
"quantity": 1,
|
31
32
|
"plan": {
|
32
33
|
"interval": "month",
|
33
|
-
"
|
34
|
+
"product": "pr_00000000000000",
|
34
35
|
"amount": 100,
|
35
36
|
"currency": "usd",
|
36
37
|
"id": "fkx0AFo",
|
data/lib/stripe_mock.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'ostruct'
|
2
2
|
require 'multi_json'
|
3
3
|
require 'dante'
|
4
|
+
require 'time'
|
4
5
|
|
5
6
|
require 'stripe'
|
6
7
|
|
@@ -26,6 +27,8 @@ require 'stripe_mock/api/client'
|
|
26
27
|
require 'stripe_mock/api/server'
|
27
28
|
|
28
29
|
require 'stripe_mock/api/bank_tokens'
|
30
|
+
require 'stripe_mock/api/account_balance'
|
31
|
+
require 'stripe_mock/api/conversion_rate'
|
29
32
|
require 'stripe_mock/api/card_tokens'
|
30
33
|
require 'stripe_mock/api/debug'
|
31
34
|
require 'stripe_mock/api/errors'
|
@@ -35,6 +38,7 @@ require 'stripe_mock/api/test_helpers'
|
|
35
38
|
require 'stripe_mock/api/webhooks'
|
36
39
|
|
37
40
|
require 'stripe_mock/request_handlers/helpers/bank_account_helpers.rb'
|
41
|
+
require 'stripe_mock/request_handlers/helpers/external_account_helpers.rb'
|
38
42
|
require 'stripe_mock/request_handlers/helpers/card_helpers.rb'
|
39
43
|
require 'stripe_mock/request_handlers/helpers/charge_helpers.rb'
|
40
44
|
require 'stripe_mock/request_handlers/helpers/coupon_helpers.rb'
|
@@ -44,6 +48,8 @@ require 'stripe_mock/request_handlers/helpers/token_helpers.rb'
|
|
44
48
|
require 'stripe_mock/request_handlers/validators/param_validators.rb'
|
45
49
|
|
46
50
|
require 'stripe_mock/request_handlers/accounts.rb'
|
51
|
+
require 'stripe_mock/request_handlers/external_accounts.rb'
|
52
|
+
require 'stripe_mock/request_handlers/balance.rb'
|
47
53
|
require 'stripe_mock/request_handlers/balance_transactions.rb'
|
48
54
|
require 'stripe_mock/request_handlers/charges.rb'
|
49
55
|
require 'stripe_mock/request_handlers/cards.rb'
|
@@ -57,9 +63,16 @@ require 'stripe_mock/request_handlers/invoice_items.rb'
|
|
57
63
|
require 'stripe_mock/request_handlers/orders.rb'
|
58
64
|
require 'stripe_mock/request_handlers/plans.rb'
|
59
65
|
require 'stripe_mock/request_handlers/recipients.rb'
|
66
|
+
require 'stripe_mock/request_handlers/refunds.rb'
|
60
67
|
require 'stripe_mock/request_handlers/transfers.rb'
|
68
|
+
require 'stripe_mock/request_handlers/payouts.rb'
|
61
69
|
require 'stripe_mock/request_handlers/subscriptions.rb'
|
70
|
+
require 'stripe_mock/request_handlers/subscription_items.rb'
|
62
71
|
require 'stripe_mock/request_handlers/tokens.rb'
|
72
|
+
require 'stripe_mock/request_handlers/country_spec.rb'
|
73
|
+
require 'stripe_mock/request_handlers/ephemeral_key.rb'
|
74
|
+
require 'stripe_mock/request_handlers/products.rb'
|
75
|
+
require 'stripe_mock/request_handlers/tax_rates.rb'
|
63
76
|
require 'stripe_mock/instance'
|
64
77
|
|
65
78
|
require 'stripe_mock/test_strategies/base.rb'
|
@@ -68,11 +81,13 @@ require 'stripe_mock/test_strategies/live.rb'
|
|
68
81
|
|
69
82
|
module StripeMock
|
70
83
|
|
84
|
+
@default_currency = 'usd'
|
71
85
|
lib_dir = File.expand_path(File.dirname(__FILE__), '../..')
|
72
86
|
@webhook_fixture_path = './spec/fixtures/stripe_webhooks/'
|
73
87
|
@webhook_fixture_fallback_path = File.join(lib_dir, 'stripe_mock/webhook_fixtures')
|
74
88
|
|
75
89
|
class << self
|
90
|
+
attr_accessor :default_currency
|
76
91
|
attr_accessor :webhook_fixture_path
|
77
92
|
end
|
78
93
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe StripeMock do
|
4
|
+
describe ".mock" do
|
5
|
+
it "yields the given block between starting and stopping StripeMock" do
|
6
|
+
expect(StripeMock.instance).to be_nil
|
7
|
+
expect(StripeMock.state).to eq "ready"
|
8
|
+
|
9
|
+
StripeMock.mock do
|
10
|
+
expect(StripeMock.instance).to be_instance_of StripeMock::Instance
|
11
|
+
expect(StripeMock.state).to eq "local"
|
12
|
+
end
|
13
|
+
|
14
|
+
expect(StripeMock.instance).to be_nil
|
15
|
+
expect(StripeMock.state).to eq "ready"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "stops StripeMock if the given block raises an exception" do
|
19
|
+
expect(StripeMock.instance).to be_nil
|
20
|
+
begin
|
21
|
+
StripeMock.mock do
|
22
|
+
raise "Uh-oh..."
|
23
|
+
end
|
24
|
+
rescue
|
25
|
+
expect(StripeMock.instance).to be_nil
|
26
|
+
expect(StripeMock.state).to eq "ready"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/spec/instance_spec.rb
CHANGED
@@ -17,9 +17,9 @@ describe StripeMock::Instance do
|
|
17
17
|
"id" => "str_abcde",
|
18
18
|
:name => "String Plan"
|
19
19
|
)
|
20
|
-
res, api_key = StripeMock.instance.mock_request('post', '/v1/plans', 'api_key', string_params)
|
21
|
-
expect(res[:id]).to eq('str_abcde')
|
22
|
-
expect(res[:name]).to eq('String Plan')
|
20
|
+
res, api_key = StripeMock.instance.mock_request('post', '/v1/plans', api_key: 'api_key', params: string_params)
|
21
|
+
expect(res.data[:id]).to eq('str_abcde')
|
22
|
+
expect(res.data[:name]).to eq('String Plan')
|
23
23
|
end
|
24
24
|
|
25
25
|
it "exits gracefully on an unrecognized handler url" do
|
@@ -28,7 +28,7 @@ describe StripeMock::Instance do
|
|
28
28
|
"name" => "PLAN"
|
29
29
|
}
|
30
30
|
|
31
|
-
expect { res, api_key = StripeMock.instance.mock_request('post', '/v1/unrecongnized_method', 'api_key', dummy_params) }.to_not raise_error
|
31
|
+
expect { res, api_key = StripeMock.instance.mock_request('post', '/v1/unrecongnized_method', api_key: 'api_key', params: dummy_params) }.to_not raise_error
|
32
32
|
end
|
33
33
|
|
34
34
|
it "can toggle debug" do
|
@@ -47,4 +47,54 @@ describe StripeMock::Instance do
|
|
47
47
|
StripeMock.start
|
48
48
|
expect(StripeMock.instance.debug).to eq(false)
|
49
49
|
end
|
50
|
+
|
51
|
+
it "can set a conversion rate" do
|
52
|
+
StripeMock.set_conversion_rate(1.25)
|
53
|
+
expect(StripeMock.instance.conversion_rate).to eq(1.25)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "allows non-usd default currency" do
|
57
|
+
old_default_currency = StripeMock.default_currency
|
58
|
+
customer = begin
|
59
|
+
StripeMock.default_currency = "jpy"
|
60
|
+
Stripe::Customer.create({
|
61
|
+
email: 'johnny@appleseed.com',
|
62
|
+
source: stripe_helper.generate_card_token
|
63
|
+
})
|
64
|
+
ensure
|
65
|
+
StripeMock.default_currency = old_default_currency
|
66
|
+
end
|
67
|
+
expect(customer.currency).to eq("jpy")
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'when creating sources with metadata' do
|
71
|
+
let(:customer) { Stripe::Customer.create(email: 'test@email.com') }
|
72
|
+
let(:metadata) { { test_key: 'test_value' } }
|
73
|
+
|
74
|
+
context 'for credit card' do
|
75
|
+
let(:credit_card) do
|
76
|
+
customer.sources.create(
|
77
|
+
source: stripe_helper.generate_card_token,
|
78
|
+
metadata: metadata
|
79
|
+
)
|
80
|
+
end
|
81
|
+
|
82
|
+
it('should save metadata') do
|
83
|
+
expect(credit_card.metadata.test_key).to eq metadata[:test_key]
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'for bank account' do
|
88
|
+
let(:bank_account) do
|
89
|
+
customer.sources.create(
|
90
|
+
source: stripe_helper.generate_bank_token,
|
91
|
+
metadata: metadata
|
92
|
+
)
|
93
|
+
end
|
94
|
+
|
95
|
+
it('should save metadata') do
|
96
|
+
expect(bank_account.metadata.test_key).to eq metadata[:test_key]
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
50
100
|
end
|
@@ -26,13 +26,13 @@ shared_examples 'Card Error Prep' do
|
|
26
26
|
)
|
27
27
|
rescue Stripe::CardError => e
|
28
28
|
body = e.json_body
|
29
|
-
err = body[:error]
|
30
|
-
|
31
29
|
expect(body).to be_a(Hash)
|
32
|
-
|
33
|
-
|
34
|
-
expect(
|
35
|
-
expect(
|
30
|
+
error = body[:error]
|
31
|
+
|
32
|
+
expect(error[:type]).to eq 'card_error'
|
33
|
+
expect(error[:param]).to eq 'number'
|
34
|
+
expect(error[:code]).to eq 'invalid_number'
|
35
|
+
expect(error[:message]).to eq 'The card number is not a valid credit card number.'
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
data/spec/list_spec.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require "spec_helper"
|
2
2
|
|
3
3
|
describe StripeMock::Data::List do
|
4
|
+
let(:stripe_helper) { StripeMock.create_test_helper }
|
5
|
+
|
4
6
|
before :all do
|
5
7
|
StripeMock.start
|
6
8
|
end
|
@@ -32,16 +34,30 @@ describe StripeMock::Data::List do
|
|
32
34
|
expect(list.url).to eq("/v1/customers")
|
33
35
|
end
|
34
36
|
|
37
|
+
it "returns in descending order if created available" do
|
38
|
+
charge_newer = Stripe::Charge.create(amount: 1, currency: 'usd', source: stripe_helper.generate_card_token, created: 5)
|
39
|
+
charge_older = Stripe::Charge.create(amount: 1, currency: 'usd', source: stripe_helper.generate_card_token, created: 4)
|
40
|
+
list = StripeMock::Data::List.new([charge_older, charge_newer])
|
41
|
+
hash = list.to_h
|
42
|
+
|
43
|
+
expect(hash).to eq(
|
44
|
+
object: "list",
|
45
|
+
data: [charge_newer, charge_older],
|
46
|
+
url: "/v1/charges",
|
47
|
+
has_more: false
|
48
|
+
)
|
49
|
+
end
|
50
|
+
|
35
51
|
it "eventually gets turned into a hash" do
|
36
|
-
charge1 = Stripe::Charge.create(amount: 1, currency: 'usd')
|
37
|
-
charge2 = Stripe::Charge.create(amount: 1, currency: 'usd')
|
38
|
-
charge3 = Stripe::Charge.create(amount: 1, currency: 'usd')
|
52
|
+
charge1 = Stripe::Charge.create(amount: 1, currency: 'usd', source: stripe_helper.generate_card_token)
|
53
|
+
charge2 = Stripe::Charge.create(amount: 1, currency: 'usd', source: stripe_helper.generate_card_token)
|
54
|
+
charge3 = Stripe::Charge.create(amount: 1, currency: 'usd', source: stripe_helper.generate_card_token)
|
39
55
|
list = StripeMock::Data::List.new([charge1, charge2, charge3])
|
40
56
|
hash = list.to_h
|
41
57
|
|
42
58
|
expect(hash).to eq(
|
43
59
|
object: "list",
|
44
|
-
data: [
|
60
|
+
data: [charge3, charge2, charge1],
|
45
61
|
url: "/v1/charges",
|
46
62
|
has_more: false
|
47
63
|
)
|
@@ -95,26 +111,27 @@ describe StripeMock::Data::List do
|
|
95
111
|
|
96
112
|
context "pagination" do
|
97
113
|
it "has a has_more field when it has more" do
|
98
|
-
list = StripeMock::Data::List.new(
|
114
|
+
list = StripeMock::Data::List.new(
|
115
|
+
[Stripe::Charge.create(amount: 1, currency: 'usd', source: stripe_helper.generate_card_token)] * 256
|
116
|
+
)
|
99
117
|
|
100
118
|
expect(list).to have_more
|
101
119
|
end
|
102
120
|
|
103
121
|
it "accepts a starting_after parameter" do
|
104
122
|
data = []
|
105
|
-
255.times { data << Stripe::Charge.create(amount: 1, currency: 'usd') }
|
106
|
-
new_charge = Stripe::Charge.create(amount: 1, currency: 'usd')
|
123
|
+
255.times { data << Stripe::Charge.create(amount: 1, currency: 'usd', source: stripe_helper.generate_card_token) }
|
124
|
+
new_charge = Stripe::Charge.create(amount: 1, currency: 'usd', source: stripe_helper.generate_card_token)
|
107
125
|
data[89] = new_charge
|
108
126
|
list = StripeMock::Data::List.new(data, starting_after: new_charge.id)
|
109
127
|
hash = list.to_h
|
110
|
-
|
111
128
|
expect(hash[:data].size).to eq(10)
|
112
|
-
expect(hash[:data]).to eq(data[
|
129
|
+
expect(hash[:data]).to eq(data[79, 10].reverse)
|
113
130
|
end
|
114
131
|
|
115
132
|
it "raises an error if starting_after cursor is not found" do
|
116
133
|
data = []
|
117
|
-
255.times { data << Stripe::Charge.create(amount: 1, currency: 'usd') }
|
134
|
+
255.times { data << Stripe::Charge.create(amount: 1, currency: 'usd', source: stripe_helper.generate_card_token) }
|
118
135
|
list = StripeMock::Data::List.new(data, starting_after: "test_ch_unknown")
|
119
136
|
|
120
137
|
expect { list.to_h }.to raise_error
|
data/spec/readme_spec.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'stripe_mock'
|
1
2
|
|
2
3
|
describe 'README examples' do
|
3
4
|
let(:stripe_helper) { StripeMock.create_test_helper }
|
@@ -24,6 +25,7 @@ describe 'README examples' do
|
|
24
25
|
expect(e).to be_a Stripe::CardError
|
25
26
|
expect(e.http_status).to eq(402)
|
26
27
|
expect(e.code).to eq('card_declined')
|
28
|
+
expect(e.json_body[:error][:decline_code]).to eq('do_not_honor')
|
27
29
|
}
|
28
30
|
end
|
29
31
|
|
data/spec/server_spec.rb
CHANGED
@@ -24,7 +24,7 @@ describe 'StripeMock Server', :mock_server => true do
|
|
24
24
|
charge = Stripe::Charge.create(
|
25
25
|
amount: 987,
|
26
26
|
currency: 'USD',
|
27
|
-
|
27
|
+
source: stripe_helper.generate_card_token,
|
28
28
|
description: 'card charge'
|
29
29
|
)
|
30
30
|
expect(charge.amount).to eq(987)
|
@@ -52,8 +52,8 @@ describe 'StripeMock Server', :mock_server => true do
|
|
52
52
|
|
53
53
|
it "returns a response with symbolized hash keys" do
|
54
54
|
stripe_helper.create_plan(id: 'x')
|
55
|
-
response, api_key = StripeMock.redirect_to_mock_server('get', '/v1/plans/x', 'xxx')
|
56
|
-
response.keys.each {|k| expect(k).to be_a(Symbol) }
|
55
|
+
response, api_key = StripeMock.redirect_to_mock_server('get', '/v1/plans/x', api_key: 'xxx')
|
56
|
+
response.data.keys.each {|k| expect(k).to be_a(Symbol) }
|
57
57
|
end
|
58
58
|
|
59
59
|
|
@@ -132,4 +132,8 @@ describe 'StripeMock Server', :mock_server => true do
|
|
132
132
|
end
|
133
133
|
end
|
134
134
|
|
135
|
+
it "can set a conversion rate" do
|
136
|
+
StripeMock.set_conversion_rate(1.2)
|
137
|
+
expect(StripeMock.client.get_conversion_rate).to eq(1.2)
|
138
|
+
end
|
135
139
|
end
|
@@ -34,6 +34,9 @@ shared_examples 'Account API' do
|
|
34
34
|
expect(account.keys).not_to be_nil
|
35
35
|
expect(account.keys.secret).to match /sk_(live|test)_[\d\w]+/
|
36
36
|
expect(account.keys.publishable).to match /pk_(live|test)_[\d\w]+/
|
37
|
+
expect(account.external_accounts).not_to be_nil
|
38
|
+
expect(account.external_accounts.data).to be_an Array
|
39
|
+
expect(account.external_accounts.url).to match /\/v1\/accounts\/.*\/external_accounts/
|
37
40
|
end
|
38
41
|
end
|
39
42
|
describe 'updates account' do
|
@@ -46,5 +49,48 @@ shared_examples 'Account API' do
|
|
46
49
|
|
47
50
|
expect(account.support_phone).to eq '1234567'
|
48
51
|
end
|
52
|
+
|
53
|
+
it 'raises when sending an empty tos date' do
|
54
|
+
account = Stripe::Account.retrieve
|
55
|
+
account.tos_acceptance.date = nil
|
56
|
+
expect {
|
57
|
+
account.save
|
58
|
+
}.to raise_error
|
59
|
+
end
|
60
|
+
|
61
|
+
context 'with tos acceptance date' do
|
62
|
+
let(:error_message) { "ToS acceptance date is not valid. Dates are expected to be integers, measured in seconds, not in the future, and after 2009" }
|
63
|
+
|
64
|
+
it 'raises error when tos date is before 2009' do
|
65
|
+
date = Date.new(2008,1,1).strftime("%s").to_i
|
66
|
+
|
67
|
+
account = Stripe::Account.retrieve
|
68
|
+
account.tos_acceptance.date = date
|
69
|
+
|
70
|
+
expect {
|
71
|
+
account.save
|
72
|
+
}.to raise_error Stripe::InvalidRequestError, error_message
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'raises error when tos date is in the future' do
|
76
|
+
year = Time.now.year + 5
|
77
|
+
date = Date.new(year,1,1).strftime("%s").to_i
|
78
|
+
|
79
|
+
account = Stripe::Account.retrieve
|
80
|
+
account.tos_acceptance.date = date
|
81
|
+
|
82
|
+
expect {
|
83
|
+
account.save
|
84
|
+
}.to raise_error Stripe::InvalidRequestError, error_message
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'deauthorizes the stripe account', live: false do
|
90
|
+
account = Stripe::Account.retrieve
|
91
|
+
result = account.deauthorize('CLIENT_ID')
|
92
|
+
|
93
|
+
expect(result).to be_a Stripe::StripeObject
|
94
|
+
expect(result[:stripe_user_id]).to eq account[:id]
|
49
95
|
end
|
50
96
|
end
|