Skip to content

Commit 92bedc9

Browse files
committed
Merge pull request stripe-ruby-mock#308 from mhenrixon/master
Allow webhooks for Stripe Connect
2 parents ce99122 + fd265d8 commit 92bedc9

File tree

3 files changed

+18
-5
lines changed

3 files changed

+18
-5
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,12 @@ it "mocks a stripe webhook" do
292292
expect(customer_object.default_card).to_not be_nil
293293
# etc.
294294
end
295+
296+
it "mocks stripe connect webhooks" do
297+
event = StripeMock.mock_webhook_event('customer.created', user_id: 'acc_123123')
298+
299+
expect(event.user_id).to eq('acc_123123')
300+
end
295301
```
296302

297303
### Customizing Webhooks

lib/stripe_mock/api/webhooks.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def self.mock_webhook_payload(type, params = {})
1515

1616
json = Stripe::Util.symbolize_names(json)
1717
params = Stripe::Util.symbolize_names(params)
18+
json[:user_id] = params.delete(:user_id) if params.key?(:user_id)
1819
json[:data][:object] = Util.rmerge(json[:data][:object], params)
1920
json.delete(:id)
2021

spec/shared_stripe_examples/webhook_event_examples.rb

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@
7070
expect(data[event_b.id][:id]).to eq(event_b.id)
7171
end
7272

73+
it "handles stripe connect event when user_id is present" do
74+
acc_12314 = 'acc_12314'
75+
event = StripeMock.mock_webhook_event('customer.created', user_id: acc_12314)
76+
expect(event[:user_id]).to eq(acc_12314)
77+
end
78+
7379
it "retrieves an eveng using the event resource" do
7480
webhook_event = StripeMock.mock_webhook_event('plan.created')
7581
expect(webhook_event.id).to_not be_nil
@@ -145,9 +151,9 @@
145151
invoice_item_created_event = StripeMock.mock_webhook_event('invoiceitem.created')
146152
expect(invoice_item_created_event).to be_a(Stripe::Event)
147153
expect(invoice_item_created_event).to_not be_nil
148-
154+
149155
events = Stripe::Event.all
150-
156+
151157
expect(events.count).to eq(5)
152158
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)
153159
expect(events.map &:type).to include('customer.created', 'plan.created', 'coupon.created', 'invoice.created', 'invoiceitem.created')
@@ -173,13 +179,13 @@
173179
invoice_item_created_event = StripeMock.mock_webhook_event('invoiceitem.created')
174180
expect(invoice_item_created_event).to be_a(Stripe::Event)
175181
expect(invoice_item_created_event).to_not be_nil
176-
182+
177183
events = Stripe::Event.all(limit: 3)
178-
184+
179185
expect(events.count).to eq(3)
180186
expect(events.map &:id).to include(customer_created_event.id, plan_created_event.id, coupon_created_event.id)
181187
expect(events.map &:type).to include('customer.created', 'plan.created', 'coupon.created')
182-
end
188+
end
183189

184190
end
185191

0 commit comments

Comments
 (0)