mirror of
https://github.com/stripe/stripe-ruby.git
synced 2025-08-19 00:01:04 -04:00
More tests converted
This commit is contained in:
parent
0019cfdc7e
commit
d1d5b9d39d
@ -5,21 +5,17 @@ module Stripe
|
||||
TEST_ID = "btctxn_test_transaction".freeze
|
||||
|
||||
should "retrieve should retrieve bitcoin receiver" do
|
||||
@mock.expects(:get).
|
||||
with("#{Stripe.api_base}/v1/bitcoin/transactions/#{TEST_ID}", nil, nil).
|
||||
once.
|
||||
returns(make_response(make_bitcoin_transaction))
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/bitcoin/transactions/#{TEST_ID}").
|
||||
to_return(body: make_response(make_bitcoin_transaction))
|
||||
receiver = Stripe::BitcoinTransaction.retrieve(TEST_ID)
|
||||
assert_equal TEST_ID, receiver.id
|
||||
end
|
||||
|
||||
should "all should list bitcoin transactions" do
|
||||
@mock.expects(:get).
|
||||
with("#{Stripe.api_base}/v1/bitcoin/transactions", nil, nil).
|
||||
once.
|
||||
returns(make_response(make_bitcoin_transaction_array))
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/bitcoin/transactions").
|
||||
to_return(body: make_response(make_bitcoin_transaction_array))
|
||||
transactions = Stripe::BitcoinTransaction.list
|
||||
assert_equal 3, transactions.data.length
|
||||
|
||||
assert transactions.data.kind_of? Array
|
||||
transactions.each do |transaction|
|
||||
assert transaction.kind_of?(Stripe::BitcoinTransaction)
|
||||
|
@ -3,41 +3,19 @@ require File.expand_path('../../test_helper', __FILE__)
|
||||
module Stripe
|
||||
class CountrySpecTest < Test::Unit::TestCase
|
||||
should "be listable" do
|
||||
@mock.expects(:get).once.
|
||||
returns(make_response(country_spec_array))
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/country_specs").
|
||||
to_return(body: make_response(make_country_spec_array))
|
||||
c = Stripe::CountrySpec.list
|
||||
|
||||
assert_equal('/v1/country_specs', c.resource_url)
|
||||
assert_equal('list', c.object)
|
||||
assert(c.data.kind_of?(Array))
|
||||
assert_equal('US', c.data[0].id)
|
||||
assert(c.data[0].kind_of?(Stripe::CountrySpec))
|
||||
end
|
||||
|
||||
should "be retrievable" do
|
||||
resp = make_country_spec
|
||||
@mock.expects(:get).once.
|
||||
with('https://api.stripe.com/v1/country_specs/US', nil, nil).
|
||||
returns(make_response(resp))
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/country_specs/US").
|
||||
to_return(body: make_response(make_country_spec))
|
||||
s = Stripe::CountrySpec.retrieve('US')
|
||||
|
||||
assert_equal('/v1/country_specs/US', s.resource_url)
|
||||
assert_equal('country_spec', s.object)
|
||||
assert(s.kind_of?(Stripe::CountrySpec))
|
||||
|
||||
s.supported_bank_account_currencies.map{ |k,v| assert v.kind_of?(Array) }
|
||||
assert_equal(['US'], s.supported_bank_account_currencies['usd'])
|
||||
assert(s.supported_payment_currencies.include?('usd'))
|
||||
assert s.supported_payment_currencies.kind_of?(Array)
|
||||
assert s.supported_payment_methods.kind_of?(Array)
|
||||
|
||||
['individual', 'company'].map{ |type|
|
||||
item = s.verification_fields[type]
|
||||
assert item.minimum.include?('external_account')
|
||||
assert item.additional.include?('legal_entity.verification.document')
|
||||
assert item.additional.kind_of?(Array)
|
||||
assert item.minimum.kind_of?(Array)
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -3,26 +3,28 @@ require File.expand_path('../../test_helper', __FILE__)
|
||||
module Stripe
|
||||
class CouponTest < Test::Unit::TestCase
|
||||
should "create should return a new coupon" do
|
||||
@mock.expects(:post).once.returns(make_response(make_coupon))
|
||||
c = Stripe::Coupon.create
|
||||
assert_equal "co_test_coupon", c.id
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/coupons").
|
||||
to_return(body: make_response(make_coupon))
|
||||
_ = Stripe::Coupon.create
|
||||
end
|
||||
|
||||
should "coupons should be saveable" do
|
||||
@mock.expects(:get).once.returns(make_response(make_coupon))
|
||||
@mock.expects(:post).once.returns(make_response(make_coupon))
|
||||
c = Stripe::Coupon.new("test_coupon")
|
||||
c.refresh
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/coupons/test_coupon").
|
||||
to_return(body: make_response(make_coupon))
|
||||
c = Stripe::Coupon.retrieve("test_coupon")
|
||||
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/coupons/#{c.id}").
|
||||
with(body: { metadata: { foo: "bar" } }).
|
||||
to_return(body: make_response(make_customer))
|
||||
c.metadata['foo'] = 'bar'
|
||||
c.save
|
||||
end
|
||||
|
||||
should "coupons should be updateable" do
|
||||
@mock.expects(:post).once.
|
||||
with("https://api.stripe.com/v1/coupons/test_coupon", nil, "metadata[foo]=bar").
|
||||
returns(make_response(make_coupon(metadata: {foo: 'bar'})))
|
||||
c = Stripe::Coupon.update("test_coupon", metadata: {foo: 'bar'})
|
||||
assert_equal('bar', c.metadata['foo'])
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/coupons/test_coupon").
|
||||
with(body: { metadata: { foo: "bar" } }).
|
||||
to_return(body: make_response(make_customer))
|
||||
_ = Stripe::Coupon.update("test_coupon", metadata: {foo: 'bar'})
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -2,56 +2,56 @@ require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
module Stripe
|
||||
class CustomerCardTest < Test::Unit::TestCase
|
||||
CUSTOMER_CARD_URL = '/v1/customers/test_customer/sources/test_card'
|
||||
|
||||
def customer
|
||||
@mock.expects(:get).once.returns(make_response(make_customer))
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/customers/test_customer").
|
||||
to_return(body: make_response(make_customer))
|
||||
Stripe::Customer.retrieve('test_customer')
|
||||
end
|
||||
|
||||
should "customer cards should be listable" do
|
||||
c = customer
|
||||
@mock.expects(:get).once.returns(make_response(make_customer_card_array(customer.id)))
|
||||
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/customers/#{c.id}/sources").
|
||||
with(query: { object: "card" }).
|
||||
to_return(body: make_response(make_customer_card_array(customer.id)))
|
||||
cards = c.sources.list(:object => "card").data
|
||||
assert cards.kind_of? Array
|
||||
assert cards[0].kind_of? Stripe::Card
|
||||
end
|
||||
|
||||
should "customer cards should have the correct resource url" do
|
||||
c = customer
|
||||
@mock.expects(:get).once.returns(make_response(make_card(
|
||||
:id => 'test_card',
|
||||
:customer => 'test_customer'
|
||||
)))
|
||||
card = c.sources.retrieve('card')
|
||||
assert_equal CUSTOMER_CARD_URL, card.resource_url
|
||||
end
|
||||
|
||||
should "customer cards should be deletable" do
|
||||
c = customer
|
||||
@mock.expects(:get).once.returns(make_response(make_card))
|
||||
@mock.expects(:delete).once.returns(make_response(make_card(:deleted => true)))
|
||||
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/customers/#{c.id}/sources/card").
|
||||
to_return(body: make_response(make_card))
|
||||
card = c.sources.retrieve('card')
|
||||
card.delete
|
||||
assert card.deleted
|
||||
|
||||
stub_request(:delete, "#{Stripe.api_base}/v1/customers/#{card.customer}/sources/#{card.id}").
|
||||
to_return(body: make_response(make_card(:deleted => true)))
|
||||
_ = card.delete
|
||||
end
|
||||
|
||||
should "customer cards should be updateable" do
|
||||
c = customer
|
||||
@mock.expects(:get).once.returns(make_response(make_card(:exp_year => "2000")))
|
||||
@mock.expects(:post).once.returns(make_response(make_card(:exp_year => "2100")))
|
||||
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/customers/#{c.id}/sources/card").
|
||||
to_return(body: make_response(make_card))
|
||||
card = c.sources.retrieve('card')
|
||||
assert_equal "2000", card.exp_year
|
||||
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/customers/#{card.customer}/sources/#{card.id}").
|
||||
with(body: { exp_year: "2100" }).
|
||||
to_return(body: make_response(make_card))
|
||||
card.exp_year = "2100"
|
||||
card.save
|
||||
assert_equal "2100", card.exp_year
|
||||
end
|
||||
|
||||
should "create should return a new customer card" do
|
||||
c = customer
|
||||
@mock.expects(:post).once.returns(make_response(make_card(:id => "test_card")))
|
||||
card = c.sources.create(:source => "tok_41YJ05ijAaWaFS")
|
||||
assert_equal "test_card", card.id
|
||||
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/customers/#{c.id}/sources").
|
||||
with(body: { source: "tok_41YJ05ijAaWaFS" }).
|
||||
to_return(body: make_response(make_card))
|
||||
_ = c.sources.create(:source => "tok_41YJ05ijAaWaFS")
|
||||
end
|
||||
|
||||
should "raise if accessing Stripe::Card.retrieve directly" do
|
||||
|
@ -3,94 +3,97 @@ require File.expand_path('../../test_helper', __FILE__)
|
||||
module Stripe
|
||||
class CustomerTest < Test::Unit::TestCase
|
||||
should "customers should be listable" do
|
||||
@mock.expects(:get).once.returns(make_response(make_customer_array))
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/customers").
|
||||
to_return(body: make_response(make_customer_array))
|
||||
c = Stripe::Customer.list.data
|
||||
assert c.kind_of? Array
|
||||
assert c[0].kind_of? Stripe::Customer
|
||||
end
|
||||
|
||||
should "customers should be deletable" do
|
||||
@mock.expects(:delete).once.returns(make_response(make_customer({:deleted => true})))
|
||||
stub_request(:delete, "#{Stripe.api_base}/v1/customers/test_customer").
|
||||
to_return(body: make_response(make_customer))
|
||||
c = Stripe::Customer.new("test_customer")
|
||||
c.delete
|
||||
assert c.deleted
|
||||
end
|
||||
|
||||
should "customers should be saveable" do
|
||||
@mock.expects(:get).once.returns(make_response(make_customer({:mnemonic => "foo"})))
|
||||
@mock.expects(:post).once.returns(make_response(make_customer({:mnemonic => "bar"})))
|
||||
c = Stripe::Customer.new("test_customer").refresh
|
||||
assert_equal "foo", c.mnemonic
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/customers/test_customer").
|
||||
to_return(body: make_response(make_customer))
|
||||
c = Stripe::Customer.retrieve("test_customer")
|
||||
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/customers/#{c.id}").
|
||||
with(body: { mnemonic: "bar" }).
|
||||
to_return(body: make_response(make_customer))
|
||||
c.mnemonic = "bar"
|
||||
c.save
|
||||
assert_equal "bar", c.mnemonic
|
||||
end
|
||||
|
||||
should "customers should be updateable" do
|
||||
@mock.expects(:post).once.
|
||||
with("https://api.stripe.com/v1/customers/test_customer", nil, "metadata[foo]=bar").
|
||||
returns(make_response(make_customer(metadata: {foo: 'bar'})))
|
||||
c = Stripe::Customer.update("test_customer", metadata: {foo: 'bar'})
|
||||
assert_equal('bar', c.metadata['foo'])
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/customers/test_customer").
|
||||
with(body: { mnemonic: "bar" }).
|
||||
to_return(body: make_response(make_customer))
|
||||
_ = Stripe::Customer.update("test_customer", mnemonic: "bar")
|
||||
end
|
||||
|
||||
should "create should return a new customer" do
|
||||
@mock.expects(:post).once.returns(make_response(make_customer))
|
||||
c = Stripe::Customer.create
|
||||
assert_equal "c_test_customer", c.id
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/customers").
|
||||
to_return(body: make_response(make_customer))
|
||||
_ = Stripe::Customer.create
|
||||
end
|
||||
|
||||
should "create_upcoming_invoice should create a new invoice" do
|
||||
@mock.expects(:post).once.returns(make_response(make_invoice))
|
||||
i = Stripe::Customer.new("test_customer").create_upcoming_invoice
|
||||
assert_equal "c_test_customer", i.customer
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/invoices").
|
||||
with(body: { customer: "test_customer" }).
|
||||
to_return(body: make_response(make_customer))
|
||||
_ = Stripe::Customer.new("test_customer").create_upcoming_invoice
|
||||
end
|
||||
|
||||
should "be able to update a customer's subscription" do
|
||||
@mock.expects(:get).once.returns(make_response(make_customer))
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/customers/test_customer").
|
||||
to_return(body: make_response(make_customer))
|
||||
c = Stripe::Customer.retrieve("test_customer")
|
||||
|
||||
@mock.expects(:post).once.with do |url, api_key, params|
|
||||
url == "#{Stripe.api_base}/v1/customers/c_test_customer/subscription" && api_key.nil? && CGI.parse(params) == {'plan' => ['silver']}
|
||||
end.returns(make_response(make_subscription(:plan => 'silver')))
|
||||
s = c.update_subscription({:plan => 'silver'})
|
||||
|
||||
assert_equal 'subscription', s.object
|
||||
assert_equal 'silver', s.plan.identifier
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/customers/#{c.id}/subscription").
|
||||
with(body: { plan: "silver" }).
|
||||
to_return(body: make_response(make_subscription))
|
||||
_ = c.update_subscription({:plan => 'silver'})
|
||||
end
|
||||
|
||||
should "be able to cancel a customer's subscription" do
|
||||
@mock.expects(:get).once.returns(make_response(make_customer))
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/customers/test_customer").
|
||||
to_return(body: make_response(make_customer))
|
||||
c = Stripe::Customer.retrieve("test_customer")
|
||||
|
||||
# Not an accurate response, but whatever
|
||||
|
||||
@mock.expects(:delete).once.with("#{Stripe.api_base}/v1/customers/c_test_customer/subscription?at_period_end=true", nil, nil).returns(make_response(make_subscription(:plan => 'silver')))
|
||||
stub_request(:delete, "#{Stripe.api_base}/v1/customers/#{c.id}/subscription").
|
||||
with(query: { at_period_end: "true" }).
|
||||
to_return(body: make_response(make_subscription))
|
||||
c.cancel_subscription({:at_period_end => 'true'})
|
||||
|
||||
@mock.expects(:delete).once.with("#{Stripe.api_base}/v1/customers/c_test_customer/subscription", nil, nil).returns(make_response(make_subscription(:plan => 'silver')))
|
||||
stub_request(:delete, "#{Stripe.api_base}/v1/customers/#{c.id}/subscription").
|
||||
to_return(body: make_response(make_subscription))
|
||||
c.cancel_subscription
|
||||
end
|
||||
|
||||
should "be able to create a subscription for a customer" do
|
||||
c = Stripe::Customer.new("test_customer")
|
||||
|
||||
@mock.expects(:post).once.with do |url, api_key, params|
|
||||
url == "#{Stripe.api_base}/v1/customers/test_customer/subscriptions" && api_key.nil? && CGI.parse(params) == {'plan' => ['silver']}
|
||||
end.returns(make_response(make_subscription(:plan => 'silver')))
|
||||
s = c.create_subscription({:plan => 'silver'})
|
||||
|
||||
assert_equal 'subscription', s.object
|
||||
assert_equal 'silver', s.plan.identifier
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/customers/#{c.id}/subscriptions").
|
||||
with(body: { plan: "silver" }).
|
||||
to_return(body: make_response(make_subscription))
|
||||
_ = c.create_subscription({:plan => 'silver'})
|
||||
end
|
||||
|
||||
should "be able to delete a customer's discount" do
|
||||
@mock.expects(:get).once.returns(make_response(make_customer))
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/customers/test_customer").
|
||||
to_return(body: make_response(make_customer))
|
||||
c = Stripe::Customer.retrieve("test_customer")
|
||||
|
||||
@mock.expects(:delete).once.with("#{Stripe.api_base}/v1/customers/c_test_customer/discount", nil, nil).returns(make_response(make_delete_discount_response))
|
||||
stub_request(:delete, "#{Stripe.api_base}/v1/customers/#{c.id}/discount").
|
||||
to_return(body: make_response(make_delete_discount_response))
|
||||
c.delete_discount
|
||||
assert_equal nil, c.discount
|
||||
end
|
||||
|
||||
should "can have a token source set" do
|
||||
|
@ -750,7 +750,7 @@ module Stripe
|
||||
}
|
||||
end
|
||||
|
||||
def country_spec_array
|
||||
def make_country_spec_array
|
||||
{
|
||||
:object => "list",
|
||||
:resource_url => "/v1/country_specs",
|
||||
|
Loading…
x
Reference in New Issue
Block a user