mirror of
https://github.com/stripe/stripe-ruby.git
synced 2025-06-02 00:00:35 -04:00
More updated tests
This commit is contained in:
parent
1ef1f79a16
commit
0019cfdc7e
@ -3,13 +3,15 @@ require File.expand_path('../../test_helper', __FILE__)
|
|||||||
module Stripe
|
module Stripe
|
||||||
class DisputeTest < Test::Unit::TestCase
|
class DisputeTest < Test::Unit::TestCase
|
||||||
should "disputes should be retrievable" do
|
should "disputes should be retrievable" do
|
||||||
@mock.expects(:get).once.returns(make_response(make_dispute))
|
stub_request(:get, "#{Stripe.api_base}/v1/disputes/dp_test_dispute").
|
||||||
|
to_return(body: make_response(make_dispute))
|
||||||
d = Stripe::Dispute.retrieve('dp_test_dispute')
|
d = Stripe::Dispute.retrieve('dp_test_dispute')
|
||||||
assert d.kind_of?(Stripe::Dispute)
|
assert d.kind_of?(Stripe::Dispute)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "disputes should be listable" do
|
should "disputes should be listable" do
|
||||||
@mock.expects(:get).once.returns(make_response(make_dispute_array))
|
stub_request(:get, "#{Stripe.api_base}/v1/disputes").
|
||||||
|
to_return(body: make_response(make_dispute_array))
|
||||||
d = Stripe::Dispute.list
|
d = Stripe::Dispute.list
|
||||||
assert d.data.kind_of? Array
|
assert d.data.kind_of? Array
|
||||||
d.each do |dispute|
|
d.each do |dispute|
|
||||||
@ -18,34 +20,27 @@ module Stripe
|
|||||||
end
|
end
|
||||||
|
|
||||||
should "disputes should be closeable" do
|
should "disputes should be closeable" do
|
||||||
@mock.expects(:get).never
|
stub_request(:post, "#{Stripe.api_base}/v1/disputes/dp_test_dispute/close").
|
||||||
@mock.expects(:post).with(
|
to_return(body: make_response(make_dispute))
|
||||||
"#{Stripe.api_base}/v1/disputes/test_dispute/close",
|
d = Stripe::Dispute.new('dp_test_dispute')
|
||||||
nil,
|
|
||||||
''
|
|
||||||
).once.returns(make_response({:id => 'dp_test_dispute', :status => 'lost'}))
|
|
||||||
d = Stripe::Dispute.new('test_dispute')
|
|
||||||
d.close
|
d.close
|
||||||
end
|
end
|
||||||
|
|
||||||
should "disputes should be updateable" do
|
should "disputes should be updateable" do
|
||||||
@mock.expects(:post).once.
|
stub_request(:post, "#{Stripe.api_base}/v1/disputes/dp_test_dispute").
|
||||||
with("https://api.stripe.com/v1/disputes/test_dispute", nil, "metadata[foo]=bar").
|
with(body: { metadata: { foo: "bar" } }).
|
||||||
returns(make_response(make_dispute(metadata: {foo: 'bar'})))
|
to_return(body: make_response(make_dispute))
|
||||||
d = Stripe::Dispute.update("test_dispute", metadata: {foo: 'bar'})
|
_ = Stripe::Dispute.update("dp_test_dispute", metadata: {foo: 'bar'})
|
||||||
assert_equal('bar', d.metadata['foo'])
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "disputes should be saveable" do
|
should "disputes should be saveable" do
|
||||||
@mock.expects(:get).once.returns(make_response(make_dispute))
|
stub_request(:get, "#{Stripe.api_base}/v1/disputes/dp_test_dispute").
|
||||||
@mock.expects(:post).with(
|
to_return(body: make_response(make_dispute))
|
||||||
"#{Stripe.api_base}/v1/disputes/dp_test_dispute",
|
d = Stripe::Dispute.retrieve('dp_test_dispute')
|
||||||
nil,
|
|
||||||
'evidence[customer_name]=customer'
|
|
||||||
).once.returns(make_response(make_dispute))
|
|
||||||
|
|
||||||
d = Stripe::Dispute.new('test_dispute')
|
stub_request(:post, "#{Stripe.api_base}/v1/disputes/dp_test_dispute").
|
||||||
d.refresh
|
with(body: { evidence: { customer_name: "customer" } }).
|
||||||
|
to_return(body: make_response(make_dispute))
|
||||||
d.evidence['customer_name'] = 'customer'
|
d.evidence['customer_name'] = 'customer'
|
||||||
d.save
|
d.save
|
||||||
end
|
end
|
||||||
|
@ -3,33 +3,26 @@ require File.expand_path('../../test_helper', __FILE__)
|
|||||||
module Stripe
|
module Stripe
|
||||||
class FileUploadTest < Test::Unit::TestCase
|
class FileUploadTest < Test::Unit::TestCase
|
||||||
should "create should return a new file" do
|
should "create should return a new file" do
|
||||||
params = {
|
stub_request(:post, "#{Stripe.uploads_base}/v1/files").
|
||||||
|
to_return(body: make_response(make_file))
|
||||||
|
|
||||||
|
f = Stripe::FileUpload.create({
|
||||||
:purpose => "dispute_evidence",
|
:purpose => "dispute_evidence",
|
||||||
:file => File.new(__FILE__),
|
:file => File.new(__FILE__),
|
||||||
}
|
})
|
||||||
|
|
||||||
@mock.expects(:post).once.
|
|
||||||
with("#{Stripe.uploads_base}/v1/files", nil, params).
|
|
||||||
returns(make_response(make_file))
|
|
||||||
|
|
||||||
f = Stripe::FileUpload.create(params)
|
|
||||||
assert_equal "fil_test_file", f.id
|
assert_equal "fil_test_file", f.id
|
||||||
end
|
end
|
||||||
|
|
||||||
should "files should be retrievable" do
|
should "files should be retrievable" do
|
||||||
@mock.expects(:get).once.
|
stub_request(:get, "#{Stripe.uploads_base}/v1/files/fil_test_file").
|
||||||
with("#{Stripe.uploads_base}/v1/files/fil_test_file", nil, nil).
|
to_return(body: make_response(make_file))
|
||||||
returns(make_response(make_file))
|
|
||||||
|
|
||||||
c = Stripe::FileUpload.new("fil_test_file")
|
_ = Stripe::FileUpload.retrieve("fil_test_file")
|
||||||
c.refresh
|
|
||||||
assert_equal 1403047735, c.created
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "files should be listable" do
|
should "files should be listable" do
|
||||||
@mock.expects(:get).once.
|
stub_request(:get, "#{Stripe.uploads_base}/v1/files").
|
||||||
with("#{Stripe.uploads_base}/v1/files", nil, nil).
|
to_return(body: make_response(make_file_array))
|
||||||
returns(make_response(make_file_array))
|
|
||||||
|
|
||||||
c = Stripe::FileUpload.list.data
|
c = Stripe::FileUpload.list.data
|
||||||
assert c.kind_of? Array
|
assert c.kind_of? Array
|
||||||
|
@ -3,17 +3,16 @@ require File.expand_path('../../test_helper', __FILE__)
|
|||||||
module Stripe
|
module Stripe
|
||||||
class InvoiceItemTest < Test::Unit::TestCase
|
class InvoiceItemTest < Test::Unit::TestCase
|
||||||
should "retrieve should retrieve invoice items" do
|
should "retrieve should retrieve invoice items" do
|
||||||
@mock.expects(:get).once.returns(make_response(make_invoice_item))
|
stub_request(:get, "#{Stripe.api_base}/v1/invoiceitems/ii_test_invoice_item").
|
||||||
ii = Stripe::InvoiceItem.retrieve('in_test_invoice_item')
|
to_return(body: make_response(make_invoice_item))
|
||||||
assert_equal 'ii_test_invoice_item', ii.id
|
_ = Stripe::InvoiceItem.retrieve('ii_test_invoice_item')
|
||||||
end
|
end
|
||||||
|
|
||||||
should "invoice items should be updateable" do
|
should "invoice items should be updateable" do
|
||||||
@mock.expects(:post).once.
|
stub_request(:post, "#{Stripe.api_base}/v1/invoiceitems/ii_test_invoice_item").
|
||||||
with('https://api.stripe.com/v1/invoiceitems/test_invoice_item', nil, 'metadata[foo]=bar').
|
with(body: { metadata: { foo: "bar" } }).
|
||||||
returns(make_response(make_charge(metadata: {'foo' => 'bar'})))
|
to_return(body: make_response(make_invoice_item))
|
||||||
ii = Stripe::InvoiceItem.update("test_invoice_item", metadata: {foo: 'bar'})
|
_ = Stripe::InvoiceItem.update("ii_test_invoice_item", metadata: {foo: 'bar'})
|
||||||
assert_equal('bar', ii.metadata['foo'])
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -3,62 +3,46 @@ require File.expand_path('../../test_helper', __FILE__)
|
|||||||
module Stripe
|
module Stripe
|
||||||
class InvoiceTest < Test::Unit::TestCase
|
class InvoiceTest < Test::Unit::TestCase
|
||||||
should "retrieve should retrieve invoices" do
|
should "retrieve should retrieve invoices" do
|
||||||
@mock.expects(:get).once.returns(make_response(make_invoice))
|
stub_request(:get, "#{Stripe.api_base}/v1/invoices/in_test_invoice").
|
||||||
|
to_return(body: make_response(make_invoice))
|
||||||
i = Stripe::Invoice.retrieve('in_test_invoice')
|
i = Stripe::Invoice.retrieve('in_test_invoice')
|
||||||
assert_equal 'in_test_invoice', i.id
|
assert_equal 'in_test_invoice', i.id
|
||||||
end
|
end
|
||||||
|
|
||||||
should "create should create a new invoice" do
|
should "create should create a new invoice" do
|
||||||
@mock.expects(:post).once.returns(make_response(make_invoice))
|
stub_request(:post, "#{Stripe.api_base}/v1/invoices").
|
||||||
i = Stripe::Invoice.create
|
to_return(body: make_response(make_invoice))
|
||||||
assert_equal "in_test_invoice", i.id
|
_ = Stripe::Invoice.create
|
||||||
end
|
end
|
||||||
|
|
||||||
should "pay should pay an invoice" do
|
should "pay should pay an invoice" do
|
||||||
@mock.expects(:get).once.returns(make_response(make_invoice))
|
stub_request(:get, "#{Stripe.api_base}/v1/invoices/in_test_invoice").
|
||||||
|
to_return(body: make_response(make_invoice))
|
||||||
i = Stripe::Invoice.retrieve('in_test_invoice')
|
i = Stripe::Invoice.retrieve('in_test_invoice')
|
||||||
|
|
||||||
@mock.expects(:post).once.with('https://api.stripe.com/v1/invoices/in_test_invoice/pay', nil, '').returns(make_response(make_paid_invoice))
|
stub_request(:post, "#{Stripe.api_base}/v1/invoices/#{i.id}/pay").
|
||||||
|
to_return(body: make_response(make_invoice))
|
||||||
i.pay
|
i.pay
|
||||||
assert_equal nil, i.next_payment_attempt
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "invoices should be updateable" do
|
should "invoices should be updateable" do
|
||||||
@mock.expects(:post).once.
|
stub_request(:post, "#{Stripe.api_base}/v1/invoices/test_invoice").
|
||||||
with("https://api.stripe.com/v1/invoices/test_invoice", nil, "metadata[foo]=bar").
|
with(body: { metadata: { foo: "bar" } }).
|
||||||
returns(make_response(make_invoice(metadata: {foo: 'bar'})))
|
to_return(body: make_response(make_invoice))
|
||||||
i = Stripe::Invoice.update("test_invoice", metadata: {foo: 'bar'})
|
_ = Stripe::Invoice.update("test_invoice", metadata: {foo: 'bar'})
|
||||||
assert_equal('bar', i.metadata['foo'])
|
|
||||||
end
|
|
||||||
|
|
||||||
should "pay with extra opts should pay an invoice" do
|
|
||||||
@mock.expects(:get).once.returns(make_response(make_invoice))
|
|
||||||
i = Stripe::Invoice.retrieve('in_test_invoice', {:api_key => 'foobar'})
|
|
||||||
|
|
||||||
@mock.expects(:post).once.width do |url, _, _|
|
|
||||||
url == "#{Stripe.api_base}/v1/invoices/in_test_invoice/pay"
|
|
||||||
end.returns(make_response(make_paid_invoice))
|
|
||||||
|
|
||||||
i.pay
|
|
||||||
assert_equal nil, i.next_payment_attempt
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "be able to retrieve upcoming invoices" do
|
should "be able to retrieve upcoming invoices" do
|
||||||
base = "#{Stripe.api_base}/v1/invoices/upcoming?"
|
stub_request(:get, "#{Stripe.api_base}/v1/invoices/upcoming").
|
||||||
cus_sub = "customer=c_test_customer&subscription=s_test_subscription&"
|
with(query: {
|
||||||
item0 = "subscription_items[][plan]=gold&subscription_items[][quantity]=1&"
|
:customer => 'c_test_customer',
|
||||||
item1 = "subscription_items[][plan]=silver&subscription_items[][quantity]=2"
|
:subscription => 's_test_subscription',
|
||||||
@mock.expects(:get).once.with(base + cus_sub + item0 + item1, nil, nil).
|
}).
|
||||||
returns(make_response(make_invoice(:customer => 'c_test_customer', :subscription => 's_test_subscription')))
|
to_return(body: make_response(make_invoice))
|
||||||
|
_ = Stripe::Invoice.upcoming(
|
||||||
i = Stripe::Invoice.upcoming(
|
|
||||||
:customer => 'c_test_customer',
|
:customer => 'c_test_customer',
|
||||||
:subscription => 's_test_subscription',
|
:subscription => 's_test_subscription',
|
||||||
:subscription_items => [{:plan => 'gold', :quantity =>1}, {:plan => 'silver', :quantity =>2}]
|
|
||||||
)
|
)
|
||||||
|
|
||||||
assert_equal 'c_test_customer', i.customer
|
|
||||||
assert_equal 's_test_subscription', i.subscription
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -36,8 +36,9 @@ module Stripe
|
|||||||
:has_more => true,
|
:has_more => true,
|
||||||
:url => "/things",
|
:url => "/things",
|
||||||
})
|
})
|
||||||
@mock.expects(:get).once.with("#{Stripe.api_base}/things?starting_after=1", nil, nil).
|
stub_request(:get, "#{Stripe.api_base}/things").
|
||||||
returns(make_response({ :data => [{ :id => 2 }, { :id => 3}], :has_more => false }))
|
with(query: { starting_after: "1" }).
|
||||||
|
to_return(body: make_response({ :data => [{ :id => 2 }, { :id => 3}], :has_more => false }))
|
||||||
|
|
||||||
assert_equal expected, list.auto_paging_each.to_a
|
assert_equal expected, list.auto_paging_each.to_a
|
||||||
end
|
end
|
||||||
@ -55,8 +56,9 @@ module Stripe
|
|||||||
:has_more => true,
|
:has_more => true,
|
||||||
:url => "/things",
|
:url => "/things",
|
||||||
})
|
})
|
||||||
@mock.expects(:get).once.with("#{Stripe.api_base}/things?starting_after=1", nil, nil).
|
stub_request(:get, "#{Stripe.api_base}/things").
|
||||||
returns(make_response({ :data => [{ :id => 2 }, { :id => 3}], :has_more => false }))
|
with(query: { starting_after: "1" }).
|
||||||
|
to_return(body: make_response({ :data => [{ :id => 2 }, { :id => 3}], :has_more => false }))
|
||||||
|
|
||||||
actual = []
|
actual = []
|
||||||
list.auto_paging_each do |obj|
|
list.auto_paging_each do |obj|
|
||||||
@ -83,8 +85,9 @@ module Stripe
|
|||||||
:has_more => true,
|
:has_more => true,
|
||||||
:url => "/things",
|
:url => "/things",
|
||||||
})
|
})
|
||||||
@mock.expects(:get).once.with("#{Stripe.api_base}/things?starting_after=1", nil, nil).
|
stub_request(:get, "#{Stripe.api_base}/things").
|
||||||
returns(make_response({ :data => [{ :id => 2 }], :has_more => false }))
|
with(query: { starting_after: "1" }).
|
||||||
|
to_return(body: make_response({ :data => [{ :id => 2 }], :has_more => false }))
|
||||||
next_list = list.next_page
|
next_list = list.next_page
|
||||||
refute next_list.empty?
|
refute next_list.empty?
|
||||||
end
|
end
|
||||||
@ -96,15 +99,9 @@ module Stripe
|
|||||||
:url => "/things",
|
:url => "/things",
|
||||||
})
|
})
|
||||||
list.filters = { :expand => ['data.source'], :limit => 3 }
|
list.filters = { :expand => ['data.source'], :limit => 3 }
|
||||||
@mock.expects(:get).with do |url, _, _|
|
stub_request(:get, "#{Stripe.api_base}/things").
|
||||||
u = URI.parse(url)
|
with(query: { "expand[]" => "data.source", "limit" => "3", "starting_after" => "1" }).
|
||||||
params = CGI.parse(u.query)
|
to_return(body: make_response({ :data => [{ :id => 2 }], :has_more => false }))
|
||||||
u.host == URI.parse(Stripe.api_base).host && u.path == "/things" && params == {
|
|
||||||
"expand[]" => ["data.source"],
|
|
||||||
"limit" => ["3"],
|
|
||||||
"starting_after" => ["1"],
|
|
||||||
}
|
|
||||||
end.returns(make_response({ :data => [{ :id => 2 }], :has_more => false }))
|
|
||||||
next_list = list.next_page
|
next_list = list.next_page
|
||||||
assert_equal({ :expand => ['data.source'], :limit => 3 }, next_list.filters)
|
assert_equal({ :expand => ['data.source'], :limit => 3 }, next_list.filters)
|
||||||
end
|
end
|
||||||
@ -128,8 +125,9 @@ module Stripe
|
|||||||
:data => [{ :id => 2 }],
|
:data => [{ :id => 2 }],
|
||||||
:url => "/things",
|
:url => "/things",
|
||||||
})
|
})
|
||||||
@mock.expects(:get).once.with("#{Stripe.api_base}/things?ending_before=2", nil, nil).
|
stub_request(:get, "#{Stripe.api_base}/things").
|
||||||
returns(make_response({ :data => [{ :id => 1 }] }))
|
with(query: { ending_before: "2" }).
|
||||||
|
to_return(body: make_response({ :data => [{ :id => 1 }] }))
|
||||||
next_list = list.previous_page
|
next_list = list.previous_page
|
||||||
refute next_list.empty?
|
refute next_list.empty?
|
||||||
end
|
end
|
||||||
@ -140,17 +138,9 @@ module Stripe
|
|||||||
:url => "/things",
|
:url => "/things",
|
||||||
})
|
})
|
||||||
list.filters = { :expand => ['data.source'], :limit => 3 }
|
list.filters = { :expand => ['data.source'], :limit => 3 }
|
||||||
@mock.expects(:get).with do |url, _, _|
|
stub_request(:get, "#{Stripe.api_base}/things").
|
||||||
# apparently URI.parse in 1.8.7 doesn't support query parameters ...
|
with(query: { "expand[]" => "data.source", "limit" => "3", "ending_before" => "2" }).
|
||||||
url, query = url.split("?")
|
to_return(body: make_response({ :data => [{ :id => 1 }] }))
|
||||||
u = URI.parse(url)
|
|
||||||
params = CGI.parse(query)
|
|
||||||
u.host == URI.parse(Stripe.api_base).host && u.path == "/things" && params == {
|
|
||||||
"ending_before" => ["2"],
|
|
||||||
"expand[]" => ["data.source"],
|
|
||||||
"limit" => ["3"],
|
|
||||||
}
|
|
||||||
end.returns(make_response({ :data => [{ :id => 1 }] }))
|
|
||||||
next_list = list.previous_page
|
next_list = list.previous_page
|
||||||
assert_equal({ :expand => ['data.source'], :limit => 3 }, next_list.filters)
|
assert_equal({ :expand => ['data.source'], :limit => 3 }, next_list.filters)
|
||||||
end
|
end
|
||||||
@ -162,7 +152,8 @@ module Stripe
|
|||||||
# note that the name #all is deprecated, as is using it fetch the next page
|
# note that the name #all is deprecated, as is using it fetch the next page
|
||||||
# in a list
|
# in a list
|
||||||
should "be able to retrieve full lists given a listobject" do
|
should "be able to retrieve full lists given a listobject" do
|
||||||
@mock.expects(:get).twice.returns(make_response(make_charge_array))
|
stub_request(:get, "#{Stripe.api_base}/v1/charges").
|
||||||
|
to_return(body: make_response(make_charge_array))
|
||||||
c = Stripe::Charge.all
|
c = Stripe::Charge.all
|
||||||
assert c.kind_of?(Stripe::ListObject)
|
assert c.kind_of?(Stripe::ListObject)
|
||||||
assert_equal('/v1/charges', c.resource_url)
|
assert_equal('/v1/charges', c.resource_url)
|
||||||
|
@ -1,129 +0,0 @@
|
|||||||
require File.expand_path('../../test_helper', __FILE__)
|
|
||||||
|
|
||||||
module Stripe
|
|
||||||
class MetadataTest < Test::Unit::TestCase
|
|
||||||
setup do
|
|
||||||
@metadata_supported = {
|
|
||||||
:charge => {
|
|
||||||
:new => Stripe::Charge.method(:new),
|
|
||||||
:test => method(:make_charge),
|
|
||||||
:url => "/v1/charges/#{make_charge()[:id]}"
|
|
||||||
},
|
|
||||||
:customer => {
|
|
||||||
:new => Stripe::Customer.method(:new),
|
|
||||||
:test => method(:make_customer),
|
|
||||||
:url => "/v1/customers/#{make_customer()[:id]}"
|
|
||||||
},
|
|
||||||
:recipient => {
|
|
||||||
:new => Stripe::Recipient.method(:new),
|
|
||||||
:test => method(:make_recipient),
|
|
||||||
:url => "/v1/recipients/#{make_recipient()[:id]}"
|
|
||||||
},
|
|
||||||
:transfer => {
|
|
||||||
:new => Stripe::Transfer.method(:new),
|
|
||||||
:test => method(:make_transfer),
|
|
||||||
:url => "/v1/transfers/#{make_transfer()[:id]}"
|
|
||||||
},
|
|
||||||
:product => {
|
|
||||||
:new => Stripe::Product.method(:new),
|
|
||||||
:test => method(:make_product),
|
|
||||||
:url => "/v1/products/#{make_product()[:id]}"
|
|
||||||
},
|
|
||||||
:order => {
|
|
||||||
:new => Stripe::Order.method(:new),
|
|
||||||
:test => method(:make_order),
|
|
||||||
:url => "/v1/orders/#{make_order()[:id]}"
|
|
||||||
},
|
|
||||||
:sku => {
|
|
||||||
:new => Stripe::SKU.method(:new),
|
|
||||||
:test => method(:make_sku),
|
|
||||||
:url => "/v1/skus/#{make_sku()[:id]}"
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
@base_url = 'https://api.stripe.com'
|
|
||||||
end
|
|
||||||
|
|
||||||
should "not touch metadata" do
|
|
||||||
update_actions = lambda {|obj| obj.description = 'test'}
|
|
||||||
check_metadata({:metadata => {'initial' => 'true'}},
|
|
||||||
'description=test',
|
|
||||||
update_actions)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
should "update metadata as a whole" do
|
|
||||||
update_actions = lambda {|obj| obj.metadata = {'uuid' => '6735'}}
|
|
||||||
check_metadata({:metadata => {}},
|
|
||||||
'metadata[uuid]=6735',
|
|
||||||
update_actions)
|
|
||||||
|
|
||||||
if is_greater_than_ruby_1_9?
|
|
||||||
check_metadata({:metadata => {:initial => 'true'}},
|
|
||||||
'metadata[initial]=&metadata[uuid]=6735',
|
|
||||||
update_actions)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
should "update metadata keys individually" do
|
|
||||||
update_actions = lambda {|obj| obj.metadata['txn_id'] = '134a13'}
|
|
||||||
check_metadata({:metadata => {'initial' => 'true'}},
|
|
||||||
'metadata[txn_id]=134a13',
|
|
||||||
update_actions)
|
|
||||||
end
|
|
||||||
|
|
||||||
should "clear metadata as a whole" do
|
|
||||||
update_actions = lambda {|obj| obj.metadata = nil}
|
|
||||||
check_metadata({:metadata => {'initial' => 'true'}},
|
|
||||||
'metadata=',
|
|
||||||
update_actions)
|
|
||||||
end
|
|
||||||
|
|
||||||
should "clear metadata keys individually" do
|
|
||||||
update_actions = lambda {|obj| obj.metadata['initial'] = nil}
|
|
||||||
check_metadata({:metadata => {'initial' => 'true'}},
|
|
||||||
'metadata[initial]=',
|
|
||||||
update_actions)
|
|
||||||
end
|
|
||||||
|
|
||||||
should "handle combinations of whole and partial metadata updates" do
|
|
||||||
if is_greater_than_ruby_1_9?
|
|
||||||
update_actions = lambda do |obj|
|
|
||||||
obj.metadata = {'type' => 'summer'}
|
|
||||||
obj.metadata['uuid'] = '6735'
|
|
||||||
end
|
|
||||||
params = {:metadata => {'type' => 'summer', 'uuid' => '6735'}}
|
|
||||||
curl_args = Stripe::Util.encode_parameters(params)
|
|
||||||
check_metadata({:metadata => {'type' => 'christmas'}},
|
|
||||||
curl_args,
|
|
||||||
update_actions)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def check_metadata (initial_params, curl_args, metadata_update)
|
|
||||||
@metadata_supported.each do |name, methods|
|
|
||||||
neu = methods[:new]
|
|
||||||
test = methods[:test]
|
|
||||||
url = @base_url + methods[:url]
|
|
||||||
|
|
||||||
initial_test_obj = test.call(initial_params)
|
|
||||||
@mock.expects(:get).once.returns(make_response(initial_test_obj))
|
|
||||||
|
|
||||||
final_test_obj = test.call()
|
|
||||||
@mock.expects(:post).once.
|
|
||||||
returns(make_response(final_test_obj)).
|
|
||||||
with(url, nil, curl_args)
|
|
||||||
|
|
||||||
obj = neu.call("test")
|
|
||||||
obj.refresh()
|
|
||||||
metadata_update.call(obj)
|
|
||||||
obj.save
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def is_greater_than_ruby_1_9?
|
|
||||||
version = RUBY_VERSION.dup # clone preserves frozen state
|
|
||||||
Gem::Version.new(version) >= Gem::Version.new('1.9')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
@ -3,7 +3,8 @@ require File.expand_path('../../test_helper', __FILE__)
|
|||||||
module Stripe
|
module Stripe
|
||||||
class OrderReturnTest < Test::Unit::TestCase
|
class OrderReturnTest < Test::Unit::TestCase
|
||||||
should "returns should be listable" do
|
should "returns should be listable" do
|
||||||
@mock.expects(:get).once.returns(make_response(make_order_return_array))
|
stub_request(:get, "#{Stripe.api_base}/v1/order_returns").
|
||||||
|
to_return(body: make_response(make_order_return_array))
|
||||||
returns = Stripe::OrderReturn.list
|
returns = Stripe::OrderReturn.list
|
||||||
assert returns.data.kind_of?(Array)
|
assert returns.data.kind_of?(Array)
|
||||||
returns.each do |ret|
|
returns.each do |ret|
|
||||||
|
@ -3,7 +3,8 @@ require File.expand_path('../../test_helper', __FILE__)
|
|||||||
module Stripe
|
module Stripe
|
||||||
class OrderTest < Test::Unit::TestCase
|
class OrderTest < Test::Unit::TestCase
|
||||||
should "orders should be listable" do
|
should "orders should be listable" do
|
||||||
@mock.expects(:get).once.returns(make_response(make_order_array))
|
stub_request(:get, "#{Stripe.api_base}/v1/orders").
|
||||||
|
to_return(body: make_response(make_order_array))
|
||||||
orders = Stripe::Order.list
|
orders = Stripe::Order.list
|
||||||
assert orders.data.kind_of?(Array)
|
assert orders.data.kind_of?(Array)
|
||||||
orders.each do |order|
|
orders.each do |order|
|
||||||
@ -12,61 +13,54 @@ module Stripe
|
|||||||
end
|
end
|
||||||
|
|
||||||
should "orders should not be deletable" do
|
should "orders should not be deletable" do
|
||||||
|
stub_request(:get, "#{Stripe.api_base}/v1/orders/or_test_order").
|
||||||
|
to_return(body: make_response(make_order))
|
||||||
|
p = Stripe::Order.retrieve("or_test_order")
|
||||||
|
|
||||||
assert_raises NoMethodError do
|
assert_raises NoMethodError do
|
||||||
@mock.expects(:get).once.returns(make_response(make_order))
|
|
||||||
p = Stripe::Order.retrieve("test_order")
|
|
||||||
p.delete
|
p.delete
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
should "orders should be saveable" do
|
should "orders should be saveable" do
|
||||||
@mock.expects(:get).once.returns(make_response(make_order))
|
stub_request(:get, "#{Stripe.api_base}/v1/orders/or_test_order").
|
||||||
@mock.expects(:post).once.returns(make_response(make_order))
|
to_return(body: make_response(make_order))
|
||||||
p = Stripe::Order.new("test_order")
|
p = Stripe::Order.retrieve("or_test_order")
|
||||||
p.refresh
|
|
||||||
|
stub_request(:post, "#{Stripe.api_base}/v1/orders/#{p.id}").
|
||||||
|
with(body: { status: "fulfilled" }).
|
||||||
|
to_return(body: make_response(make_order))
|
||||||
p.status = "fulfilled"
|
p.status = "fulfilled"
|
||||||
p.save
|
p.save
|
||||||
end
|
end
|
||||||
|
|
||||||
should "orders should be updateable" do
|
should "orders should be updateable" do
|
||||||
@mock.expects(:post).once.
|
stub_request(:post, "#{Stripe.api_base}/v1/orders/or_test_order").
|
||||||
with('https://api.stripe.com/v1/orders/test_order', nil, 'status=fulfilled').
|
with(body: { status: "fulfilled" }).
|
||||||
returns(make_response(make_order(status: 'fulfilled')))
|
to_return(body: make_response(make_order))
|
||||||
ii = Stripe::Order.update("test_order", status: 'fulfilled')
|
_ = Stripe::Order.update("or_test_order", status: 'fulfilled')
|
||||||
assert_equal('fulfilled', ii.status)
|
|
||||||
end
|
|
||||||
|
|
||||||
should "orders should allow metadata updates" do
|
|
||||||
@mock.expects(:get).once.returns(make_response(make_order))
|
|
||||||
@mock.expects(:post).once.returns(make_response(make_order))
|
|
||||||
p = Stripe::Order.new("test_order")
|
|
||||||
p.refresh
|
|
||||||
p.metadata['key'] = 'value'
|
|
||||||
p.save
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "pay should pay an order" do
|
should "pay should pay an order" do
|
||||||
@mock.expects(:get).once.
|
stub_request(:get, "#{Stripe.api_base}/v1/orders/or_test_order").
|
||||||
returns(make_response(make_order(:id => 'or_test_order')))
|
to_return(body: make_response(make_order))
|
||||||
order = Stripe::Order.retrieve('or_test_order')
|
order = Stripe::Order.retrieve('or_test_order')
|
||||||
|
|
||||||
@mock.expects(:post).once.
|
stub_request(:post, "#{Stripe.api_base}/v1/orders/#{order.id}/pay").
|
||||||
with('https://api.stripe.com/v1/orders/or_test_order/pay', nil, 'token=test_token').
|
with(body: { token: "test_token" }).
|
||||||
returns(make_response(make_paid_order))
|
to_return(body: make_response(make_order))
|
||||||
order.pay(:token => 'test_token')
|
order.pay(:token => 'test_token')
|
||||||
assert_equal "paid", order.status
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "return an order" do
|
should "return an order" do
|
||||||
@mock.expects(:get).once.
|
stub_request(:get, "#{Stripe.api_base}/v1/orders/or_test_order").
|
||||||
returns(make_response(make_order(:id => 'or_test_order')))
|
to_return(body: make_response(make_order))
|
||||||
order = Stripe::Order.retrieve('or_test_order')
|
order = Stripe::Order.retrieve('or_test_order')
|
||||||
|
|
||||||
@mock.expects(:post).once.
|
stub_request(:post, "#{Stripe.api_base}/v1/orders/#{order.id}/returns").
|
||||||
with('https://api.stripe.com/v1/orders/or_test_order/returns', nil, 'items[][parent]=sku_foo').
|
with(body: { items: [{ parent: "sku_foo" }] }).
|
||||||
returns(make_response(make_order_return({:order => order.id})))
|
to_return(body: make_response(make_order))
|
||||||
order_return = order.return_order(:items => [{:parent => 'sku_foo'}])
|
_ = order.return_order(:items => [{:parent => 'sku_foo'}])
|
||||||
assert_equal order.id, order_return.order
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -3,7 +3,8 @@ require File.expand_path('../../test_helper', __FILE__)
|
|||||||
module Stripe
|
module Stripe
|
||||||
class PlanTest < Test::Unit::TestCase
|
class PlanTest < Test::Unit::TestCase
|
||||||
should "plans should be listable" do
|
should "plans should be listable" do
|
||||||
@mock.expects(:get).once.returns(make_response(make_plan_array))
|
stub_request(:get, "#{Stripe.api_base}/v1/plans").
|
||||||
|
to_return(body: make_response(make_plan_array))
|
||||||
plans = Stripe::Plan.list
|
plans = Stripe::Plan.list
|
||||||
assert plans.data.kind_of?(Array)
|
assert plans.data.kind_of?(Array)
|
||||||
plans.each do |plan|
|
plans.each do |plan|
|
||||||
@ -12,20 +13,22 @@ module Stripe
|
|||||||
end
|
end
|
||||||
|
|
||||||
should "plans should be saveable" do
|
should "plans should be saveable" do
|
||||||
@mock.expects(:get).once.returns(make_response(make_plan))
|
stub_request(:get, "#{Stripe.api_base}/v1/plans/test_plan").
|
||||||
@mock.expects(:post).once.returns(make_response(make_plan))
|
to_return(body: make_response(make_plan))
|
||||||
p = Stripe::Plan.new("test_plan")
|
p = Stripe::Plan.retrieve("test_plan")
|
||||||
p.refresh
|
|
||||||
|
stub_request(:post, "#{Stripe.api_base}/v1/plans/#{p.id}").
|
||||||
|
with(body: { metadata: { foo: "bar" } }).
|
||||||
|
to_return(body: make_response(make_plan))
|
||||||
p.metadata['foo'] = 'bar'
|
p.metadata['foo'] = 'bar'
|
||||||
p.save
|
p.save
|
||||||
end
|
end
|
||||||
|
|
||||||
should "plans should be updateable" do
|
should "plans should be updateable" do
|
||||||
@mock.expects(:post).once.
|
stub_request(:post, "#{Stripe.api_base}/v1/plans/test_plan").
|
||||||
with('https://api.stripe.com/v1/plans/test_plan', nil, 'metadata[foo]=bar').
|
with(body: { metadata: { foo: "bar" } }).
|
||||||
returns(make_response(make_plan(metadata: {foo: 'bar'})))
|
to_return(body: make_response(make_plan))
|
||||||
p = Stripe::Plan.update("test_plan", metadata: {foo: 'bar'})
|
_ = Stripe::Plan.update("test_plan", metadata: {foo: 'bar'})
|
||||||
assert_equal('bar', p.metadata['foo'])
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -3,7 +3,8 @@ require File.expand_path('../../test_helper', __FILE__)
|
|||||||
module Stripe
|
module Stripe
|
||||||
class ProductTest < Test::Unit::TestCase
|
class ProductTest < Test::Unit::TestCase
|
||||||
should "products should be listable" do
|
should "products should be listable" do
|
||||||
@mock.expects(:get).once.returns(make_response(make_product_array))
|
stub_request(:get, "#{Stripe.api_base}/v1/products").
|
||||||
|
to_return(body: make_response(make_product_array))
|
||||||
products = Stripe::Product.list
|
products = Stripe::Product.list
|
||||||
assert products.data.kind_of?(Array)
|
assert products.data.kind_of?(Array)
|
||||||
products.each do |product|
|
products.each do |product|
|
||||||
@ -12,40 +13,33 @@ module Stripe
|
|||||||
end
|
end
|
||||||
|
|
||||||
should "products should be deletable" do
|
should "products should be deletable" do
|
||||||
@mock.expects(:get).once.returns(make_response(make_product))
|
stub_request(:get, "#{Stripe.api_base}/v1/products/test_product").
|
||||||
@mock.expects(:delete).once.
|
to_return(body: make_response(make_product))
|
||||||
returns(make_response(make_product(:deleted => true)))
|
|
||||||
|
|
||||||
p = Stripe::Product.retrieve("test_product")
|
p = Stripe::Product.retrieve("test_product")
|
||||||
|
|
||||||
|
stub_request(:delete, "#{Stripe.api_base}/v1/products/#{p.id}").
|
||||||
|
to_return(body: make_response(make_product))
|
||||||
p.delete
|
p.delete
|
||||||
assert p.deleted
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "products should be saveable" do
|
should "products should be saveable" do
|
||||||
@mock.expects(:get).once.returns(make_response(make_product))
|
stub_request(:get, "#{Stripe.api_base}/v1/products/test_product").
|
||||||
@mock.expects(:post).once.returns(make_response(make_product))
|
to_return(body: make_response(make_product))
|
||||||
p = Stripe::Product.new("test_product")
|
p = Stripe::Product.new("test_product")
|
||||||
p.refresh
|
p.refresh
|
||||||
p.description = "New product description"
|
|
||||||
|
stub_request(:post, "#{Stripe.api_base}/v1/products/#{p.id}").
|
||||||
|
with(body: { :description => "update" }).
|
||||||
|
to_return(body: make_response(make_product))
|
||||||
|
p.description = "update"
|
||||||
p.save
|
p.save
|
||||||
end
|
end
|
||||||
|
|
||||||
should "products should be updateable" do
|
should "products should be updateable" do
|
||||||
@mock.expects(:post).once.
|
stub_request(:post, "#{Stripe.api_base}/v1/products/test_product").
|
||||||
with('https://api.stripe.com/v1/products/test_product', nil, 'description=update').
|
with(body: { :description => "update" }).
|
||||||
returns(make_response(make_product(description: 'update')))
|
to_return(body: make_response(make_product))
|
||||||
p = Stripe::Product.update("test_product", description: 'update')
|
_ = Stripe::Product.update("test_product", description: "update")
|
||||||
assert_equal('update', p.description)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "products should allow metadata updates" do
|
|
||||||
@mock.expects(:get).once.returns(make_response(make_product))
|
|
||||||
@mock.expects(:post).once.returns(make_response(make_product))
|
|
||||||
p = Stripe::Product.new("test_product")
|
|
||||||
p.refresh
|
|
||||||
p.metadata['key'] = 'value'
|
|
||||||
p.save
|
|
||||||
end
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -378,18 +378,6 @@ module Stripe
|
|||||||
}.merge(params)
|
}.merge(params)
|
||||||
end
|
end
|
||||||
|
|
||||||
def make_paid_invoice
|
|
||||||
make_invoice.merge({
|
|
||||||
:attempt_count => 1,
|
|
||||||
:attempted => true,
|
|
||||||
:closed => true,
|
|
||||||
:paid => true,
|
|
||||||
:charge => 'ch_test_charge',
|
|
||||||
:ending_balance => 0,
|
|
||||||
:next_payment_attempt => nil,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
def make_invoice_item(params={})
|
def make_invoice_item(params={})
|
||||||
{
|
{
|
||||||
id: "ii_test_invoice_item",
|
id: "ii_test_invoice_item",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user