forked from stripe-ruby-mock/stripe-ruby-mock
-
Notifications
You must be signed in to change notification settings - Fork 6
/
invoice_items.rb
45 lines (37 loc) · 1.44 KB
/
invoice_items.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
module StripeMock
module RequestHandlers
module InvoiceItems
def InvoiceItems.included(klass)
klass.add_handler 'post /v1/invoiceitems', :new_invoice_item
klass.add_handler 'post /v1/invoiceitems/(.*)', :update_invoice_item
klass.add_handler 'get /v1/invoiceitems/(.*)', :get_invoice_item
klass.add_handler 'get /v1/invoiceitems', :list_invoice_items
klass.add_handler 'delete /v1/invoiceitems/(.*)', :delete_invoice_item
end
def new_invoice_item(route, method_url, params, headers)
params[:id] ||= new_id('ii')
invoice_items[params[:id]] = Data.mock_invoice_item(params)
end
def update_invoice_item(route, method_url, params, headers)
route =~ method_url
list_item = assert_existence :list_item, $1, invoice_items[$1]
list_item.merge!(params)
end
def delete_invoice_item(route, method_url, params, headers)
route =~ method_url
assert_existence :list_item, $1, invoice_items[$1]
invoice_items[$1] = {
id: invoice_items[$1][:id],
deleted: true
}
end
def list_invoice_items(route, method_url, params, headers)
Data.mock_list_object(invoice_items.values, params)
end
def get_invoice_item(route, method_url, params, headers)
route =~ method_url
assert_existence :invoice_item, $1, invoice_items[$1]
end
end
end
end