stripe-ruby-mock 2.5.8 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.github/workflows/rspec_tests.yml +38 -0
- data/.gitignore +1 -1
- data/.rspec +2 -1
- data/CHANGELOG.md +77 -0
- data/Gemfile +1 -5
- data/README.md +19 -11
- data/lib/stripe_mock/api/client.rb +2 -2
- data/lib/stripe_mock/api/errors.rb +34 -28
- data/lib/stripe_mock/api/instance.rb +1 -1
- data/lib/stripe_mock/api/webhooks.rb +68 -24
- data/lib/stripe_mock/client.rb +2 -1
- data/lib/stripe_mock/data/list.rb +42 -9
- data/lib/stripe_mock/data.rb +359 -21
- data/lib/stripe_mock/instance.rb +23 -5
- data/lib/stripe_mock/request_handlers/account_links.rb +15 -0
- data/lib/stripe_mock/request_handlers/accounts.rb +17 -6
- data/lib/stripe_mock/request_handlers/balance_transactions.rb +2 -2
- data/lib/stripe_mock/request_handlers/charges.rb +31 -5
- data/lib/stripe_mock/request_handlers/checkout_session.rb +179 -0
- data/lib/stripe_mock/request_handlers/customers.rb +47 -19
- data/lib/stripe_mock/request_handlers/ephemeral_key.rb +1 -1
- data/lib/stripe_mock/request_handlers/events.rb +30 -3
- data/lib/stripe_mock/request_handlers/express_login_links.rb +15 -0
- data/lib/stripe_mock/request_handlers/helpers/coupon_helpers.rb +6 -0
- data/lib/stripe_mock/request_handlers/helpers/search_helpers.rb +67 -0
- data/lib/stripe_mock/request_handlers/helpers/subscription_helpers.rb +36 -12
- data/lib/stripe_mock/request_handlers/helpers/token_helpers.rb +1 -1
- data/lib/stripe_mock/request_handlers/invoices.rb +26 -6
- data/lib/stripe_mock/request_handlers/payment_intents.rb +202 -0
- data/lib/stripe_mock/request_handlers/payment_methods.rb +124 -0
- data/lib/stripe_mock/request_handlers/plans.rb +1 -1
- data/lib/stripe_mock/request_handlers/prices.rb +71 -0
- data/lib/stripe_mock/request_handlers/products.rb +15 -5
- data/lib/stripe_mock/request_handlers/promotion_codes.rb +43 -0
- data/lib/stripe_mock/request_handlers/refunds.rb +13 -2
- data/lib/stripe_mock/request_handlers/setup_intents.rb +100 -0
- data/lib/stripe_mock/request_handlers/sources.rb +12 -6
- data/lib/stripe_mock/request_handlers/subscriptions.rb +146 -25
- data/lib/stripe_mock/request_handlers/tokens.rb +6 -4
- data/lib/stripe_mock/request_handlers/transfers.rb +12 -1
- data/lib/stripe_mock/request_handlers/validators/param_validators.rb +124 -9
- data/lib/stripe_mock/server.rb +2 -2
- data/lib/stripe_mock/test_strategies/base.rb +98 -12
- data/lib/stripe_mock/test_strategies/live.rb +23 -12
- data/lib/stripe_mock/test_strategies/mock.rb +6 -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/balance.available.json +27 -15
- data/lib/stripe_mock/webhook_fixtures/charge.captured.json +143 -0
- data/lib/stripe_mock/webhook_fixtures/charge.dispute.created.json +63 -16
- data/lib/stripe_mock/webhook_fixtures/charge.failed.json +101 -44
- data/lib/stripe_mock/webhook_fixtures/charge.refund.updated.json +35 -0
- data/lib/stripe_mock/webhook_fixtures/charge.refunded.json +145 -50
- data/lib/stripe_mock/webhook_fixtures/charge.succeeded.json +114 -43
- data/lib/stripe_mock/webhook_fixtures/checkout.session.completed.json +79 -0
- data/lib/stripe_mock/webhook_fixtures/checkout.session.completed.payment_mode.json +53 -0
- data/lib/stripe_mock/webhook_fixtures/checkout.session.completed.setup_mode.json +45 -0
- data/lib/stripe_mock/webhook_fixtures/customer.created.json +37 -45
- data/lib/stripe_mock/webhook_fixtures/customer.deleted.json +36 -32
- data/lib/stripe_mock/webhook_fixtures/customer.source.created.json +31 -22
- data/lib/stripe_mock/webhook_fixtures/customer.source.updated.json +36 -25
- data/lib/stripe_mock/webhook_fixtures/customer.subscription.created.json +135 -47
- data/lib/stripe_mock/webhook_fixtures/customer.subscription.deleted.json +134 -45
- data/lib/stripe_mock/webhook_fixtures/customer.subscription.updated.json +135 -56
- data/lib/stripe_mock/webhook_fixtures/customer.updated.json +38 -46
- data/lib/stripe_mock/webhook_fixtures/invoice.created.json +176 -49
- data/lib/stripe_mock/webhook_fixtures/invoice.finalized.json +171 -0
- data/lib/stripe_mock/webhook_fixtures/invoice.paid.json +171 -0
- data/lib/stripe_mock/webhook_fixtures/invoice.payment_action_required.json +171 -0
- data/lib/stripe_mock/webhook_fixtures/invoice.payment_failed.json +149 -83
- data/lib/stripe_mock/webhook_fixtures/invoice.payment_succeeded.json +149 -90
- data/lib/stripe_mock/webhook_fixtures/invoice.upcoming.json +70 -0
- data/lib/stripe_mock/webhook_fixtures/invoice.updated.json +178 -50
- data/lib/stripe_mock/webhook_fixtures/invoiceitem.created.json +87 -13
- data/lib/stripe_mock/webhook_fixtures/invoiceitem.updated.json +88 -14
- data/lib/stripe_mock/webhook_fixtures/mandate.updated.json +34 -0
- data/lib/stripe_mock/webhook_fixtures/payment_intent.amount_capturable_updated.json +170 -0
- data/lib/stripe_mock/webhook_fixtures/payment_intent.canceled.json +73 -0
- data/lib/stripe_mock/webhook_fixtures/payment_intent.created.json +86 -0
- data/lib/stripe_mock/webhook_fixtures/payment_intent.payment_failed.json +225 -0
- data/lib/stripe_mock/webhook_fixtures/payment_intent.processing.json +162 -0
- data/lib/stripe_mock/webhook_fixtures/payment_intent.requires_action.json +191 -0
- data/lib/stripe_mock/webhook_fixtures/payment_intent.succeeded.json +196 -0
- data/lib/stripe_mock/webhook_fixtures/payment_link.created.json +47 -0
- data/lib/stripe_mock/webhook_fixtures/payment_link.updated.json +50 -0
- data/lib/stripe_mock/webhook_fixtures/payment_method.attached.json +63 -0
- data/lib/stripe_mock/webhook_fixtures/payment_method.detached.json +62 -0
- data/lib/stripe_mock/webhook_fixtures/payout.created.json +40 -0
- data/lib/stripe_mock/webhook_fixtures/payout.paid.json +40 -0
- data/lib/stripe_mock/webhook_fixtures/payout.updated.json +46 -0
- data/lib/stripe_mock/webhook_fixtures/plan.created.json +30 -13
- data/lib/stripe_mock/webhook_fixtures/plan.deleted.json +30 -13
- data/lib/stripe_mock/webhook_fixtures/plan.updated.json +34 -14
- data/lib/stripe_mock/webhook_fixtures/price.created.json +42 -0
- data/lib/stripe_mock/webhook_fixtures/price.deleted.json +42 -0
- data/lib/stripe_mock/webhook_fixtures/price.updated.json +48 -0
- data/lib/stripe_mock/webhook_fixtures/product.created.json +40 -0
- data/lib/stripe_mock/webhook_fixtures/product.deleted.json +40 -0
- data/lib/stripe_mock/webhook_fixtures/product.updated.json +47 -0
- data/lib/stripe_mock/webhook_fixtures/quote.accepted.json +92 -0
- data/lib/stripe_mock/webhook_fixtures/quote.canceled.json +92 -0
- data/lib/stripe_mock/webhook_fixtures/quote.created.json +92 -0
- data/lib/stripe_mock/webhook_fixtures/quote.finalized.json +92 -0
- data/lib/stripe_mock/webhook_fixtures/setup_intent.canceled.json +46 -0
- data/lib/stripe_mock/webhook_fixtures/setup_intent.created.json +51 -0
- data/lib/stripe_mock/webhook_fixtures/setup_intent.setup_failed.json +100 -0
- data/lib/stripe_mock/webhook_fixtures/setup_intent.succeeded.json +46 -0
- data/lib/stripe_mock/webhook_fixtures/subscription_schedule.canceled.json +119 -0
- data/lib/stripe_mock/webhook_fixtures/subscription_schedule.created.json +114 -0
- data/lib/stripe_mock/webhook_fixtures/subscription_schedule.released.json +111 -0
- data/lib/stripe_mock/webhook_fixtures/subscription_schedule.updated.json +125 -0
- data/lib/stripe_mock/webhook_fixtures/tax_rate.created.json +32 -0
- data/lib/stripe_mock/webhook_fixtures/tax_rate.updated.json +37 -0
- data/lib/stripe_mock.rb +11 -0
- data/spec/instance_spec.rb +13 -13
- data/spec/integration_examples/completing_checkout_sessions_example.rb +37 -0
- data/spec/list_spec.rb +38 -0
- data/spec/readme_spec.rb +1 -1
- data/spec/server_spec.rb +6 -3
- data/spec/shared_stripe_examples/account_examples.rb +10 -2
- data/spec/shared_stripe_examples/account_link_examples.rb +16 -0
- data/spec/shared_stripe_examples/balance_examples.rb +6 -0
- data/spec/shared_stripe_examples/balance_transaction_examples.rb +3 -3
- data/spec/shared_stripe_examples/bank_examples.rb +3 -3
- data/spec/shared_stripe_examples/bank_token_examples.rb +5 -7
- data/spec/shared_stripe_examples/card_examples.rb +4 -4
- data/spec/shared_stripe_examples/card_token_examples.rb +17 -21
- data/spec/shared_stripe_examples/charge_examples.rb +106 -22
- data/spec/shared_stripe_examples/checkout_session_examples.rb +99 -0
- data/spec/shared_stripe_examples/coupon_examples.rb +1 -1
- data/spec/shared_stripe_examples/customer_examples.rb +149 -53
- data/spec/shared_stripe_examples/dispute_examples.rb +2 -2
- data/spec/shared_stripe_examples/error_mock_examples.rb +8 -7
- data/spec/shared_stripe_examples/express_login_link_examples.rb +12 -0
- data/spec/shared_stripe_examples/external_account_examples.rb +3 -3
- data/spec/shared_stripe_examples/invoice_examples.rb +148 -40
- data/spec/shared_stripe_examples/invoice_item_examples.rb +1 -1
- data/spec/shared_stripe_examples/payment_intent_examples.rb +283 -0
- data/spec/shared_stripe_examples/payment_method_examples.rb +454 -0
- data/spec/shared_stripe_examples/payout_examples.rb +2 -2
- data/spec/shared_stripe_examples/plan_examples.rb +135 -92
- data/spec/shared_stripe_examples/price_examples.rb +292 -0
- data/spec/shared_stripe_examples/product_examples.rb +215 -0
- data/spec/shared_stripe_examples/promotion_code_examples.rb +68 -0
- data/spec/shared_stripe_examples/refund_examples.rb +38 -21
- data/spec/shared_stripe_examples/setup_intent_examples.rb +85 -0
- data/spec/shared_stripe_examples/subscription_examples.rb +706 -324
- data/spec/shared_stripe_examples/subscription_items_examples.rb +3 -2
- data/spec/shared_stripe_examples/transfer_examples.rb +16 -7
- data/spec/shared_stripe_examples/webhook_event_examples.rb +62 -16
- data/spec/spec_helper.rb +8 -5
- data/spec/stripe_mock_spec.rb +4 -4
- data/spec/support/shared_contexts/stripe_validator_spec.rb +8 -0
- data/spec/support/stripe_examples.rb +11 -1
- data/stripe-ruby-mock.gemspec +9 -5
- metadata +115 -47
- data/.travis.yml +0 -28
- data/spec/shared_stripe_examples/product_example.rb +0 -65
@@ -2,8 +2,9 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
shared_examples 'Subscription Items API' do
|
4
4
|
let(:stripe_helper) { StripeMock.create_test_helper }
|
5
|
-
let(:
|
6
|
-
let(:
|
5
|
+
let(:product) { stripe_helper.create_product(name: 'Silver Product') }
|
6
|
+
let(:plan) { stripe_helper.create_plan(product: product.id, id: 'silver_plan') }
|
7
|
+
let(:plan2) { stripe_helper.create_plan(amount: 100, id: 'one_more_1_plan', product: product.id) }
|
7
8
|
let(:customer) { Stripe::Customer.create(source: stripe_helper.generate_card_token) }
|
8
9
|
let(:subscription) { Stripe::Subscription.create(customer: customer.id, items: [{ plan: plan.id }]) }
|
9
10
|
|
@@ -9,7 +9,7 @@ shared_examples 'Transfer API' do
|
|
9
9
|
expect(transfer.id).to match /^test_tr/
|
10
10
|
expect(transfer.amount).to eq(100)
|
11
11
|
expect(transfer.amount_reversed).to eq(0)
|
12
|
-
expect(transfer.balance_transaction).to eq('
|
12
|
+
expect(transfer.balance_transaction).to eq('test_txn_1')
|
13
13
|
expect(transfer.created).to eq(1304114826)
|
14
14
|
expect(transfer.currency).to eq('usd')
|
15
15
|
expect(transfer.description).to eq('Transfer description')
|
@@ -30,6 +30,15 @@ shared_examples 'Transfer API' do
|
|
30
30
|
expect(transfer.transfer_group).to eq("group_ch_164xRv2eZvKYlo2Clu1sIJWB")
|
31
31
|
end
|
32
32
|
|
33
|
+
it "creates a balance transaction" do
|
34
|
+
destination = Stripe::Account.create(type: "custom", email: "#{SecureRandom.uuid}@example.com", id: "acct_12345", requested_capabilities: ['card_payments', 'platform_payments'])
|
35
|
+
transfer = Stripe::Transfer.create(amount: 100, currency: "usd", destination: destination.id)
|
36
|
+
|
37
|
+
bal_trans = Stripe::BalanceTransaction.retrieve(transfer.balance_transaction)
|
38
|
+
expect(bal_trans.amount).to eq(100)
|
39
|
+
expect(bal_trans.source).to eq(transfer.id)
|
40
|
+
end
|
41
|
+
|
33
42
|
describe "listing transfers" do
|
34
43
|
let(:destination) { Stripe::Account.create(type: "custom", email: "#{SecureRandom.uuid}@example.com", business_name: "MyCo") }
|
35
44
|
|
@@ -40,22 +49,22 @@ shared_examples 'Transfer API' do
|
|
40
49
|
end
|
41
50
|
|
42
51
|
it "without params retrieves all tripe transfers" do
|
43
|
-
expect(Stripe::Transfer.
|
52
|
+
expect(Stripe::Transfer.list.count).to eq(3)
|
44
53
|
end
|
45
54
|
|
46
55
|
it "accepts a limit param" do
|
47
|
-
expect(Stripe::Transfer.
|
56
|
+
expect(Stripe::Transfer.list(limit: 2).count).to eq(2)
|
48
57
|
end
|
49
58
|
|
50
59
|
it "filters the search to a specific destination" do
|
51
60
|
d2 = Stripe::Account.create(type: "custom", email: "#{SecureRandom.uuid}@example.com", business_name: "MyCo")
|
52
61
|
Stripe::Transfer.create(amount: "100", currency: "usd", destination: d2.id)
|
53
62
|
|
54
|
-
expect(Stripe::Transfer.
|
63
|
+
expect(Stripe::Transfer.list(destination: d2.id).count).to eq(1)
|
55
64
|
end
|
56
65
|
|
57
66
|
it "disallows unknown parameters" do
|
58
|
-
expect { Stripe::Transfer.
|
67
|
+
expect { Stripe::Transfer.list(recipient: "foo") }.to raise_error {|e|
|
59
68
|
expect(e).to be_a Stripe::InvalidRequestError
|
60
69
|
expect(e.param).to eq("recipient")
|
61
70
|
expect(e.message).to eq("Received unknown parameter: recipient")
|
@@ -104,7 +113,7 @@ shared_examples 'Transfer API' do
|
|
104
113
|
end
|
105
114
|
|
106
115
|
it "when amount is not integer", live: true do
|
107
|
-
dest = Stripe::Account.create(type: "custom", email: "#{SecureRandom.uuid}@example.com",
|
116
|
+
dest = Stripe::Account.create(type: "custom", email: "#{SecureRandom.uuid}@example.com", requested_capabilities: ['card_payments', 'platform_payments'])
|
108
117
|
expect { Stripe::Transfer.create(amount: '400.2',
|
109
118
|
currency: 'usd',
|
110
119
|
destination: dest.id,
|
@@ -116,7 +125,7 @@ shared_examples 'Transfer API' do
|
|
116
125
|
end
|
117
126
|
|
118
127
|
it "when amount is negative", live: true do
|
119
|
-
dest = Stripe::Account.create(type: "custom", email: "#{SecureRandom.uuid}@example.com",
|
128
|
+
dest = Stripe::Account.create(type: "custom", email: "#{SecureRandom.uuid}@example.com", requested_capabilities: ['card_payments', 'platform_payments'])
|
120
129
|
expect { Stripe::Transfer.create(amount: '-400',
|
121
130
|
currency: 'usd',
|
122
131
|
destination: dest.id,
|
@@ -168,7 +168,7 @@ shared_examples 'Webhook Events API' do
|
|
168
168
|
expect(invoice_item_created_event).to be_a(Stripe::Event)
|
169
169
|
expect(invoice_item_created_event).to_not be_nil
|
170
170
|
|
171
|
-
events = Stripe::Event.
|
171
|
+
events = Stripe::Event.list
|
172
172
|
|
173
173
|
expect(events.count).to eq(5)
|
174
174
|
expect(events.map &:id).to include(customer_created_event.id, plan_created_event.id, coupon_created_event.id, invoice_created_event.id, invoice_item_created_event.id)
|
@@ -196,47 +196,93 @@ shared_examples 'Webhook Events API' do
|
|
196
196
|
expect(invoice_item_created_event).to be_a(Stripe::Event)
|
197
197
|
expect(invoice_item_created_event).to_not be_nil
|
198
198
|
|
199
|
-
events = Stripe::Event.
|
199
|
+
events = Stripe::Event.list(limit: 3)
|
200
200
|
|
201
201
|
expect(events.count).to eq(3)
|
202
202
|
expect(events.map &:id).to include(invoice_item_created_event.id, invoice_created_event.id, coupon_created_event.id)
|
203
203
|
expect(events.map &:type).to include('invoiceitem.created', 'invoice.created', 'coupon.created')
|
204
204
|
end
|
205
205
|
|
206
|
+
it "retrieves events with a created timestamp" do
|
207
|
+
timestamp = Time.now.to_i - 7200
|
208
|
+
customer_created_event = StripeMock.mock_webhook_event('customer.created', created: Time.now.to_i - 14_400)
|
209
|
+
plan_created_event = StripeMock.mock_webhook_event('plan.created', created: Time.now.to_i - 10_800)
|
210
|
+
coupon_created_event = StripeMock.mock_webhook_event('coupon.created', created: timestamp)
|
211
|
+
invoice_created_event = StripeMock.mock_webhook_event('invoice.created', created: Time.now.to_i - 3600)
|
212
|
+
invoice_item_created_event = StripeMock.mock_webhook_event('invoiceitem.created')
|
213
|
+
|
214
|
+
events = Stripe::Event.list(created: timestamp)
|
215
|
+
expect(events.count).to eq(1)
|
216
|
+
expect(events.map &:id).to match_array([coupon_created_event.id])
|
217
|
+
expect(events.map &:type).to match_array(['coupon.created'])
|
218
|
+
|
219
|
+
events = Stripe::Event.list(created: timestamp.to_s)
|
220
|
+
expect(events.count).to eq(1)
|
221
|
+
expect(events.map &:id).to match_array([coupon_created_event.id])
|
222
|
+
expect(events.map &:type).to match_array(['coupon.created'])
|
223
|
+
end
|
224
|
+
|
225
|
+
it "retrieves events with a created filter" do
|
226
|
+
timestamp1 = Time.now.to_i - 3600
|
227
|
+
timestamp2 = Time.now.to_i - 7200
|
228
|
+
timestamp3 = Time.now.to_i - 10_800
|
229
|
+
timestamp4 = Time.now.to_i - 14_400
|
230
|
+
customer_created_event = StripeMock.mock_webhook_event('customer.created', created: timestamp4)
|
231
|
+
plan_created_event = StripeMock.mock_webhook_event('plan.created', created: timestamp3)
|
232
|
+
coupon_created_event = StripeMock.mock_webhook_event('coupon.created', created: timestamp2)
|
233
|
+
invoice_created_event = StripeMock.mock_webhook_event('invoice.created', created: timestamp1)
|
234
|
+
invoice_item_created_event = StripeMock.mock_webhook_event('invoiceitem.created')
|
235
|
+
|
236
|
+
events = Stripe::Event.list(created: {gte: timestamp2, lte: timestamp1})
|
237
|
+
expect(events.count).to eq(2)
|
238
|
+
expect(events.map &:id).to match_array([coupon_created_event.id, invoice_created_event.id])
|
239
|
+
expect(events.map &:type).to match_array(['coupon.created', 'invoice.created'])
|
240
|
+
|
241
|
+
events = Stripe::Event.list(created: {gt: timestamp3})
|
242
|
+
expect(events.count).to eq(3)
|
243
|
+
expect(events.map &:id).to match_array([coupon_created_event.id, invoice_created_event.id, invoice_item_created_event.id])
|
244
|
+
expect(events.map &:type).to match_array(['coupon.created', 'invoice.created', 'invoiceitem.created'])
|
245
|
+
|
246
|
+
events = Stripe::Event.list(created: {lt: timestamp3.to_s})
|
247
|
+
expect(events.count).to eq(1)
|
248
|
+
expect(events.map &:id).to match_array([customer_created_event.id])
|
249
|
+
expect(events.map &:type).to match_array(['customer.created'])
|
250
|
+
end
|
251
|
+
|
206
252
|
end
|
207
|
-
|
208
|
-
describe 'Subscription events' do
|
209
|
-
it "Checks for billing items in customer.subscription.created" do
|
253
|
+
|
254
|
+
describe 'Subscription events' do
|
255
|
+
it "Checks for billing items in customer.subscription.created" do
|
210
256
|
subscription_created_event = StripeMock.mock_webhook_event('customer.subscription.created')
|
211
257
|
expect(subscription_created_event).to be_a(Stripe::Event)
|
212
258
|
expect(subscription_created_event.id).to_not be_nil
|
213
259
|
expect(subscription_created_event.data.object.items.data.class).to be Array
|
214
|
-
expect(subscription_created_event.data.object.items.data.length).to be
|
260
|
+
expect(subscription_created_event.data.object.items.data.length).to be 1
|
215
261
|
expect(subscription_created_event.data.object.items.data.first).to respond_to(:plan)
|
216
262
|
expect(subscription_created_event.data.object.items.data.first.id).to eq('si_00000000000000')
|
217
263
|
end
|
218
264
|
|
219
|
-
it "Checks for billing items in customer.subscription.deleted" do
|
265
|
+
it "Checks for billing items in customer.subscription.deleted" do
|
220
266
|
subscription_deleted_event = StripeMock.mock_webhook_event('customer.subscription.deleted')
|
221
267
|
expect(subscription_deleted_event).to be_a(Stripe::Event)
|
222
268
|
expect(subscription_deleted_event.id).to_not be_nil
|
223
269
|
expect(subscription_deleted_event.data.object.items.data.class).to be Array
|
224
|
-
expect(subscription_deleted_event.data.object.items.data.length).to be
|
270
|
+
expect(subscription_deleted_event.data.object.items.data.length).to be 1
|
225
271
|
expect(subscription_deleted_event.data.object.items.data.first).to respond_to(:plan)
|
226
272
|
expect(subscription_deleted_event.data.object.items.data.first.id).to eq('si_00000000000000')
|
227
273
|
end
|
228
|
-
|
229
|
-
it "Checks for billing items in customer.subscription.updated" do
|
274
|
+
|
275
|
+
it "Checks for billing items in customer.subscription.updated" do
|
230
276
|
subscription_updated_event = StripeMock.mock_webhook_event('customer.subscription.updated')
|
231
277
|
expect(subscription_updated_event).to be_a(Stripe::Event)
|
232
278
|
expect(subscription_updated_event.id).to_not be_nil
|
233
279
|
expect(subscription_updated_event.data.object.items.data.class).to be Array
|
234
|
-
expect(subscription_updated_event.data.object.items.data.length).to be
|
280
|
+
expect(subscription_updated_event.data.object.items.data.length).to be 1
|
235
281
|
expect(subscription_updated_event.data.object.items.data.first).to respond_to(:plan)
|
236
282
|
expect(subscription_updated_event.data.object.items.data.first.id).to eq('si_00000000000000')
|
237
283
|
end
|
238
|
-
|
239
|
-
it "Checks for billing items in customer.subscription.trial_will_end" do
|
284
|
+
|
285
|
+
it "Checks for billing items in customer.subscription.trial_will_end" do
|
240
286
|
subscription_trial_will_end_event = StripeMock.mock_webhook_event('customer.subscription.trial_will_end')
|
241
287
|
expect(subscription_trial_will_end_event).to be_a(Stripe::Event)
|
242
288
|
expect(subscription_trial_will_end_event.id).to_not be_nil
|
@@ -247,15 +293,15 @@ shared_examples 'Webhook Events API' do
|
|
247
293
|
end
|
248
294
|
end
|
249
295
|
|
250
|
-
describe 'Invoices events' do
|
296
|
+
describe 'Invoices events' do
|
251
297
|
it "Checks for billing items in invoice.payment_succeeded" do
|
252
298
|
invoice_payment_succeeded = StripeMock.mock_webhook_event('invoice.payment_succeeded')
|
253
299
|
expect(invoice_payment_succeeded).to be_a(Stripe::Event)
|
254
300
|
expect(invoice_payment_succeeded.id).to_not be_nil
|
255
301
|
expect(invoice_payment_succeeded.data.object.lines.data.class).to be Array
|
256
|
-
expect(invoice_payment_succeeded.data.object.lines.data.length).to be
|
302
|
+
expect(invoice_payment_succeeded.data.object.lines.data.length).to be 1
|
257
303
|
expect(invoice_payment_succeeded.data.object.lines.data.first).to respond_to(:plan)
|
258
|
-
expect(invoice_payment_succeeded.data.object.lines.data.first.id).to eq('
|
304
|
+
expect(invoice_payment_succeeded.data.object.lines.data.first.id).to eq('il_000000000000000000000000')
|
259
305
|
end
|
260
306
|
end
|
261
307
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,10 +1,13 @@
|
|
1
1
|
require 'set'
|
2
2
|
|
3
|
-
gem 'rspec', '~> 3.
|
3
|
+
gem 'rspec', '~> 3.13'
|
4
4
|
require 'rspec'
|
5
5
|
require 'stripe'
|
6
6
|
require 'stripe_mock'
|
7
7
|
require 'stripe_mock/server'
|
8
|
+
require 'dotenv'
|
9
|
+
|
10
|
+
Dotenv.load('.env')
|
8
11
|
|
9
12
|
# Requires supporting ruby files with custom matchers and macros, etc,
|
10
13
|
# in spec/support/ and its subdirectories.
|
@@ -30,10 +33,10 @@ RSpec.configure do |c|
|
|
30
33
|
if ENV['IS_TRAVIS']
|
31
34
|
puts "Travis ruby version: #{RUBY_VERSION}"
|
32
35
|
api_key = case RUBY_VERSION
|
33
|
-
when '2.
|
34
|
-
when '2.
|
35
|
-
when '2.
|
36
|
-
when '2.
|
36
|
+
when '2.4.6' then ENV['STRIPE_TEST_SECRET_KEY_A']
|
37
|
+
when '2.5.5' then ENV['STRIPE_TEST_SECRET_KEY_B']
|
38
|
+
when '2.6.3' then ENV['STRIPE_TEST_SECRET_KEY_C']
|
39
|
+
when '2.7.0' then ENV['STRIPE_TEST_SECRET_KEY_D']
|
37
40
|
end
|
38
41
|
else
|
39
42
|
api_key = ENV['STRIPE_TEST_SECRET_KEY']
|
data/spec/stripe_mock_spec.rb
CHANGED
@@ -18,14 +18,14 @@ describe StripeMock do
|
|
18
18
|
StripeMock.start
|
19
19
|
Stripe::StripeClient.active_client.execute_request(:xtest, '/', api_key: 'abcde') # no error
|
20
20
|
StripeMock.stop
|
21
|
-
expect { Stripe::StripeClient.active_client.execute_request(:x, '/', api_key: 'abcde') }.to raise_error
|
21
|
+
expect { Stripe::StripeClient.active_client.execute_request(:x, '/', api_key: 'abcde') }.to raise_error Stripe::APIError
|
22
22
|
end
|
23
23
|
|
24
24
|
it "reverts overriding stripe's execute_request method in other threads" do
|
25
25
|
StripeMock.start
|
26
26
|
Thread.new { Stripe::StripeClient.active_client.execute_request(:xtest, '/', api_key: 'abcde') }.join # no error
|
27
27
|
StripeMock.stop
|
28
|
-
expect { Thread.new { Stripe::StripeClient.active_client.execute_request(:x, '/', api_key: 'abcde') }.join }.to raise_error
|
28
|
+
expect { Thread.new { Stripe::StripeClient.active_client.execute_request(:x, '/', api_key: 'abcde') }.join }.to raise_error Stripe::APIError
|
29
29
|
end
|
30
30
|
|
31
31
|
it "does not persist data between mock sessions" do
|
@@ -35,8 +35,8 @@ describe StripeMock do
|
|
35
35
|
StripeMock.stop
|
36
36
|
StripeMock.start
|
37
37
|
|
38
|
-
expect(StripeMock.instance.customers[:x]).to be_nil
|
39
|
-
expect(StripeMock.instance.customers.keys.length).to eq(0)
|
38
|
+
expect(StripeMock.instance.customers[''][:x]).to be_nil
|
39
|
+
expect(StripeMock.instance.customers[''].keys.length).to eq(0)
|
40
40
|
StripeMock.stop
|
41
41
|
end
|
42
42
|
|
@@ -5,6 +5,7 @@ end
|
|
5
5
|
|
6
6
|
def it_behaves_like_stripe(&block)
|
7
7
|
it_behaves_like 'Account API', &block
|
8
|
+
it_behaves_like 'Account Link API', &block
|
8
9
|
it_behaves_like 'Balance API', &block
|
9
10
|
it_behaves_like 'Balance Transaction API', &block
|
10
11
|
it_behaves_like 'Bank Account Token Mocking', &block
|
@@ -12,6 +13,7 @@ def it_behaves_like_stripe(&block)
|
|
12
13
|
it_behaves_like 'Card API', &block
|
13
14
|
it_behaves_like 'Charge API', &block
|
14
15
|
it_behaves_like 'Bank API', &block
|
16
|
+
it_behaves_like 'Express Login Link API', &block
|
15
17
|
it_behaves_like 'External Account API', &block
|
16
18
|
it_behaves_like 'Coupon API', &block
|
17
19
|
it_behaves_like 'Customer API', &block
|
@@ -20,21 +22,29 @@ def it_behaves_like_stripe(&block)
|
|
20
22
|
it_behaves_like 'Invoice API', &block
|
21
23
|
it_behaves_like 'Invoice Item API', &block
|
22
24
|
it_behaves_like 'Plan API', &block
|
25
|
+
it_behaves_like 'Price API', &block
|
23
26
|
it_behaves_like 'Product API', &block
|
27
|
+
it_behaves_like 'PromotionCode API', &block
|
24
28
|
it_behaves_like 'Recipient API', &block
|
25
29
|
it_behaves_like 'Refund API', &block
|
26
30
|
it_behaves_like 'Transfer API', &block
|
27
31
|
it_behaves_like 'Payout API', &block
|
32
|
+
it_behaves_like 'PaymentIntent API', &block
|
33
|
+
it_behaves_like 'PaymentMethod API', &block
|
34
|
+
it_behaves_like 'SetupIntent API', &block
|
28
35
|
it_behaves_like 'Stripe Error Mocking', &block
|
29
|
-
it_behaves_like 'Customer Subscriptions', &block
|
36
|
+
it_behaves_like 'Customer Subscriptions with plans', &block
|
37
|
+
it_behaves_like 'Customer Subscriptions with prices', &block
|
30
38
|
it_behaves_like 'Subscription Items API', &block
|
31
39
|
it_behaves_like 'Webhook Events API', &block
|
32
40
|
it_behaves_like 'Country Spec API', &block
|
33
41
|
it_behaves_like 'EphemeralKey API', &block
|
34
42
|
it_behaves_like 'TaxRate API', &block
|
43
|
+
it_behaves_like 'Checkout Session API', &block
|
35
44
|
|
36
45
|
# Integration tests
|
37
46
|
it_behaves_like 'Multiple Customer Cards'
|
38
47
|
it_behaves_like 'Charging with Tokens'
|
39
48
|
it_behaves_like 'Card Error Prep'
|
49
|
+
it_behaves_like 'Completing Checkout Sessions'
|
40
50
|
end
|
data/stripe-ruby-mock.gemspec
CHANGED
@@ -10,18 +10,22 @@ Gem::Specification.new do |gem|
|
|
10
10
|
gem.license = "MIT"
|
11
11
|
gem.authors = ["Gilbert"]
|
12
12
|
gem.email = "gilbertbgarza@gmail.com"
|
13
|
-
gem.homepage = "https://github.com/
|
13
|
+
gem.homepage = "https://github.com/stripe-ruby-mock/stripe-ruby-mock"
|
14
|
+
gem.metadata = {
|
15
|
+
"bug_tracker_uri" => "https://github.com/stripe-ruby-mock/stripe-ruby-mock/issues",
|
16
|
+
"changelog_uri" => "https://github.com/stripe-ruby-mock/stripe-ruby-mock/blob/master/CHANGELOG.md",
|
17
|
+
"source_code_uri" => "https://github.com/stripe-ruby-mock/stripe-ruby-mock"
|
18
|
+
}
|
14
19
|
|
15
20
|
gem.files = `git ls-files`.split($/)
|
16
21
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
22
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
23
|
gem.require_paths = ['lib']
|
19
24
|
|
20
|
-
gem.add_dependency 'stripe', '
|
25
|
+
gem.add_dependency 'stripe', '> 5', '< 12'
|
21
26
|
gem.add_dependency 'multi_json', '~> 1.0'
|
22
27
|
gem.add_dependency 'dante', '>= 0.2.0'
|
23
28
|
|
24
|
-
gem.add_development_dependency 'rspec', '~> 3.
|
25
|
-
gem.add_development_dependency '
|
26
|
-
gem.add_development_dependency 'thin', '~> 1.6.4'
|
29
|
+
gem.add_development_dependency 'rspec', '~> 3.13.0'
|
30
|
+
gem.add_development_dependency 'thin', '~> 1.8.1'
|
27
31
|
end
|