stripe-ruby-mock 1.8.3.6 → 1.8.3.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/lib/stripe_mock.rb +8 -0
  2. data/lib/stripe_mock/api/errors.rb +16 -16
  3. data/lib/stripe_mock/api/webhooks.rb +55 -0
  4. data/lib/stripe_mock/errors/unsupported_request_error.rb +4 -0
  5. data/lib/stripe_mock/util.rb +23 -0
  6. data/lib/stripe_mock/version.rb +1 -1
  7. data/lib/stripe_mock/webhook_fixtures/account.application.deauthorized.json +12 -0
  8. data/lib/stripe_mock/webhook_fixtures/account.updated.json +24 -0
  9. data/lib/stripe_mock/webhook_fixtures/charge.dispute.closed.json +21 -0
  10. data/lib/stripe_mock/webhook_fixtures/charge.dispute.created.json +21 -0
  11. data/lib/stripe_mock/webhook_fixtures/charge.dispute.updated.json +24 -0
  12. data/lib/stripe_mock/webhook_fixtures/charge.failed.json +57 -0
  13. data/lib/stripe_mock/webhook_fixtures/charge.refunded.json +57 -0
  14. data/lib/stripe_mock/webhook_fixtures/charge.succeeded.json +57 -0
  15. data/lib/stripe_mock/webhook_fixtures/coupon.created.json +22 -0
  16. data/lib/stripe_mock/webhook_fixtures/coupon.deleted.json +22 -0
  17. data/lib/stripe_mock/webhook_fixtures/customer.created.json +40 -0
  18. data/lib/stripe_mock/webhook_fixtures/customer.deleted.json +40 -0
  19. data/lib/stripe_mock/webhook_fixtures/customer.discount.created.json +28 -0
  20. data/lib/stripe_mock/webhook_fixtures/customer.discount.deleted.json +28 -0
  21. data/lib/stripe_mock/webhook_fixtures/customer.discount.updated.json +43 -0
  22. data/lib/stripe_mock/webhook_fixtures/customer.subscription.created.json +34 -0
  23. data/lib/stripe_mock/webhook_fixtures/customer.subscription.deleted.json +34 -0
  24. data/lib/stripe_mock/webhook_fixtures/customer.subscription.trial_will_end.json +34 -0
  25. data/lib/stripe_mock/webhook_fixtures/customer.subscription.updated.json +47 -0
  26. data/lib/stripe_mock/webhook_fixtures/customer.updated.json +43 -0
  27. data/lib/stripe_mock/webhook_fixtures/invoice.created.json +64 -0
  28. data/lib/stripe_mock/webhook_fixtures/invoice.payment_failed.json +64 -0
  29. data/lib/stripe_mock/webhook_fixtures/invoice.payment_succeeded.json +64 -0
  30. data/lib/stripe_mock/webhook_fixtures/invoice.updated.json +67 -0
  31. data/lib/stripe_mock/webhook_fixtures/invoiceitem.created.json +21 -0
  32. data/lib/stripe_mock/webhook_fixtures/invoiceitem.deleted.json +21 -0
  33. data/lib/stripe_mock/webhook_fixtures/invoiceitem.updated.json +24 -0
  34. data/lib/stripe_mock/webhook_fixtures/plan.created.json +20 -0
  35. data/lib/stripe_mock/webhook_fixtures/plan.deleted.json +20 -0
  36. data/lib/stripe_mock/webhook_fixtures/plan.updated.json +23 -0
  37. data/lib/stripe_mock/webhook_fixtures/transfer.created.json +23 -0
  38. data/lib/stripe_mock/webhook_fixtures/transfer.failed.json +23 -0
  39. data/lib/stripe_mock/webhook_fixtures/transfer.paid.json +23 -0
  40. data/lib/stripe_mock/webhook_fixtures/transfer.updated.json +26 -0
  41. data/spec/spec_helper.rb +2 -0
  42. data/spec/util_spec.rb +45 -0
  43. data/spec/webhook_spec.rb +61 -0
  44. metadata +43 -2
data/spec/util_spec.rb ADDED
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe StripeMock::Util do
4
+
5
+ it "recursively merges a simple hash" do
6
+ hash_one = { x: { y: 50 }, a: 5, b: 3 }
7
+ hash_two = { x: { y: 999 }, a: 77 }
8
+ result = StripeMock::Util.rmerge(hash_one, hash_two)
9
+
10
+ expect(result).to eq({ x: { y: 999 }, a: 77, b: 3 })
11
+ end
12
+
13
+ it "recursively merges a nested hash" do
14
+ hash_one = { x: { y: 50, z: { m: 44, n: 4 } } }
15
+ hash_two = { x: { y: 999, z: { n: 55 } } }
16
+ result = StripeMock::Util.rmerge(hash_one, hash_two)
17
+
18
+ expect(result).to eq({ x: { y: 999, z: { m: 44, n: 55 } } })
19
+ end
20
+
21
+ it "merges array elements" do
22
+ hash_one = { x: [ {a: 1}, {b: 2}, {c: 3} ] }
23
+ hash_two = { x: [ {a: 0}, {a: 0} ] }
24
+ result = StripeMock::Util.rmerge(hash_one, hash_two)
25
+
26
+ expect(result).to eq({ x: [ {a: 0}, {a: 0, b: 2}, {c: 3} ] })
27
+ end
28
+
29
+ it "treats an array nil element as a skip op" do
30
+ hash_one = { x: [ {a: 1}, {b: 2}, {c: 3} ] }
31
+ hash_two = { x: [ nil, nil, {c: 0} ] }
32
+ result = StripeMock::Util.rmerge(hash_one, hash_two)
33
+
34
+ expect(result).to eq({ x: [ {a: 1}, {b: 2}, {c: 0} ] })
35
+ end
36
+
37
+ it "treats nil as a replacement otherwise" do
38
+ hash_one = { x: 99 }
39
+ hash_two = { x: nil }
40
+ result = StripeMock::Util.rmerge(hash_one, hash_two)
41
+
42
+ expect(result).to eq({ x: nil })
43
+ end
44
+
45
+ end
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Webhook Generation' do
4
+
5
+ it "matches the list of webhooks with the folder of fixtures" do
6
+ events = StripeMock::Webhooks.event_list.to_set
7
+ file_names = Dir['./lib/stripe_mock/webhook_fixtures/*'].map {|f| File.basename(f, '.json')}.to_set
8
+ expect(events - file_names).to eq(Set.new)
9
+ expect(file_names - events).to eq(Set.new)
10
+ end
11
+
12
+ it "generates an event" do
13
+ event = StripeMock.mock_webhook_event('customer.created')
14
+ expect(event).to be_a(Stripe::Event)
15
+ end
16
+
17
+ it "takes a hash and deep merges" do
18
+ event = StripeMock.mock_webhook_event('customer.created', {
19
+ :data => {
20
+ :object => {
21
+ :account_balance => 12345
22
+ }
23
+ }
24
+ })
25
+ expect(event.data.object.account_balance).to eq(12345)
26
+ end
27
+
28
+ it "takes a hash and deep merges arrays" do
29
+ event = StripeMock.mock_webhook_event('invoice.created', {
30
+ :data => {
31
+ :object => {
32
+ :lines => {
33
+ :data => [
34
+ { :amount => 555,
35
+ :plan => { :id => 'wh_test' }
36
+ }
37
+ ]
38
+ }
39
+ }
40
+ }
41
+ })
42
+ expect(event.data.object.lines.data.first.amount).to eq(555)
43
+ expect(event.data.object.lines.data.first.plan.id).to eq('wh_test')
44
+ # Ensure data from invoice.created.json is still present
45
+ expect(event.data.object.lines.data.first.type).to eq('subscription')
46
+ expect(event.data.object.lines.data.first.plan.currency).to eq('usd')
47
+ end
48
+
49
+ it "can generate all events" do
50
+ StripeMock::Webhooks.event_list.each do |event_name|
51
+ expect { StripeMock.mock_webhook_event(event_name) }.to_not raise_error
52
+ end
53
+ end
54
+
55
+ it "raises an error for non-existant event types" do
56
+ expect {
57
+ event = StripeMock.mock_webhook_event('cow.bell')
58
+ }.to raise_error StripeMock::UnsupportedRequestError
59
+ end
60
+
61
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stripe-ruby-mock
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.3.6
4
+ version: 1.8.3.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-17 00:00:00.000000000 Z
12
+ date: 2013-06-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: stripe
@@ -110,6 +110,7 @@ files:
110
110
  - lib/stripe_mock/api/errors.rb
111
111
  - lib/stripe_mock/api/instance.rb
112
112
  - lib/stripe_mock/api/server.rb
113
+ - lib/stripe_mock/api/webhooks.rb
113
114
  - lib/stripe_mock/client.rb
114
115
  - lib/stripe_mock/data.rb
115
116
  - lib/stripe_mock/errors/closed_client_connection_error.rb
@@ -117,13 +118,49 @@ files:
117
118
  - lib/stripe_mock/errors/stripe_mock_error.rb
118
119
  - lib/stripe_mock/errors/uninitialized_instance_error.rb
119
120
  - lib/stripe_mock/errors/unstarted_state_error.rb
121
+ - lib/stripe_mock/errors/unsupported_request_error.rb
120
122
  - lib/stripe_mock/instance.rb
121
123
  - lib/stripe_mock/request_handlers/charges.rb
122
124
  - lib/stripe_mock/request_handlers/customers.rb
123
125
  - lib/stripe_mock/request_handlers/invoice_items.rb
124
126
  - lib/stripe_mock/request_handlers/plans.rb
125
127
  - lib/stripe_mock/server.rb
128
+ - lib/stripe_mock/util.rb
126
129
  - lib/stripe_mock/version.rb
130
+ - lib/stripe_mock/webhook_fixtures/account.application.deauthorized.json
131
+ - lib/stripe_mock/webhook_fixtures/account.updated.json
132
+ - lib/stripe_mock/webhook_fixtures/charge.dispute.closed.json
133
+ - lib/stripe_mock/webhook_fixtures/charge.dispute.created.json
134
+ - lib/stripe_mock/webhook_fixtures/charge.dispute.updated.json
135
+ - lib/stripe_mock/webhook_fixtures/charge.failed.json
136
+ - lib/stripe_mock/webhook_fixtures/charge.refunded.json
137
+ - lib/stripe_mock/webhook_fixtures/charge.succeeded.json
138
+ - lib/stripe_mock/webhook_fixtures/coupon.created.json
139
+ - lib/stripe_mock/webhook_fixtures/coupon.deleted.json
140
+ - lib/stripe_mock/webhook_fixtures/customer.created.json
141
+ - lib/stripe_mock/webhook_fixtures/customer.deleted.json
142
+ - lib/stripe_mock/webhook_fixtures/customer.discount.created.json
143
+ - lib/stripe_mock/webhook_fixtures/customer.discount.deleted.json
144
+ - lib/stripe_mock/webhook_fixtures/customer.discount.updated.json
145
+ - lib/stripe_mock/webhook_fixtures/customer.subscription.created.json
146
+ - lib/stripe_mock/webhook_fixtures/customer.subscription.deleted.json
147
+ - lib/stripe_mock/webhook_fixtures/customer.subscription.trial_will_end.json
148
+ - lib/stripe_mock/webhook_fixtures/customer.subscription.updated.json
149
+ - lib/stripe_mock/webhook_fixtures/customer.updated.json
150
+ - lib/stripe_mock/webhook_fixtures/invoice.created.json
151
+ - lib/stripe_mock/webhook_fixtures/invoice.payment_failed.json
152
+ - lib/stripe_mock/webhook_fixtures/invoice.payment_succeeded.json
153
+ - lib/stripe_mock/webhook_fixtures/invoice.updated.json
154
+ - lib/stripe_mock/webhook_fixtures/invoiceitem.created.json
155
+ - lib/stripe_mock/webhook_fixtures/invoiceitem.deleted.json
156
+ - lib/stripe_mock/webhook_fixtures/invoiceitem.updated.json
157
+ - lib/stripe_mock/webhook_fixtures/plan.created.json
158
+ - lib/stripe_mock/webhook_fixtures/plan.deleted.json
159
+ - lib/stripe_mock/webhook_fixtures/plan.updated.json
160
+ - lib/stripe_mock/webhook_fixtures/transfer.created.json
161
+ - lib/stripe_mock/webhook_fixtures/transfer.failed.json
162
+ - lib/stripe_mock/webhook_fixtures/transfer.paid.json
163
+ - lib/stripe_mock/webhook_fixtures/transfer.updated.json
127
164
  - lib/trollop.rb
128
165
  - spec/instance_spec.rb
129
166
  - spec/readme_spec.rb
@@ -136,6 +173,8 @@ files:
136
173
  - spec/spec_helper.rb
137
174
  - spec/stripe_mock_spec.rb
138
175
  - spec/support/stripe_examples.rb
176
+ - spec/util_spec.rb
177
+ - spec/webhook_spec.rb
139
178
  - stripe-ruby-mock.gemspec
140
179
  homepage: https://github.com/mindeavor/stripe-ruby-mock
141
180
  licenses:
@@ -174,3 +213,5 @@ test_files:
174
213
  - spec/spec_helper.rb
175
214
  - spec/stripe_mock_spec.rb
176
215
  - spec/support/stripe_examples.rb
216
+ - spec/util_spec.rb
217
+ - spec/webhook_spec.rb