epopia-stripe-ruby-mock 2.5.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (171) hide show
  1. checksums.yaml +7 -0
  2. data/.env +2 -0
  3. data/.gitignore +8 -0
  4. data/.rspec +1 -0
  5. data/.travis.yml +28 -0
  6. data/Gemfile +12 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +413 -0
  9. data/Rakefile +14 -0
  10. data/bin/stripe-mock-server +19 -0
  11. data/lib/stripe_mock.rb +95 -0
  12. data/lib/stripe_mock/api/account_balance.rb +14 -0
  13. data/lib/stripe_mock/api/bank_tokens.rb +13 -0
  14. data/lib/stripe_mock/api/card_tokens.rb +13 -0
  15. data/lib/stripe_mock/api/client.rb +41 -0
  16. data/lib/stripe_mock/api/conversion_rate.rb +14 -0
  17. data/lib/stripe_mock/api/debug.rb +11 -0
  18. data/lib/stripe_mock/api/errors.rb +65 -0
  19. data/lib/stripe_mock/api/global_id_prefix.rb +22 -0
  20. data/lib/stripe_mock/api/instance.rb +38 -0
  21. data/lib/stripe_mock/api/live.rb +15 -0
  22. data/lib/stripe_mock/api/server.rb +39 -0
  23. data/lib/stripe_mock/api/test_helpers.rb +24 -0
  24. data/lib/stripe_mock/api/webhooks.rb +88 -0
  25. data/lib/stripe_mock/client.rb +127 -0
  26. data/lib/stripe_mock/data.rb +1193 -0
  27. data/lib/stripe_mock/data/list.rb +73 -0
  28. data/lib/stripe_mock/error_queue.rb +27 -0
  29. data/lib/stripe_mock/errors/closed_client_connection_error.rb +9 -0
  30. data/lib/stripe_mock/errors/server_timeout_error.rb +12 -0
  31. data/lib/stripe_mock/errors/stripe_mock_error.rb +15 -0
  32. data/lib/stripe_mock/errors/uninitialized_instance_error.rb +9 -0
  33. data/lib/stripe_mock/errors/unstarted_state_error.rb +9 -0
  34. data/lib/stripe_mock/errors/unsupported_request_error.rb +4 -0
  35. data/lib/stripe_mock/instance.rb +237 -0
  36. data/lib/stripe_mock/request_handlers/accounts.rb +86 -0
  37. data/lib/stripe_mock/request_handlers/balance.rb +17 -0
  38. data/lib/stripe_mock/request_handlers/balance_transactions.rb +37 -0
  39. data/lib/stripe_mock/request_handlers/cards.rb +35 -0
  40. data/lib/stripe_mock/request_handlers/charges.rb +177 -0
  41. data/lib/stripe_mock/request_handlers/country_spec.rb +22 -0
  42. data/lib/stripe_mock/request_handlers/coupons.rb +35 -0
  43. data/lib/stripe_mock/request_handlers/customers.rb +137 -0
  44. data/lib/stripe_mock/request_handlers/disputes.rb +35 -0
  45. data/lib/stripe_mock/request_handlers/ephemeral_key.rb +13 -0
  46. data/lib/stripe_mock/request_handlers/events.rb +21 -0
  47. data/lib/stripe_mock/request_handlers/external_accounts.rb +55 -0
  48. data/lib/stripe_mock/request_handlers/helpers/bank_account_helpers.rb +14 -0
  49. data/lib/stripe_mock/request_handlers/helpers/card_helpers.rb +127 -0
  50. data/lib/stripe_mock/request_handlers/helpers/charge_helpers.rb +16 -0
  51. data/lib/stripe_mock/request_handlers/helpers/coupon_helpers.rb +17 -0
  52. data/lib/stripe_mock/request_handlers/helpers/external_account_helpers.rb +49 -0
  53. data/lib/stripe_mock/request_handlers/helpers/subscription_helpers.rb +119 -0
  54. data/lib/stripe_mock/request_handlers/helpers/token_helpers.rb +44 -0
  55. data/lib/stripe_mock/request_handlers/invoice_items.rb +45 -0
  56. data/lib/stripe_mock/request_handlers/invoices.rb +177 -0
  57. data/lib/stripe_mock/request_handlers/orders.rb +80 -0
  58. data/lib/stripe_mock/request_handlers/payment_intents.rb +203 -0
  59. data/lib/stripe_mock/request_handlers/payment_methods.rb +112 -0
  60. data/lib/stripe_mock/request_handlers/payouts.rb +32 -0
  61. data/lib/stripe_mock/request_handlers/plans.rb +42 -0
  62. data/lib/stripe_mock/request_handlers/products.rb +43 -0
  63. data/lib/stripe_mock/request_handlers/recipients.rb +60 -0
  64. data/lib/stripe_mock/request_handlers/refunds.rb +91 -0
  65. data/lib/stripe_mock/request_handlers/sources.rb +55 -0
  66. data/lib/stripe_mock/request_handlers/subscription_items.rb +36 -0
  67. data/lib/stripe_mock/request_handlers/subscriptions.rb +296 -0
  68. data/lib/stripe_mock/request_handlers/tax_rates.rb +36 -0
  69. data/lib/stripe_mock/request_handlers/tokens.rb +75 -0
  70. data/lib/stripe_mock/request_handlers/transfers.rb +65 -0
  71. data/lib/stripe_mock/request_handlers/validators/param_validators.rb +32 -0
  72. data/lib/stripe_mock/server.rb +93 -0
  73. data/lib/stripe_mock/test_strategies/base.rb +81 -0
  74. data/lib/stripe_mock/test_strategies/live.rb +40 -0
  75. data/lib/stripe_mock/test_strategies/mock.rb +27 -0
  76. data/lib/stripe_mock/util.rb +44 -0
  77. data/lib/stripe_mock/version.rb +4 -0
  78. data/lib/stripe_mock/webhook_fixtures/account.application.deauthorized.json +12 -0
  79. data/lib/stripe_mock/webhook_fixtures/account.external_account.created.json +27 -0
  80. data/lib/stripe_mock/webhook_fixtures/account.external_account.deleted.json +27 -0
  81. data/lib/stripe_mock/webhook_fixtures/account.external_account.updated.json +27 -0
  82. data/lib/stripe_mock/webhook_fixtures/account.updated.json +26 -0
  83. data/lib/stripe_mock/webhook_fixtures/balance.available.json +25 -0
  84. data/lib/stripe_mock/webhook_fixtures/charge.dispute.closed.json +22 -0
  85. data/lib/stripe_mock/webhook_fixtures/charge.dispute.created.json +22 -0
  86. data/lib/stripe_mock/webhook_fixtures/charge.dispute.funds_reinstated.json +88 -0
  87. data/lib/stripe_mock/webhook_fixtures/charge.dispute.funds_withdrawn.json +88 -0
  88. data/lib/stripe_mock/webhook_fixtures/charge.dispute.updated.json +25 -0
  89. data/lib/stripe_mock/webhook_fixtures/charge.failed.json +56 -0
  90. data/lib/stripe_mock/webhook_fixtures/charge.refunded.json +69 -0
  91. data/lib/stripe_mock/webhook_fixtures/charge.succeeded.json +55 -0
  92. data/lib/stripe_mock/webhook_fixtures/charge.updated.json +58 -0
  93. data/lib/stripe_mock/webhook_fixtures/coupon.created.json +23 -0
  94. data/lib/stripe_mock/webhook_fixtures/coupon.deleted.json +23 -0
  95. data/lib/stripe_mock/webhook_fixtures/customer.created.json +54 -0
  96. data/lib/stripe_mock/webhook_fixtures/customer.deleted.json +42 -0
  97. data/lib/stripe_mock/webhook_fixtures/customer.discount.created.json +28 -0
  98. data/lib/stripe_mock/webhook_fixtures/customer.discount.deleted.json +28 -0
  99. data/lib/stripe_mock/webhook_fixtures/customer.discount.updated.json +43 -0
  100. data/lib/stripe_mock/webhook_fixtures/customer.source.created.json +32 -0
  101. data/lib/stripe_mock/webhook_fixtures/customer.source.deleted.json +32 -0
  102. data/lib/stripe_mock/webhook_fixtures/customer.source.updated.json +36 -0
  103. data/lib/stripe_mock/webhook_fixtures/customer.subscription.created.json +66 -0
  104. data/lib/stripe_mock/webhook_fixtures/customer.subscription.deleted.json +65 -0
  105. data/lib/stripe_mock/webhook_fixtures/customer.subscription.trial_will_end.json +65 -0
  106. data/lib/stripe_mock/webhook_fixtures/customer.subscription.updated.json +78 -0
  107. data/lib/stripe_mock/webhook_fixtures/customer.updated.json +57 -0
  108. data/lib/stripe_mock/webhook_fixtures/invoice.created.json +71 -0
  109. data/lib/stripe_mock/webhook_fixtures/invoice.payment_failed.json +105 -0
  110. data/lib/stripe_mock/webhook_fixtures/invoice.payment_succeeded.json +112 -0
  111. data/lib/stripe_mock/webhook_fixtures/invoice.updated.json +74 -0
  112. data/lib/stripe_mock/webhook_fixtures/invoiceitem.created.json +21 -0
  113. data/lib/stripe_mock/webhook_fixtures/invoiceitem.deleted.json +21 -0
  114. data/lib/stripe_mock/webhook_fixtures/invoiceitem.updated.json +24 -0
  115. data/lib/stripe_mock/webhook_fixtures/plan.created.json +20 -0
  116. data/lib/stripe_mock/webhook_fixtures/plan.deleted.json +20 -0
  117. data/lib/stripe_mock/webhook_fixtures/plan.updated.json +23 -0
  118. data/lib/stripe_mock/webhook_fixtures/transfer.created.json +89 -0
  119. data/lib/stripe_mock/webhook_fixtures/transfer.failed.json +89 -0
  120. data/lib/stripe_mock/webhook_fixtures/transfer.paid.json +89 -0
  121. data/lib/stripe_mock/webhook_fixtures/transfer.updated.json +92 -0
  122. data/lib/trollop.rb +782 -0
  123. data/spec/_dummy/webhooks/dummy.event.json +6 -0
  124. data/spec/api/instance_spec.rb +30 -0
  125. data/spec/fixtures/create_refund.yml +126 -0
  126. data/spec/fixtures/stripe_webhooks/account.updated.json +7 -0
  127. data/spec/fixtures/stripe_webhooks/custom.account.updated.json +5 -0
  128. data/spec/instance_spec.rb +100 -0
  129. data/spec/integration_examples/charge_token_examples.rb +51 -0
  130. data/spec/integration_examples/customer_card_examples.rb +42 -0
  131. data/spec/integration_examples/prepare_error_examples.rb +38 -0
  132. data/spec/list_spec.rb +140 -0
  133. data/spec/readme_spec.rb +75 -0
  134. data/spec/server_spec.rb +139 -0
  135. data/spec/shared_stripe_examples/account_examples.rb +96 -0
  136. data/spec/shared_stripe_examples/balance_examples.rb +11 -0
  137. data/spec/shared_stripe_examples/balance_transaction_examples.rb +63 -0
  138. data/spec/shared_stripe_examples/bank_examples.rb +229 -0
  139. data/spec/shared_stripe_examples/bank_token_examples.rb +59 -0
  140. data/spec/shared_stripe_examples/card_examples.rb +307 -0
  141. data/spec/shared_stripe_examples/card_token_examples.rb +185 -0
  142. data/spec/shared_stripe_examples/charge_examples.rb +510 -0
  143. data/spec/shared_stripe_examples/country_specs_examples.rb +18 -0
  144. data/spec/shared_stripe_examples/coupon_examples.rb +85 -0
  145. data/spec/shared_stripe_examples/customer_examples.rb +453 -0
  146. data/spec/shared_stripe_examples/dispute_examples.rb +98 -0
  147. data/spec/shared_stripe_examples/ephemeral_key_examples.rb +17 -0
  148. data/spec/shared_stripe_examples/error_mock_examples.rb +162 -0
  149. data/spec/shared_stripe_examples/external_account_examples.rb +170 -0
  150. data/spec/shared_stripe_examples/extra_features_examples.rb +36 -0
  151. data/spec/shared_stripe_examples/invoice_examples.rb +524 -0
  152. data/spec/shared_stripe_examples/invoice_item_examples.rb +69 -0
  153. data/spec/shared_stripe_examples/payment_intent_examples.rb +131 -0
  154. data/spec/shared_stripe_examples/payment_method_examples.rb +175 -0
  155. data/spec/shared_stripe_examples/payout_examples.rb +68 -0
  156. data/spec/shared_stripe_examples/plan_examples.rb +194 -0
  157. data/spec/shared_stripe_examples/product_example.rb +65 -0
  158. data/spec/shared_stripe_examples/recipient_examples.rb +118 -0
  159. data/spec/shared_stripe_examples/refund_examples.rb +472 -0
  160. data/spec/shared_stripe_examples/subscription_examples.rb +1148 -0
  161. data/spec/shared_stripe_examples/subscription_items_examples.rb +75 -0
  162. data/spec/shared_stripe_examples/tax_rate_examples.rb +42 -0
  163. data/spec/shared_stripe_examples/transfer_examples.rb +130 -0
  164. data/spec/shared_stripe_examples/validation_examples.rb +19 -0
  165. data/spec/shared_stripe_examples/webhook_event_examples.rb +261 -0
  166. data/spec/spec_helper.rb +58 -0
  167. data/spec/stripe_mock_spec.rb +123 -0
  168. data/spec/support/stripe_examples.rb +42 -0
  169. data/spec/util_spec.rb +121 -0
  170. data/stripe-ruby-mock.gemspec +27 -0
  171. metadata +344 -0
@@ -0,0 +1,58 @@
1
+ require 'set'
2
+
3
+ gem 'rspec', '~> 3.1'
4
+ require 'rspec'
5
+ require 'stripe'
6
+ require 'stripe_mock'
7
+ require 'stripe_mock/server'
8
+
9
+ # Requires supporting ruby files with custom matchers and macros, etc,
10
+ # in spec/support/ and its subdirectories.
11
+ Dir["./spec/support/**/*.rb"].each {|f| require f}
12
+
13
+ RSpec.configure do |c|
14
+ tags = c.filter_manager.inclusions.rules
15
+
16
+ if tags.include?(:live) || tags.include?(:oauth)
17
+ puts "Running **live** tests against Stripe..."
18
+ StripeMock.set_default_test_helper_strategy(:live)
19
+
20
+ if tags.include?(:oauth)
21
+ oauth_token = ENV['STRIPE_TEST_OAUTH_ACCESS_TOKEN']
22
+ if oauth_token.nil? || oauth_token == ''
23
+ raise "Please set your STRIPE_TEST_OAUTH_ACCESS_TOKEN environment variable."
24
+ end
25
+ c.filter_run_excluding :mock_server => true, :live => true
26
+ else
27
+ c.filter_run_excluding :mock_server => true, :oauth => true
28
+ end
29
+
30
+ if ENV['IS_TRAVIS']
31
+ puts "Travis ruby version: #{RUBY_VERSION}"
32
+ api_key = case RUBY_VERSION
33
+ when '2.0.0' then ENV['STRIPE_TEST_SECRET_KEY_A']
34
+ when '2.1.10' then ENV['STRIPE_TEST_SECRET_KEY_B']
35
+ when '2.2.7' then ENV['STRIPE_TEST_SECRET_KEY_C']
36
+ when '2.3.4' then ENV['STRIPE_TEST_SECRET_KEY_D']
37
+ end
38
+ else
39
+ api_key = ENV['STRIPE_TEST_SECRET_KEY']
40
+ if api_key.nil? || api_key == ''
41
+ raise "Please set your STRIPE_TEST_SECRET_KEY environment variable."
42
+ end
43
+ end
44
+
45
+ c.before(:each) do
46
+ allow(StripeMock).to receive(:start).and_return(nil)
47
+ allow(StripeMock).to receive(:stop).and_return(nil)
48
+ Stripe.api_key = api_key
49
+ end
50
+ c.after(:each) { sleep 0.01 }
51
+ else
52
+ c.filter_run_excluding :oauth => true
53
+ Stripe.api_key ||= ''
54
+ end
55
+
56
+ c.filter_run focus: true
57
+ c.run_all_when_everything_filtered = true
58
+ end
@@ -0,0 +1,123 @@
1
+ require 'spec_helper'
2
+
3
+ describe StripeMock do
4
+
5
+ it "overrides stripe's request method" do
6
+ StripeMock.start
7
+ Stripe::StripeClient.active_client.execute_request(:xtest, '/', api_key: 'abcde') # no error
8
+ StripeMock.stop
9
+ end
10
+
11
+ it "overrides stripe's execute_request method in other threads" do
12
+ StripeMock.start
13
+ Thread.new { Stripe::StripeClient.active_client.execute_request(:xtest, '/', api_key: 'abcde') }.join # no error
14
+ StripeMock.stop
15
+ end
16
+
17
+ it "reverts overriding stripe's request method" do
18
+ StripeMock.start
19
+ Stripe::StripeClient.active_client.execute_request(:xtest, '/', api_key: 'abcde') # no error
20
+ StripeMock.stop
21
+ expect { Stripe::StripeClient.active_client.execute_request(:x, '/', api_key: 'abcde') }.to raise_error ArgumentError
22
+ end
23
+
24
+ it "reverts overriding stripe's execute_request method in other threads" do
25
+ StripeMock.start
26
+ Thread.new { Stripe::StripeClient.active_client.execute_request(:xtest, '/', api_key: 'abcde') }.join # no error
27
+ StripeMock.stop
28
+ expect { Thread.new { Stripe::StripeClient.active_client.execute_request(:x, '/', api_key: 'abcde') }.join }.to raise_error ArgumentError
29
+ end
30
+
31
+ it "does not persist data between mock sessions" do
32
+ StripeMock.start
33
+ StripeMock.instance.customers[:x] = 9
34
+
35
+ StripeMock.stop
36
+ StripeMock.start
37
+
38
+ expect(StripeMock.instance.customers[:x]).to be_nil
39
+ expect(StripeMock.instance.customers.keys.length).to eq(0)
40
+ StripeMock.stop
41
+ end
42
+
43
+ it "throws an error when trying to prepare an error before starting" do
44
+ expect { StripeMock.prepare_error(StandardError.new) }.to raise_error {|e|
45
+ expect(e).to be_a(StripeMock::UnstartedStateError)
46
+ }
47
+
48
+ expect { StripeMock.prepare_card_error(:card_declined) }.to raise_error {|e|
49
+ expect(e).to be_a(StripeMock::UnstartedStateError)
50
+ }
51
+ end
52
+
53
+ describe "Live Testing" do
54
+ after { StripeMock.instance_variable_set(:@state, 'ready') }
55
+
56
+ it "sets the default test strategy" do
57
+ StripeMock.toggle_live(true)
58
+ expect(StripeMock.create_test_helper).to be_a StripeMock::TestStrategies::Live
59
+
60
+ StripeMock.toggle_live(false)
61
+ expect(StripeMock.create_test_helper).to be_a StripeMock::TestStrategies::Mock
62
+ end
63
+
64
+ it "does not start when live" do
65
+ expect(StripeMock.state).to eq 'ready'
66
+ StripeMock.toggle_live(true)
67
+ expect(StripeMock.state).to eq 'live'
68
+ expect(StripeMock.start).to eq false
69
+ expect(StripeMock.start_client).to eq false
70
+ end
71
+
72
+ it "can be undone" do
73
+ StripeMock.toggle_live(true)
74
+ StripeMock.toggle_live(false)
75
+ expect(StripeMock.state).to eq 'ready'
76
+ expect(StripeMock.start).to_not eq false
77
+ StripeMock.stop
78
+ end
79
+
80
+ it "cannot be toggled when already started" do
81
+ StripeMock.start
82
+ expect { StripeMock.toggle_live(true) }.to raise_error
83
+ StripeMock.stop
84
+
85
+ StripeMock.instance_variable_set(:@state, 'remote')
86
+ expect { StripeMock.toggle_live(true) }.to raise_error
87
+ end
88
+ end
89
+
90
+ describe "Test Helper Strategies" do
91
+ before { StripeMock.instance_variable_set("@__test_strat", nil) }
92
+
93
+ it "uses mock by default" do
94
+ helper = StripeMock.create_test_helper
95
+ expect(helper).to be_a StripeMock::TestStrategies::Mock
96
+ end
97
+
98
+ it "can specify which strategy to use" do
99
+ helper = StripeMock.create_test_helper(:live)
100
+ expect(helper).to be_a StripeMock::TestStrategies::Live
101
+
102
+ helper = StripeMock.create_test_helper(:mock)
103
+ expect(helper).to be_a StripeMock::TestStrategies::Mock
104
+ end
105
+
106
+ it "throws an error on an unknown strategy" do
107
+ expect { StripeMock.create_test_helper(:lol) }.to raise_error
108
+ end
109
+
110
+ it "can configure the default strategy" do
111
+ StripeMock.set_default_test_helper_strategy(:live)
112
+ helper = StripeMock.create_test_helper
113
+ expect(helper).to be_a StripeMock::TestStrategies::Live
114
+ end
115
+
116
+ it "can overrige a set default strategy" do
117
+ StripeMock.set_default_test_helper_strategy(:live)
118
+ helper = StripeMock.create_test_helper(:mock)
119
+ expect(helper).to be_a StripeMock::TestStrategies::Mock
120
+ end
121
+ end
122
+
123
+ end
@@ -0,0 +1,42 @@
1
+ def require_stripe_examples
2
+ Dir["./spec/shared_stripe_examples/**/*.rb"].each {|f| require f}
3
+ Dir["./spec/integration_examples/**/*.rb"].each {|f| require f}
4
+ end
5
+
6
+ def it_behaves_like_stripe(&block)
7
+ it_behaves_like 'Account API', &block
8
+ it_behaves_like 'Balance API', &block
9
+ it_behaves_like 'Balance Transaction API', &block
10
+ it_behaves_like 'Bank Account Token Mocking', &block
11
+ it_behaves_like 'Card Token Mocking', &block
12
+ it_behaves_like 'Card API', &block
13
+ it_behaves_like 'Charge API', &block
14
+ it_behaves_like 'Bank API', &block
15
+ it_behaves_like 'External Account API', &block
16
+ it_behaves_like 'Coupon API', &block
17
+ it_behaves_like 'Customer API', &block
18
+ it_behaves_like 'Dispute API', &block
19
+ it_behaves_like 'Extra Features', &block
20
+ it_behaves_like 'Invoice API', &block
21
+ it_behaves_like 'Invoice Item API', &block
22
+ it_behaves_like 'Plan API', &block
23
+ it_behaves_like 'Product API', &block
24
+ it_behaves_like 'Recipient API', &block
25
+ it_behaves_like 'Refund API', &block
26
+ it_behaves_like 'Transfer API', &block
27
+ it_behaves_like 'Payout API', &block
28
+ it_behaves_like 'PaymentIntent API', &block
29
+ it_behaves_like 'PaymentMethod API', &block
30
+ it_behaves_like 'Stripe Error Mocking', &block
31
+ it_behaves_like 'Customer Subscriptions', &block
32
+ it_behaves_like 'Subscription Items API', &block
33
+ it_behaves_like 'Webhook Events API', &block
34
+ it_behaves_like 'Country Spec API', &block
35
+ it_behaves_like 'EphemeralKey API', &block
36
+ it_behaves_like 'TaxRate API', &block
37
+
38
+ # Integration tests
39
+ it_behaves_like 'Multiple Customer Cards'
40
+ it_behaves_like 'Charging with Tokens'
41
+ it_behaves_like 'Card Error Prep'
42
+ end
@@ -0,0 +1,121 @@
1
+ require 'spec_helper'
2
+
3
+ describe StripeMock::Util do
4
+
5
+ describe 'rmerge' do
6
+ it "recursively merges a simple hash" do
7
+ dest = { x: { y: 50 }, a: 5, b: 3 }
8
+ source = { x: { y: 999 }, a: 77 }
9
+ result = StripeMock::Util.rmerge(dest, source)
10
+
11
+ expect(result).to eq({ x: { y: 999 }, a: 77, b: 3 })
12
+ end
13
+
14
+ it "recursively merges a nested hash" do
15
+ dest = { x: { y: 50, z: { m: 44, n: 4 } } }
16
+ source = { x: { y: 999, z: { n: 55 } } }
17
+ result = StripeMock::Util.rmerge(dest, source)
18
+
19
+ expect(result).to eq({ x: { y: 999, z: { m: 44, n: 55 } } })
20
+ end
21
+
22
+ it "merges array elements (that are hashes)" do
23
+ dest = { x: [ {a: 1}, {b: 2}, {c: 3} ] }
24
+ source = { x: [ {a: 0}, {a: 0} ] }
25
+ result = StripeMock::Util.rmerge(dest, source)
26
+
27
+ expect(result).to eq({ x: [ {a: 0}, {a: 0, b: 2}, {c: 3} ] })
28
+ end
29
+
30
+ context "array elements (that are simple values)" do
31
+ it "merges arrays" do
32
+ dest = { x: [ 1, 2 ] }
33
+ source = { x: [ 3, 4 ] }
34
+ result = StripeMock::Util.rmerge(dest, source)
35
+
36
+ expect(result).to eq({ x: [ 1, 3, 2, 4 ] })
37
+ end
38
+
39
+ it "ignores empty arrays" do
40
+ dest = { x: [] }
41
+ source = { x: [ 3, 4 ] }
42
+ result = StripeMock::Util.rmerge(dest, source)
43
+
44
+ expect(result).to eq({ x: [ 3, 4 ] })
45
+ end
46
+
47
+ it "removes nil values" do
48
+ dest = { x: [ 1, 2, nil ] }
49
+ source = { x: [ nil, 3, 4 ] }
50
+ result = StripeMock::Util.rmerge(dest, source)
51
+
52
+ expect(result).to eq({ x: [ 1, 2, 3, 4 ] })
53
+ end
54
+
55
+ it "respects duplicate values" do
56
+ dest = { x: [ 1, 2, 3 ] }
57
+ source = { x: [ 3, 4 ] }
58
+ result = StripeMock::Util.rmerge(dest, source)
59
+
60
+ expect(result).to eq({ x: [ 1, 3, 2, 4, 3 ] })
61
+ end
62
+ end
63
+
64
+ it "does not truncate the array when merging" do
65
+ dest = { x: [ {a: 1}, {b: 2} ] }
66
+ source = { x: [ nil, nil, {c: 3} ] }
67
+ result = StripeMock::Util.rmerge(dest, source)
68
+
69
+ expect(result).to eq({ x: [ {a: 1}, {b: 2}, {c: 3} ] })
70
+ end
71
+
72
+ it "treats an array nil element as a skip op" do
73
+ dest = { x: [ {a: 1}, {b: 2}, {c: 3} ] }
74
+ source = { x: [ nil, nil, {c: 0} ] }
75
+ result = StripeMock::Util.rmerge(dest, source)
76
+
77
+ expect(result).to eq({ x: [ {a: 1}, {b: 2}, {c: 0} ] })
78
+ end
79
+
80
+ it "treats nil as a replacement otherwise" do
81
+ dest = { x: 99 }
82
+ source = { x: nil }
83
+ result = StripeMock::Util.rmerge(dest, source)
84
+
85
+ expect(result).to eq({ x: nil })
86
+ end
87
+ end
88
+
89
+ describe 'card_merge' do
90
+ it 'merges last4 into number' do
91
+ new_param = { last4: '9999' }
92
+ old_param = { number: '4242424242424242' }
93
+ result = StripeMock::Util.card_merge(old_param, new_param)
94
+ expect(result[:last4]).to eq('9999')
95
+ expect(result[:number]).to eq('4242424242429999')
96
+ end
97
+
98
+ it 'overwrites old last4 if new number given' do
99
+ new_param = { number: '9999999999999999' }
100
+ old_param = { number: '4242424242424242', last4: '4242' }
101
+ result = StripeMock::Util.card_merge(old_param, new_param)
102
+ expect(result[:last4]).to eq('9999')
103
+ expect(result[:number]).to eq('9999999999999999')
104
+ end
105
+
106
+ it 'uses last4 in preference to number if both given' do
107
+ new_param = { number: '9999999999999999', last4: '1111' }
108
+ old_param = { number: '4242424242424242', last4: '4242' }
109
+ result = StripeMock::Util.card_merge(old_param, new_param)
110
+ expect(result[:last4]).to eq('1111')
111
+ expect(result[:number]).to eq('9999999999991111')
112
+ end
113
+
114
+ it 'simple merge if old and new cards are missing number' do
115
+ new_param = { last4: '1111' }
116
+ old_param = { last4: '4242' }
117
+ result = StripeMock::Util.card_merge(old_param, new_param)
118
+ expect(result[:last4]).to eq('1111')
119
+ end
120
+ end
121
+ end
@@ -0,0 +1,27 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ require File.expand_path('../lib/stripe_mock/version', __FILE__)
4
+
5
+ Gem::Specification.new do |gem|
6
+ gem.name = "epopia-stripe-ruby-mock"
7
+ gem.version = StripeMock::VERSION
8
+ gem.summary = %q{TDD with stripe (Epopia version)}
9
+ gem.description = %q{A drop-in library to test stripe without hitting their servers (Epopia version)}
10
+ gem.license = "MIT"
11
+ gem.authors = ["Gilbert"]
12
+ gem.email = "gilbertbgarza@gmail.com"
13
+ gem.homepage = "https://github.com/CreaLettres/stripe-ruby-mock"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ['lib']
19
+
20
+ gem.add_dependency 'stripe', '>= 2.0.3'
21
+ gem.add_dependency 'multi_json', '~> 1.0'
22
+ gem.add_dependency 'dante', '>= 0.2.0'
23
+
24
+ gem.add_development_dependency 'rspec', '~> 3.1.0'
25
+ gem.add_development_dependency 'rubygems-tasks', '~> 0.2'
26
+ gem.add_development_dependency 'thin', '~> 1.6.4'
27
+ end
metadata ADDED
@@ -0,0 +1,344 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: epopia-stripe-ruby-mock
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.5.8
5
+ platform: ruby
6
+ authors:
7
+ - Gilbert
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-12-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: stripe
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 2.0.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: multi_json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: dante
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 0.2.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 0.2.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 3.1.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 3.1.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubygems-tasks
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.2'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.2'
83
+ - !ruby/object:Gem::Dependency
84
+ name: thin
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.6.4
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.6.4
97
+ description: A drop-in library to test stripe without hitting their servers (Epopia
98
+ version)
99
+ email: gilbertbgarza@gmail.com
100
+ executables:
101
+ - stripe-mock-server
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".env"
106
+ - ".gitignore"
107
+ - ".rspec"
108
+ - ".travis.yml"
109
+ - Gemfile
110
+ - LICENSE.txt
111
+ - README.md
112
+ - Rakefile
113
+ - bin/stripe-mock-server
114
+ - lib/stripe_mock.rb
115
+ - lib/stripe_mock/api/account_balance.rb
116
+ - lib/stripe_mock/api/bank_tokens.rb
117
+ - lib/stripe_mock/api/card_tokens.rb
118
+ - lib/stripe_mock/api/client.rb
119
+ - lib/stripe_mock/api/conversion_rate.rb
120
+ - lib/stripe_mock/api/debug.rb
121
+ - lib/stripe_mock/api/errors.rb
122
+ - lib/stripe_mock/api/global_id_prefix.rb
123
+ - lib/stripe_mock/api/instance.rb
124
+ - lib/stripe_mock/api/live.rb
125
+ - lib/stripe_mock/api/server.rb
126
+ - lib/stripe_mock/api/test_helpers.rb
127
+ - lib/stripe_mock/api/webhooks.rb
128
+ - lib/stripe_mock/client.rb
129
+ - lib/stripe_mock/data.rb
130
+ - lib/stripe_mock/data/list.rb
131
+ - lib/stripe_mock/error_queue.rb
132
+ - lib/stripe_mock/errors/closed_client_connection_error.rb
133
+ - lib/stripe_mock/errors/server_timeout_error.rb
134
+ - lib/stripe_mock/errors/stripe_mock_error.rb
135
+ - lib/stripe_mock/errors/uninitialized_instance_error.rb
136
+ - lib/stripe_mock/errors/unstarted_state_error.rb
137
+ - lib/stripe_mock/errors/unsupported_request_error.rb
138
+ - lib/stripe_mock/instance.rb
139
+ - lib/stripe_mock/request_handlers/accounts.rb
140
+ - lib/stripe_mock/request_handlers/balance.rb
141
+ - lib/stripe_mock/request_handlers/balance_transactions.rb
142
+ - lib/stripe_mock/request_handlers/cards.rb
143
+ - lib/stripe_mock/request_handlers/charges.rb
144
+ - lib/stripe_mock/request_handlers/country_spec.rb
145
+ - lib/stripe_mock/request_handlers/coupons.rb
146
+ - lib/stripe_mock/request_handlers/customers.rb
147
+ - lib/stripe_mock/request_handlers/disputes.rb
148
+ - lib/stripe_mock/request_handlers/ephemeral_key.rb
149
+ - lib/stripe_mock/request_handlers/events.rb
150
+ - lib/stripe_mock/request_handlers/external_accounts.rb
151
+ - lib/stripe_mock/request_handlers/helpers/bank_account_helpers.rb
152
+ - lib/stripe_mock/request_handlers/helpers/card_helpers.rb
153
+ - lib/stripe_mock/request_handlers/helpers/charge_helpers.rb
154
+ - lib/stripe_mock/request_handlers/helpers/coupon_helpers.rb
155
+ - lib/stripe_mock/request_handlers/helpers/external_account_helpers.rb
156
+ - lib/stripe_mock/request_handlers/helpers/subscription_helpers.rb
157
+ - lib/stripe_mock/request_handlers/helpers/token_helpers.rb
158
+ - lib/stripe_mock/request_handlers/invoice_items.rb
159
+ - lib/stripe_mock/request_handlers/invoices.rb
160
+ - lib/stripe_mock/request_handlers/orders.rb
161
+ - lib/stripe_mock/request_handlers/payment_intents.rb
162
+ - lib/stripe_mock/request_handlers/payment_methods.rb
163
+ - lib/stripe_mock/request_handlers/payouts.rb
164
+ - lib/stripe_mock/request_handlers/plans.rb
165
+ - lib/stripe_mock/request_handlers/products.rb
166
+ - lib/stripe_mock/request_handlers/recipients.rb
167
+ - lib/stripe_mock/request_handlers/refunds.rb
168
+ - lib/stripe_mock/request_handlers/sources.rb
169
+ - lib/stripe_mock/request_handlers/subscription_items.rb
170
+ - lib/stripe_mock/request_handlers/subscriptions.rb
171
+ - lib/stripe_mock/request_handlers/tax_rates.rb
172
+ - lib/stripe_mock/request_handlers/tokens.rb
173
+ - lib/stripe_mock/request_handlers/transfers.rb
174
+ - lib/stripe_mock/request_handlers/validators/param_validators.rb
175
+ - lib/stripe_mock/server.rb
176
+ - lib/stripe_mock/test_strategies/base.rb
177
+ - lib/stripe_mock/test_strategies/live.rb
178
+ - lib/stripe_mock/test_strategies/mock.rb
179
+ - lib/stripe_mock/util.rb
180
+ - lib/stripe_mock/version.rb
181
+ - lib/stripe_mock/webhook_fixtures/account.application.deauthorized.json
182
+ - lib/stripe_mock/webhook_fixtures/account.external_account.created.json
183
+ - lib/stripe_mock/webhook_fixtures/account.external_account.deleted.json
184
+ - lib/stripe_mock/webhook_fixtures/account.external_account.updated.json
185
+ - lib/stripe_mock/webhook_fixtures/account.updated.json
186
+ - lib/stripe_mock/webhook_fixtures/balance.available.json
187
+ - lib/stripe_mock/webhook_fixtures/charge.dispute.closed.json
188
+ - lib/stripe_mock/webhook_fixtures/charge.dispute.created.json
189
+ - lib/stripe_mock/webhook_fixtures/charge.dispute.funds_reinstated.json
190
+ - lib/stripe_mock/webhook_fixtures/charge.dispute.funds_withdrawn.json
191
+ - lib/stripe_mock/webhook_fixtures/charge.dispute.updated.json
192
+ - lib/stripe_mock/webhook_fixtures/charge.failed.json
193
+ - lib/stripe_mock/webhook_fixtures/charge.refunded.json
194
+ - lib/stripe_mock/webhook_fixtures/charge.succeeded.json
195
+ - lib/stripe_mock/webhook_fixtures/charge.updated.json
196
+ - lib/stripe_mock/webhook_fixtures/coupon.created.json
197
+ - lib/stripe_mock/webhook_fixtures/coupon.deleted.json
198
+ - lib/stripe_mock/webhook_fixtures/customer.created.json
199
+ - lib/stripe_mock/webhook_fixtures/customer.deleted.json
200
+ - lib/stripe_mock/webhook_fixtures/customer.discount.created.json
201
+ - lib/stripe_mock/webhook_fixtures/customer.discount.deleted.json
202
+ - lib/stripe_mock/webhook_fixtures/customer.discount.updated.json
203
+ - lib/stripe_mock/webhook_fixtures/customer.source.created.json
204
+ - lib/stripe_mock/webhook_fixtures/customer.source.deleted.json
205
+ - lib/stripe_mock/webhook_fixtures/customer.source.updated.json
206
+ - lib/stripe_mock/webhook_fixtures/customer.subscription.created.json
207
+ - lib/stripe_mock/webhook_fixtures/customer.subscription.deleted.json
208
+ - lib/stripe_mock/webhook_fixtures/customer.subscription.trial_will_end.json
209
+ - lib/stripe_mock/webhook_fixtures/customer.subscription.updated.json
210
+ - lib/stripe_mock/webhook_fixtures/customer.updated.json
211
+ - lib/stripe_mock/webhook_fixtures/invoice.created.json
212
+ - lib/stripe_mock/webhook_fixtures/invoice.payment_failed.json
213
+ - lib/stripe_mock/webhook_fixtures/invoice.payment_succeeded.json
214
+ - lib/stripe_mock/webhook_fixtures/invoice.updated.json
215
+ - lib/stripe_mock/webhook_fixtures/invoiceitem.created.json
216
+ - lib/stripe_mock/webhook_fixtures/invoiceitem.deleted.json
217
+ - lib/stripe_mock/webhook_fixtures/invoiceitem.updated.json
218
+ - lib/stripe_mock/webhook_fixtures/plan.created.json
219
+ - lib/stripe_mock/webhook_fixtures/plan.deleted.json
220
+ - lib/stripe_mock/webhook_fixtures/plan.updated.json
221
+ - lib/stripe_mock/webhook_fixtures/transfer.created.json
222
+ - lib/stripe_mock/webhook_fixtures/transfer.failed.json
223
+ - lib/stripe_mock/webhook_fixtures/transfer.paid.json
224
+ - lib/stripe_mock/webhook_fixtures/transfer.updated.json
225
+ - lib/trollop.rb
226
+ - spec/_dummy/webhooks/dummy.event.json
227
+ - spec/api/instance_spec.rb
228
+ - spec/fixtures/create_refund.yml
229
+ - spec/fixtures/stripe_webhooks/account.updated.json
230
+ - spec/fixtures/stripe_webhooks/custom.account.updated.json
231
+ - spec/instance_spec.rb
232
+ - spec/integration_examples/charge_token_examples.rb
233
+ - spec/integration_examples/customer_card_examples.rb
234
+ - spec/integration_examples/prepare_error_examples.rb
235
+ - spec/list_spec.rb
236
+ - spec/readme_spec.rb
237
+ - spec/server_spec.rb
238
+ - spec/shared_stripe_examples/account_examples.rb
239
+ - spec/shared_stripe_examples/balance_examples.rb
240
+ - spec/shared_stripe_examples/balance_transaction_examples.rb
241
+ - spec/shared_stripe_examples/bank_examples.rb
242
+ - spec/shared_stripe_examples/bank_token_examples.rb
243
+ - spec/shared_stripe_examples/card_examples.rb
244
+ - spec/shared_stripe_examples/card_token_examples.rb
245
+ - spec/shared_stripe_examples/charge_examples.rb
246
+ - spec/shared_stripe_examples/country_specs_examples.rb
247
+ - spec/shared_stripe_examples/coupon_examples.rb
248
+ - spec/shared_stripe_examples/customer_examples.rb
249
+ - spec/shared_stripe_examples/dispute_examples.rb
250
+ - spec/shared_stripe_examples/ephemeral_key_examples.rb
251
+ - spec/shared_stripe_examples/error_mock_examples.rb
252
+ - spec/shared_stripe_examples/external_account_examples.rb
253
+ - spec/shared_stripe_examples/extra_features_examples.rb
254
+ - spec/shared_stripe_examples/invoice_examples.rb
255
+ - spec/shared_stripe_examples/invoice_item_examples.rb
256
+ - spec/shared_stripe_examples/payment_intent_examples.rb
257
+ - spec/shared_stripe_examples/payment_method_examples.rb
258
+ - spec/shared_stripe_examples/payout_examples.rb
259
+ - spec/shared_stripe_examples/plan_examples.rb
260
+ - spec/shared_stripe_examples/product_example.rb
261
+ - spec/shared_stripe_examples/recipient_examples.rb
262
+ - spec/shared_stripe_examples/refund_examples.rb
263
+ - spec/shared_stripe_examples/subscription_examples.rb
264
+ - spec/shared_stripe_examples/subscription_items_examples.rb
265
+ - spec/shared_stripe_examples/tax_rate_examples.rb
266
+ - spec/shared_stripe_examples/transfer_examples.rb
267
+ - spec/shared_stripe_examples/validation_examples.rb
268
+ - spec/shared_stripe_examples/webhook_event_examples.rb
269
+ - spec/spec_helper.rb
270
+ - spec/stripe_mock_spec.rb
271
+ - spec/support/stripe_examples.rb
272
+ - spec/util_spec.rb
273
+ - stripe-ruby-mock.gemspec
274
+ homepage: https://github.com/CreaLettres/stripe-ruby-mock
275
+ licenses:
276
+ - MIT
277
+ metadata: {}
278
+ post_install_message:
279
+ rdoc_options: []
280
+ require_paths:
281
+ - lib
282
+ required_ruby_version: !ruby/object:Gem::Requirement
283
+ requirements:
284
+ - - ">="
285
+ - !ruby/object:Gem::Version
286
+ version: '0'
287
+ required_rubygems_version: !ruby/object:Gem::Requirement
288
+ requirements:
289
+ - - ">="
290
+ - !ruby/object:Gem::Version
291
+ version: '0'
292
+ requirements: []
293
+ rubygems_version: 3.0.3
294
+ signing_key:
295
+ specification_version: 4
296
+ summary: TDD with stripe (Epopia version)
297
+ test_files:
298
+ - spec/_dummy/webhooks/dummy.event.json
299
+ - spec/api/instance_spec.rb
300
+ - spec/fixtures/create_refund.yml
301
+ - spec/fixtures/stripe_webhooks/account.updated.json
302
+ - spec/fixtures/stripe_webhooks/custom.account.updated.json
303
+ - spec/instance_spec.rb
304
+ - spec/integration_examples/charge_token_examples.rb
305
+ - spec/integration_examples/customer_card_examples.rb
306
+ - spec/integration_examples/prepare_error_examples.rb
307
+ - spec/list_spec.rb
308
+ - spec/readme_spec.rb
309
+ - spec/server_spec.rb
310
+ - spec/shared_stripe_examples/account_examples.rb
311
+ - spec/shared_stripe_examples/balance_examples.rb
312
+ - spec/shared_stripe_examples/balance_transaction_examples.rb
313
+ - spec/shared_stripe_examples/bank_examples.rb
314
+ - spec/shared_stripe_examples/bank_token_examples.rb
315
+ - spec/shared_stripe_examples/card_examples.rb
316
+ - spec/shared_stripe_examples/card_token_examples.rb
317
+ - spec/shared_stripe_examples/charge_examples.rb
318
+ - spec/shared_stripe_examples/country_specs_examples.rb
319
+ - spec/shared_stripe_examples/coupon_examples.rb
320
+ - spec/shared_stripe_examples/customer_examples.rb
321
+ - spec/shared_stripe_examples/dispute_examples.rb
322
+ - spec/shared_stripe_examples/ephemeral_key_examples.rb
323
+ - spec/shared_stripe_examples/error_mock_examples.rb
324
+ - spec/shared_stripe_examples/external_account_examples.rb
325
+ - spec/shared_stripe_examples/extra_features_examples.rb
326
+ - spec/shared_stripe_examples/invoice_examples.rb
327
+ - spec/shared_stripe_examples/invoice_item_examples.rb
328
+ - spec/shared_stripe_examples/payment_intent_examples.rb
329
+ - spec/shared_stripe_examples/payment_method_examples.rb
330
+ - spec/shared_stripe_examples/payout_examples.rb
331
+ - spec/shared_stripe_examples/plan_examples.rb
332
+ - spec/shared_stripe_examples/product_example.rb
333
+ - spec/shared_stripe_examples/recipient_examples.rb
334
+ - spec/shared_stripe_examples/refund_examples.rb
335
+ - spec/shared_stripe_examples/subscription_examples.rb
336
+ - spec/shared_stripe_examples/subscription_items_examples.rb
337
+ - spec/shared_stripe_examples/tax_rate_examples.rb
338
+ - spec/shared_stripe_examples/transfer_examples.rb
339
+ - spec/shared_stripe_examples/validation_examples.rb
340
+ - spec/shared_stripe_examples/webhook_event_examples.rb
341
+ - spec/spec_helper.rb
342
+ - spec/stripe_mock_spec.rb
343
+ - spec/support/stripe_examples.rb
344
+ - spec/util_spec.rb