Skip to content

Commit 2e62498

Browse files
committed
Merge pull request stripe-ruby-mock#291 from nomanurrehman/master
All Events Endpoint Implemented
2 parents 0c1c780 + 32d982b commit 2e62498

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

lib/stripe_mock/request_handlers/events.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,18 @@ module Events
44

55
def Events.included(klass)
66
klass.add_handler 'get /v1/events/(.*)', :retrieve_event
7+
klass.add_handler 'get /v1/events', :list_events
78
end
89

910
def retrieve_event(route, method_url, params, headers)
1011
route =~ method_url
1112
assert_existence :event, $1, events[$1]
1213
end
1314

15+
def list_events(route, method_url, params, headers)
16+
Data.mock_list_object(events.values, params)
17+
end
18+
1419
end
1520
end
1621
end

spec/shared_stripe_examples/webhook_event_examples.rb

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,64 @@
123123
}.to raise_error StripeMock::UnsupportedRequestError
124124
end
125125

126+
describe "listing events" do
127+
128+
it "retrieves all events" do
129+
customer_created_event = StripeMock.mock_webhook_event('customer.created')
130+
expect(customer_created_event).to be_a(Stripe::Event)
131+
expect(customer_created_event.id).to_not be_nil
132+
133+
plan_created_event = StripeMock.mock_webhook_event('plan.created')
134+
expect(plan_created_event).to be_a(Stripe::Event)
135+
expect(plan_created_event.id).to_not be_nil
136+
137+
coupon_created_event = StripeMock.mock_webhook_event('coupon.created')
138+
expect(coupon_created_event).to be_a(Stripe::Event)
139+
expect(coupon_created_event).to_not be_nil
140+
141+
invoice_created_event = StripeMock.mock_webhook_event('invoice.created')
142+
expect(invoice_created_event).to be_a(Stripe::Event)
143+
expect(invoice_created_event).to_not be_nil
144+
145+
invoice_item_created_event = StripeMock.mock_webhook_event('invoiceitem.created')
146+
expect(invoice_item_created_event).to be_a(Stripe::Event)
147+
expect(invoice_item_created_event).to_not be_nil
148+
149+
events = Stripe::Event.all
150+
151+
expect(events.count).to eq(5)
152+
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)
153+
expect(events.map &:type).to include('customer.created', 'plan.created', 'coupon.created', 'invoice.created', 'invoiceitem.created')
154+
end
155+
156+
it "retrieves events with a limit(3)" do
157+
customer_created_event = StripeMock.mock_webhook_event('customer.created')
158+
expect(customer_created_event).to be_a(Stripe::Event)
159+
expect(customer_created_event.id).to_not be_nil
160+
161+
plan_created_event = StripeMock.mock_webhook_event('plan.created')
162+
expect(plan_created_event).to be_a(Stripe::Event)
163+
expect(plan_created_event.id).to_not be_nil
164+
165+
coupon_created_event = StripeMock.mock_webhook_event('coupon.created')
166+
expect(coupon_created_event).to be_a(Stripe::Event)
167+
expect(coupon_created_event).to_not be_nil
168+
169+
invoice_created_event = StripeMock.mock_webhook_event('invoice.created')
170+
expect(invoice_created_event).to be_a(Stripe::Event)
171+
expect(invoice_created_event).to_not be_nil
172+
173+
invoice_item_created_event = StripeMock.mock_webhook_event('invoiceitem.created')
174+
expect(invoice_item_created_event).to be_a(Stripe::Event)
175+
expect(invoice_item_created_event).to_not be_nil
176+
177+
events = Stripe::Event.all(limit: 3)
178+
179+
expect(events.count).to eq(3)
180+
expect(events.map &:id).to include(customer_created_event.id, plan_created_event.id, coupon_created_event.id)
181+
expect(events.map &:type).to include('customer.created', 'plan.created', 'coupon.created')
182+
end
183+
184+
end
185+
126186
end

0 commit comments

Comments
 (0)