mirror of
https://github.com/stripe/stripe-ruby.git
synced 2025-11-12 00:03:12 -05:00
Port all tests over to OpenAPI
Follows the path established in 2d75c8f by porting the rest of stripe-ruby's tests over to OpenAPI. There are a few other changes here where I've removed some tests that are duplicated or don't make much sense, or reorganized how we test certain things, but this commit is largely the same migration operation applied in bulk a few dozen test suites.
This commit is contained in:
parent
5f4eff7e35
commit
3f549fb5ad
@ -10,7 +10,7 @@ module Stripe
|
|||||||
end
|
end
|
||||||
|
|
||||||
def resource_url
|
def resource_url
|
||||||
if respond_to?(:customer) && !self.customer.nil?
|
if respond_to?(:customer) && !self.customer.nil? && self.customer != ""
|
||||||
"#{Customer.resource_url}/#{CGI.escape(customer)}/sources/#{CGI.escape(id)}"
|
"#{Customer.resource_url}/#{CGI.escape(customer)}/sources/#{CGI.escape(id)}"
|
||||||
else
|
else
|
||||||
"#{self.class.resource_url}/#{CGI.escape(id)}"
|
"#{self.class.resource_url}/#{CGI.escape(id)}"
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
module Stripe
|
module Stripe
|
||||||
class Dispute < APIResource
|
class Dispute < APIResource
|
||||||
extend Stripe::APIOperations::List
|
extend Stripe::APIOperations::List
|
||||||
extend Stripe::APIOperations::Create
|
|
||||||
include Stripe::APIOperations::Save
|
include Stripe::APIOperations::Save
|
||||||
|
|
||||||
def close(params={}, opts={})
|
def close(params={}, opts={})
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
module Stripe
|
module Stripe
|
||||||
class Reversal < APIResource
|
class Reversal < APIResource
|
||||||
include Stripe::APIOperations::Save
|
|
||||||
extend Stripe::APIOperations::List
|
extend Stripe::APIOperations::List
|
||||||
|
include Stripe::APIOperations::Save
|
||||||
|
|
||||||
def resource_url
|
def resource_url
|
||||||
"#{Transfer.resource_url}/#{CGI.escape(transfer)}/reversals/#{CGI.escape(id)}"
|
"#{Transfer.resource_url}/#{CGI.escape(transfer)}/reversals/#{CGI.escape(id)}"
|
||||||
|
|||||||
@ -2,50 +2,25 @@ require File.expand_path('../../test_helper', __FILE__)
|
|||||||
|
|
||||||
module Stripe
|
module Stripe
|
||||||
class AccountTest < Test::Unit::TestCase
|
class AccountTest < Test::Unit::TestCase
|
||||||
should "be retrievable" do
|
FIXTURE = API_FIXTURES.fetch(:account)
|
||||||
resp = make_account({
|
|
||||||
:charges_enabled => false,
|
should "be listable" do
|
||||||
:details_submitted => false,
|
accounts = Stripe::Account.list
|
||||||
:email => "test+bindings@stripe.com",
|
assert_requested :get, "#{Stripe.api_base}/v1/accounts"
|
||||||
})
|
assert accounts.data.kind_of?(Array)
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/account").
|
assert accounts.data[0].kind_of?(Stripe::Account)
|
||||||
to_return(body: JSON.generate(resp))
|
|
||||||
a = Stripe::Account.retrieve
|
|
||||||
assert_equal "test+bindings@stripe.com", a.email
|
|
||||||
assert !a.charges_enabled
|
|
||||||
assert !a.details_submitted
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "be retrievable via plural endpoint" do
|
should "be retrievable using singular endpoint" do
|
||||||
resp = make_account({
|
account = Stripe::Account.retrieve
|
||||||
:charges_enabled => false,
|
assert_requested :get, "#{Stripe.api_base}/v1/account"
|
||||||
:details_submitted => false,
|
assert account.kind_of?(Stripe::Account)
|
||||||
:email => "test+bindings@stripe.com",
|
|
||||||
})
|
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/accounts/acct_foo").
|
|
||||||
to_return(body: JSON.generate(resp))
|
|
||||||
a = Stripe::Account.retrieve('acct_foo')
|
|
||||||
assert_equal "test+bindings@stripe.com", a.email
|
|
||||||
assert !a.charges_enabled
|
|
||||||
assert !a.details_submitted
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "be retrievable using an API key as the only argument" do
|
should "be retrievable using plural endpoint" do
|
||||||
account = mock
|
account = Stripe::Account.retrieve(FIXTURE[:id])
|
||||||
Stripe::Account.expects(:new).once.with(nil, {:api_key => 'sk_foobar'}).returns(account)
|
assert_requested :get, "#{Stripe.api_base}/v1/accounts/#{FIXTURE[:id]}"
|
||||||
account.expects(:refresh).once
|
assert account.kind_of?(Stripe::Account)
|
||||||
Stripe::Account.retrieve('sk_foobar')
|
|
||||||
end
|
|
||||||
|
|
||||||
should "allow access to keys by method" do
|
|
||||||
account = Stripe::Account.construct_from(make_account({
|
|
||||||
:keys => {
|
|
||||||
:publishable => 'publishable-key',
|
|
||||||
:secret => 'secret-key',
|
|
||||||
}
|
|
||||||
}))
|
|
||||||
assert_equal 'publishable-key', account.keys.publishable
|
|
||||||
assert_equal 'secret-key', account.keys.secret
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "be rejectable" do
|
should "be rejectable" do
|
||||||
@ -60,210 +35,30 @@ module Stripe
|
|||||||
account.reject(:reason => 'fraud')
|
account.reject(:reason => 'fraud')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "be creatable" do
|
||||||
|
account = Stripe::Account.create(:metadata => {})
|
||||||
|
assert_requested :post, "#{Stripe.api_base}/v1/accounts"
|
||||||
|
assert account.kind_of?(Stripe::Account)
|
||||||
|
end
|
||||||
|
|
||||||
should "be saveable" do
|
should "be saveable" do
|
||||||
resp = {
|
account = Stripe::Account.retrieve(FIXTURE[:id])
|
||||||
:id => 'acct_foo',
|
account.metadata['key'] = 'value'
|
||||||
:legal_entity => {
|
account.save
|
||||||
:address => {
|
assert_requested :post, "#{Stripe.api_base}/v1/accounts/#{FIXTURE[:id]}"
|
||||||
:line1 => '1 Two Three'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/accounts/acct_foo").
|
|
||||||
to_return(body: JSON.generate(resp))
|
|
||||||
|
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/accounts/acct_foo").
|
|
||||||
to_return(body: JSON.generate(resp))
|
|
||||||
|
|
||||||
a = Stripe::Account.retrieve('acct_foo')
|
|
||||||
a.legal_entity.first_name = 'Bob'
|
|
||||||
a.legal_entity.address.line1 = '2 Three Four'
|
|
||||||
a.save
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "be updatable" do
|
should "be updateable" do
|
||||||
resp = {
|
account = Stripe::Account.update(FIXTURE[:id], metadata: {foo: 'bar'})
|
||||||
:id => 'acct_foo',
|
assert_requested :post, "#{Stripe.api_base}/v1/accounts/#{FIXTURE[:id]}"
|
||||||
:business_name => 'ACME Corp',
|
assert account.kind_of?(Stripe::Account)
|
||||||
}
|
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/accounts/acct_foo").
|
|
||||||
to_return(body: JSON.generate(resp))
|
|
||||||
|
|
||||||
a = Stripe::Account.update('acct_foo', :business_name => "ACME Corp")
|
|
||||||
assert_equal('ACME Corp', a.business_name)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should 'disallow direct overrides of legal_entity' do
|
should "be deletable" do
|
||||||
account = Stripe::Account.construct_from(make_account({
|
account = Stripe::Account.retrieve(FIXTURE[:id])
|
||||||
:keys => {
|
account = account.delete
|
||||||
:publishable => 'publishable-key',
|
assert_requested :delete, "#{Stripe.api_base}/v1/accounts/#{FIXTURE[:id]}"
|
||||||
:secret => 'secret-key',
|
assert account.kind_of?(Stripe::Account)
|
||||||
},
|
|
||||||
:legal_entity => {
|
|
||||||
:first_name => 'Bling'
|
|
||||||
}
|
|
||||||
}))
|
|
||||||
|
|
||||||
assert_raise NoMethodError do
|
|
||||||
account.legal_entity = {:first_name => 'Blah'}
|
|
||||||
end
|
|
||||||
|
|
||||||
account.legal_entity.first_name = 'Blah'
|
|
||||||
end
|
|
||||||
|
|
||||||
should "be able to deauthorize an account" do
|
|
||||||
resp = {:id => 'acct_1234', :email => "test+bindings@stripe.com", :charge_enabled => false, :details_submitted => false}
|
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/account").
|
|
||||||
to_return(body: JSON.generate(resp))
|
|
||||||
a = Stripe::Account.retrieve
|
|
||||||
|
|
||||||
stub_request(:post, "#{Stripe.connect_base}/oauth/deauthorize").
|
|
||||||
with(body: { 'client_id' => 'ca_1234', 'stripe_user_id' => a.id}).
|
|
||||||
to_return(body: JSON.generate({ 'stripe_user_id' => a.id }))
|
|
||||||
a.deauthorize('ca_1234', 'sk_test_1234')
|
|
||||||
end
|
|
||||||
|
|
||||||
should "reject nil api keys" do
|
|
||||||
assert_raise TypeError do
|
|
||||||
Stripe::Account.retrieve(nil)
|
|
||||||
end
|
|
||||||
assert_raise TypeError do
|
|
||||||
Stripe::Account.retrieve(:api_key => nil)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
should "be able to create a bank account" do
|
|
||||||
resp = {
|
|
||||||
:id => 'acct_1234',
|
|
||||||
:external_accounts => {
|
|
||||||
:object => "list",
|
|
||||||
:resource_url => "/v1/accounts/acct_1234/external_accounts",
|
|
||||||
:data => [],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/account").
|
|
||||||
to_return(body: JSON.generate(resp))
|
|
||||||
a = Stripe::Account.retrieve
|
|
||||||
|
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/accounts/acct_1234/external_accounts").
|
|
||||||
with(body: { :external_account => 'btok_1234' }).
|
|
||||||
to_return(body: JSON.generate(resp))
|
|
||||||
a.external_accounts.create({:external_account => 'btok_1234'})
|
|
||||||
end
|
|
||||||
|
|
||||||
should "be able to retrieve a bank account" do
|
|
||||||
resp = {
|
|
||||||
:id => 'acct_1234',
|
|
||||||
:external_accounts => {
|
|
||||||
:object => "list",
|
|
||||||
:resource_url => "/v1/accounts/acct_1234/external_accounts",
|
|
||||||
:data => [{
|
|
||||||
:id => "ba_1234",
|
|
||||||
:object => "bank_account",
|
|
||||||
}],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/account").
|
|
||||||
to_return(body: JSON.generate(resp))
|
|
||||||
a = Stripe::Account.retrieve
|
|
||||||
assert_equal(BankAccount, a.external_accounts.data[0].class)
|
|
||||||
end
|
|
||||||
|
|
||||||
should "#serialize_params an a new additional_owners" do
|
|
||||||
obj = Stripe::Util.convert_to_stripe_object({
|
|
||||||
:object => "account",
|
|
||||||
:legal_entity => Stripe::StripeObject.construct_from({
|
|
||||||
}),
|
|
||||||
}, {})
|
|
||||||
obj.legal_entity.additional_owners = [
|
|
||||||
{ :first_name => "Joe" },
|
|
||||||
{ :first_name => "Jane" },
|
|
||||||
]
|
|
||||||
|
|
||||||
expected = {
|
|
||||||
:legal_entity => {
|
|
||||||
:additional_owners => {
|
|
||||||
"0" => { :first_name => "Joe" },
|
|
||||||
"1" => { :first_name => "Jane" },
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
assert_equal(expected, obj.serialize_params)
|
|
||||||
end
|
|
||||||
|
|
||||||
should "#serialize_params on an partially changed additional_owners" do
|
|
||||||
obj = Stripe::Util.convert_to_stripe_object({
|
|
||||||
:object => "account",
|
|
||||||
:legal_entity => {
|
|
||||||
:additional_owners => [
|
|
||||||
Stripe::StripeObject.construct_from({
|
|
||||||
:first_name => "Joe"
|
|
||||||
}),
|
|
||||||
Stripe::StripeObject.construct_from({
|
|
||||||
:first_name => "Jane"
|
|
||||||
}),
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}, {})
|
|
||||||
obj.legal_entity.additional_owners[1].first_name = "Stripe"
|
|
||||||
|
|
||||||
expected = {
|
|
||||||
:legal_entity => {
|
|
||||||
:additional_owners => {
|
|
||||||
"1" => { :first_name => "Stripe" }
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
assert_equal(expected, obj.serialize_params)
|
|
||||||
end
|
|
||||||
|
|
||||||
should "#serialize_params on an unchanged additional_owners" do
|
|
||||||
obj = Stripe::Util.convert_to_stripe_object({
|
|
||||||
:object => "account",
|
|
||||||
:legal_entity => {
|
|
||||||
:additional_owners => [
|
|
||||||
Stripe::StripeObject.construct_from({
|
|
||||||
:first_name => "Joe"
|
|
||||||
}),
|
|
||||||
Stripe::StripeObject.construct_from({
|
|
||||||
:first_name => "Jane"
|
|
||||||
}),
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}, {})
|
|
||||||
|
|
||||||
expected = {
|
|
||||||
:legal_entity => {
|
|
||||||
:additional_owners => {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
assert_equal(expected, obj.serialize_params)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Note that the empty string that we send for this one has a special
|
|
||||||
# meaning for the server, which interprets it as an array unset.
|
|
||||||
should "#serialize_params on an unset additional_owners" do
|
|
||||||
obj = Stripe::Util.convert_to_stripe_object({
|
|
||||||
:object => "account",
|
|
||||||
:legal_entity => {
|
|
||||||
:additional_owners => [
|
|
||||||
Stripe::StripeObject.construct_from({
|
|
||||||
:first_name => "Joe"
|
|
||||||
}),
|
|
||||||
Stripe::StripeObject.construct_from({
|
|
||||||
:first_name => "Jane"
|
|
||||||
}),
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}, {})
|
|
||||||
obj.legal_entity.additional_owners = nil
|
|
||||||
|
|
||||||
expected = {
|
|
||||||
:legal_entity => {
|
|
||||||
:additional_owners => ""
|
|
||||||
}
|
|
||||||
}
|
|
||||||
assert_equal(expected, obj.serialize_params)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
context "#bank_account=" do
|
context "#bank_account=" do
|
||||||
@ -271,8 +66,8 @@ module Stripe
|
|||||||
old_stderr = $stderr
|
old_stderr = $stderr
|
||||||
$stderr = StringIO.new
|
$stderr = StringIO.new
|
||||||
begin
|
begin
|
||||||
a = Stripe::Account.new("test_account")
|
account = Stripe::Account.retrieve(FIXTURE[:id])
|
||||||
a.bank_account = "tok_123"
|
account.bank_account = "tok_123"
|
||||||
message = "NOTE: Stripe::Account#bank_account= is " +
|
message = "NOTE: Stripe::Account#bank_account= is " +
|
||||||
"deprecated; use #external_account= instead"
|
"deprecated; use #external_account= instead"
|
||||||
assert_match Regexp.new(message), $stderr.string
|
assert_match Regexp.new(message), $stderr.string
|
||||||
@ -281,5 +76,129 @@ module Stripe
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "#deauthorize" do
|
||||||
|
should "deauthorize an account" do
|
||||||
|
account = Stripe::Account.retrieve(FIXTURE[:id])
|
||||||
|
|
||||||
|
# Unfortunately, the OpenAPI spec doesn't yet cover anything under the
|
||||||
|
# Connect endpoints, so for just stub this out with Webmock.
|
||||||
|
stub_request(:post, "#{Stripe.connect_base}/oauth/deauthorize").
|
||||||
|
with(body: { 'client_id' => 'ca_1234', 'stripe_user_id' => account.id}).
|
||||||
|
to_return(body: JSON.generate({ 'stripe_user_id' => account.id }))
|
||||||
|
account.deauthorize('ca_1234', 'sk_test_1234')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "#legal_entity=" do
|
||||||
|
should 'disallow direct overrides' do
|
||||||
|
account = Stripe::Account.retrieve(FIXTURE[:id])
|
||||||
|
|
||||||
|
assert_raise NoMethodError do
|
||||||
|
account.legal_entity = {:first_name => 'Blah'}
|
||||||
|
end
|
||||||
|
|
||||||
|
account.legal_entity.first_name = 'Blah'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "#serialize_params" do
|
||||||
|
should "serialize an a new additional_owners" do
|
||||||
|
obj = Stripe::Util.convert_to_stripe_object({
|
||||||
|
:object => "account",
|
||||||
|
:legal_entity => Stripe::StripeObject.construct_from({
|
||||||
|
}),
|
||||||
|
}, {})
|
||||||
|
obj.legal_entity.additional_owners = [
|
||||||
|
{ :first_name => "Joe" },
|
||||||
|
{ :first_name => "Jane" },
|
||||||
|
]
|
||||||
|
|
||||||
|
expected = {
|
||||||
|
:legal_entity => {
|
||||||
|
:additional_owners => {
|
||||||
|
"0" => { :first_name => "Joe" },
|
||||||
|
"1" => { :first_name => "Jane" },
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert_equal(expected, obj.serialize_params)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "serialize on an partially changed additional_owners" do
|
||||||
|
obj = Stripe::Util.convert_to_stripe_object({
|
||||||
|
:object => "account",
|
||||||
|
:legal_entity => {
|
||||||
|
:additional_owners => [
|
||||||
|
Stripe::StripeObject.construct_from({
|
||||||
|
:first_name => "Joe"
|
||||||
|
}),
|
||||||
|
Stripe::StripeObject.construct_from({
|
||||||
|
:first_name => "Jane"
|
||||||
|
}),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}, {})
|
||||||
|
obj.legal_entity.additional_owners[1].first_name = "Stripe"
|
||||||
|
|
||||||
|
expected = {
|
||||||
|
:legal_entity => {
|
||||||
|
:additional_owners => {
|
||||||
|
"1" => { :first_name => "Stripe" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert_equal(expected, obj.serialize_params)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "serialize on an unchanged additional_owners" do
|
||||||
|
obj = Stripe::Util.convert_to_stripe_object({
|
||||||
|
:object => "account",
|
||||||
|
:legal_entity => {
|
||||||
|
:additional_owners => [
|
||||||
|
Stripe::StripeObject.construct_from({
|
||||||
|
:first_name => "Joe"
|
||||||
|
}),
|
||||||
|
Stripe::StripeObject.construct_from({
|
||||||
|
:first_name => "Jane"
|
||||||
|
}),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}, {})
|
||||||
|
|
||||||
|
expected = {
|
||||||
|
:legal_entity => {
|
||||||
|
:additional_owners => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert_equal(expected, obj.serialize_params)
|
||||||
|
end
|
||||||
|
|
||||||
|
# Note that the empty string that we send for this one has a special
|
||||||
|
# meaning for the server, which interprets it as an array unset.
|
||||||
|
should "serialize on an unset additional_owners" do
|
||||||
|
obj = Stripe::Util.convert_to_stripe_object({
|
||||||
|
:object => "account",
|
||||||
|
:legal_entity => {
|
||||||
|
:additional_owners => [
|
||||||
|
Stripe::StripeObject.construct_from({
|
||||||
|
:first_name => "Joe"
|
||||||
|
}),
|
||||||
|
Stripe::StripeObject.construct_from({
|
||||||
|
:first_name => "Jane"
|
||||||
|
}),
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}, {})
|
||||||
|
obj.legal_entity.additional_owners = nil
|
||||||
|
|
||||||
|
expected = {
|
||||||
|
:legal_entity => {
|
||||||
|
:additional_owners => ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert_equal(expected, obj.serialize_params)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2,9 +2,17 @@ require File.expand_path('../../test_helper', __FILE__)
|
|||||||
|
|
||||||
module Stripe
|
module Stripe
|
||||||
class AlipayAccountTest < Test::Unit::TestCase
|
class AlipayAccountTest < Test::Unit::TestCase
|
||||||
should "raise if accessing Stripe::Alipay.account directly" do
|
FIXTURE = API_FIXTURES.fetch(:alipay_account)
|
||||||
|
|
||||||
|
should "raise on #retrieve" do
|
||||||
assert_raises NotImplementedError do
|
assert_raises NotImplementedError do
|
||||||
Stripe::AlipayAccount.retrieve "card_12345"
|
Stripe::AlipayAccount.retrieve FIXTURE[:id]
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
should "raise on #update" do
|
||||||
|
assert_raises NotImplementedError do
|
||||||
|
Stripe::AlipayAccount.update FIXTURE[:id], {}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -76,7 +76,7 @@ module Stripe
|
|||||||
should "send expand on fetch properly" do
|
should "send expand on fetch properly" do
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/charges/ch_test_charge").
|
stub_request(:get, "#{Stripe.api_base}/v1/charges/ch_test_charge").
|
||||||
with(query: { "expand" => ["customer"] }).
|
with(query: { "expand" => ["customer"] }).
|
||||||
to_return(body: JSON.generate(make_charge))
|
to_return(body: JSON.generate(API_FIXTURES.fetch(:charge)))
|
||||||
|
|
||||||
Stripe::Charge.retrieve({:id => 'ch_test_charge', :expand => [:customer]})
|
Stripe::Charge.retrieve({:id => 'ch_test_charge', :expand => [:customer]})
|
||||||
end
|
end
|
||||||
@ -84,7 +84,7 @@ module Stripe
|
|||||||
should "preserve expand across refreshes" do
|
should "preserve expand across refreshes" do
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/charges/ch_test_charge").
|
stub_request(:get, "#{Stripe.api_base}/v1/charges/ch_test_charge").
|
||||||
with(query: { "expand" => ["customer"] }).
|
with(query: { "expand" => ["customer"] }).
|
||||||
to_return(body: JSON.generate(make_charge))
|
to_return(body: JSON.generate(API_FIXTURES.fetch(:charge)))
|
||||||
|
|
||||||
ch = Stripe::Charge.retrieve({:id => 'ch_test_charge', :expand => [:customer]})
|
ch = Stripe::Charge.retrieve({:id => 'ch_test_charge', :expand => [:customer]})
|
||||||
ch.refresh
|
ch.refresh
|
||||||
@ -92,11 +92,11 @@ module Stripe
|
|||||||
|
|
||||||
should "send expand when fetching through ListObject" do
|
should "send expand when fetching through ListObject" do
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/customers/c_test_customer").
|
stub_request(:get, "#{Stripe.api_base}/v1/customers/c_test_customer").
|
||||||
to_return(body: JSON.generate(make_customer))
|
to_return(body: JSON.generate(API_FIXTURES.fetch(:customer)))
|
||||||
|
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/customers/c_test_customer/sources/cc_test_card").
|
stub_request(:get, "#{Stripe.api_base}/v1/customers/c_test_customer/sources/cc_test_card").
|
||||||
with(query: { "expand" => ["customer"] }).
|
with(query: { "expand" => ["customer"] }).
|
||||||
to_return(body: JSON.generate(make_customer))
|
to_return(body: JSON.generate(API_FIXTURES.fetch(:customer)))
|
||||||
|
|
||||||
customer = Stripe::Customer.retrieve('c_test_customer')
|
customer = Stripe::Customer.retrieve('c_test_customer')
|
||||||
customer.sources.retrieve({:id => 'cc_test_card', :expand => [:customer]})
|
customer.sources.retrieve({:id => 'cc_test_card', :expand => [:customer]})
|
||||||
@ -107,7 +107,7 @@ module Stripe
|
|||||||
should "use the per-object credential when creating" do
|
should "use the per-object credential when creating" do
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/charges").
|
stub_request(:post, "#{Stripe.api_base}/v1/charges").
|
||||||
with(headers: {"Authorization" => "Bearer sk_test_local"}).
|
with(headers: {"Authorization" => "Bearer sk_test_local"}).
|
||||||
to_return(body: JSON.generate(make_charge))
|
to_return(body: JSON.generate(API_FIXTURES.fetch(:charge)))
|
||||||
|
|
||||||
Stripe::Charge.create({:card => {:number => '4242424242424242'}},
|
Stripe::Charge.create({:card => {:number => '4242424242424242'}},
|
||||||
'sk_test_local')
|
'sk_test_local')
|
||||||
@ -126,7 +126,7 @@ module Stripe
|
|||||||
should "use the per-object credential when creating" do
|
should "use the per-object credential when creating" do
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/charges").
|
stub_request(:post, "#{Stripe.api_base}/v1/charges").
|
||||||
with(headers: {"Authorization" => "Bearer local"}).
|
with(headers: {"Authorization" => "Bearer local"}).
|
||||||
to_return(body: JSON.generate(make_charge))
|
to_return(body: JSON.generate(API_FIXTURES.fetch(:charge)))
|
||||||
|
|
||||||
Stripe::Charge.create({:card => {:number => '4242424242424242'}},
|
Stripe::Charge.create({:card => {:number => '4242424242424242'}},
|
||||||
'local')
|
'local')
|
||||||
@ -135,10 +135,10 @@ module Stripe
|
|||||||
should "use the per-object credential when retrieving and making other calls" do
|
should "use the per-object credential when retrieving and making other calls" do
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/charges/ch_test_charge").
|
stub_request(:get, "#{Stripe.api_base}/v1/charges/ch_test_charge").
|
||||||
with(headers: {"Authorization" => "Bearer local"}).
|
with(headers: {"Authorization" => "Bearer local"}).
|
||||||
to_return(body: JSON.generate(make_charge))
|
to_return(body: JSON.generate(API_FIXTURES.fetch(:charge)))
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/charges/ch_test_charge/refunds").
|
stub_request(:post, "#{Stripe.api_base}/v1/charges/ch_test_charge/refunds").
|
||||||
with(headers: {"Authorization" => "Bearer local"}).
|
with(headers: {"Authorization" => "Bearer local"}).
|
||||||
to_return(body: JSON.generate(make_refund))
|
to_return(body: JSON.generate(API_FIXTURES.fetch(:refund)))
|
||||||
|
|
||||||
ch = Stripe::Charge.retrieve('ch_test_charge', 'local')
|
ch = Stripe::Charge.retrieve('ch_test_charge', 'local')
|
||||||
ch.refunds.create
|
ch.refunds.create
|
||||||
@ -150,33 +150,40 @@ module Stripe
|
|||||||
should "urlencode values in GET params" do
|
should "urlencode values in GET params" do
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/charges").
|
stub_request(:get, "#{Stripe.api_base}/v1/charges").
|
||||||
with(query: { customer: "test customer" }).
|
with(query: { customer: "test customer" }).
|
||||||
to_return(body: JSON.generate(make_charge_array))
|
to_return(body: JSON.generate({
|
||||||
|
data: [API_FIXTURES.fetch(:charge)]
|
||||||
|
}))
|
||||||
charges = Stripe::Charge.list(:customer => 'test customer').data
|
charges = Stripe::Charge.list(:customer => 'test customer').data
|
||||||
assert charges.kind_of? Array
|
assert charges.kind_of? Array
|
||||||
end
|
end
|
||||||
|
|
||||||
should "construct URL properly with base query parameters" do
|
should "construct URL properly with base query parameters" do
|
||||||
response = JSON.generate(make_invoice_customer_array)
|
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/invoices").
|
stub_request(:get, "#{Stripe.api_base}/v1/invoices").
|
||||||
with(query: { customer: "test_customer" }).
|
with(query: { customer: "test_customer" }).
|
||||||
to_return(body: response)
|
to_return(body: JSON.generate({
|
||||||
|
data: [API_FIXTURES.fetch(:invoice)],
|
||||||
|
url: "/v1/invoices"
|
||||||
|
}))
|
||||||
invoices = Stripe::Invoice.list(:customer => 'test_customer')
|
invoices = Stripe::Invoice.list(:customer => 'test_customer')
|
||||||
|
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/invoices").
|
stub_request(:get, "#{Stripe.api_base}/v1/invoices").
|
||||||
with(query: { customer: "test_customer", paid: "true" }).
|
with(query: { customer: "test_customer", paid: "true" }).
|
||||||
to_return(body: response)
|
to_return(body: JSON.generate({
|
||||||
|
data: [API_FIXTURES.fetch(:invoice)],
|
||||||
|
url: "/v1/invoices"
|
||||||
|
}))
|
||||||
invoices.list(:paid => true)
|
invoices.list(:paid => true)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "setting a nil value for a param should exclude that param from the request" do
|
should "setting a nil value for a param should exclude that param from the request" do
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/charges").
|
stub_request(:get, "#{Stripe.api_base}/v1/charges").
|
||||||
with(query: { offset: 5, sad: false }).
|
with(query: { offset: 5, sad: false }).
|
||||||
to_return(body: JSON.generate({ :count => 1, :data => [make_charge] }))
|
to_return(body: JSON.generate({ :count => 1, :data => [API_FIXTURES.fetch(:charge)] }))
|
||||||
Stripe::Charge.list(:count => nil, :offset => 5, :sad => false)
|
Stripe::Charge.list(:count => nil, :offset => 5, :sad => false)
|
||||||
|
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/charges").
|
stub_request(:post, "#{Stripe.api_base}/v1/charges").
|
||||||
with(body: { 'amount' => '50', 'currency' => 'usd' }).
|
with(body: { 'amount' => '50', 'currency' => 'usd' }).
|
||||||
to_return(body: JSON.generate({ :count => 1, :data => [make_charge] }))
|
to_return(body: JSON.generate({ :count => 1, :data => [API_FIXTURES.fetch(:charge)] }))
|
||||||
Stripe::Charge.create(:amount => 50, :currency => 'usd', :card => { :number => nil })
|
Stripe::Charge.create(:amount => 50, :currency => 'usd', :card => { :number => nil })
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -195,27 +202,27 @@ module Stripe
|
|||||||
should "making a GET request with parameters should have a query string and no body" do
|
should "making a GET request with parameters should have a query string and no body" do
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/charges").
|
stub_request(:get, "#{Stripe.api_base}/v1/charges").
|
||||||
with(query: { limit: 1 }).
|
with(query: { limit: 1 }).
|
||||||
to_return(body: JSON.generate({ :data => [make_charge] }))
|
to_return(body: JSON.generate({ :data => [API_FIXTURES.fetch(:charge)] }))
|
||||||
Stripe::Charge.list({ :limit => 1 })
|
Stripe::Charge.list({ :limit => 1 })
|
||||||
end
|
end
|
||||||
|
|
||||||
should "making a POST request with parameters should have a body and no query string" do
|
should "making a POST request with parameters should have a body and no query string" do
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/charges").
|
stub_request(:post, "#{Stripe.api_base}/v1/charges").
|
||||||
with(body: {'amount' => '100', 'currency' => 'usd', 'card' => 'sc_token'}).
|
with(body: {'amount' => '100', 'currency' => 'usd', 'card' => 'sc_token'}).
|
||||||
to_return(body: JSON.generate(make_charge))
|
to_return(body: JSON.generate(API_FIXTURES.fetch(:charge)))
|
||||||
Stripe::Charge.create({ :amount => 100, :currency => 'usd', :card => 'sc_token' })
|
Stripe::Charge.create({ :amount => 100, :currency => 'usd', :card => 'sc_token' })
|
||||||
end
|
end
|
||||||
|
|
||||||
should "loading an object should issue a GET request" do
|
should "loading an object should issue a GET request" do
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/customers/test_customer").
|
stub_request(:get, "#{Stripe.api_base}/v1/customers/test_customer").
|
||||||
to_return(body: JSON.generate(make_customer))
|
to_return(body: JSON.generate(API_FIXTURES.fetch(:customer)))
|
||||||
c = Stripe::Customer.new("test_customer")
|
c = Stripe::Customer.new("test_customer")
|
||||||
c.refresh
|
c.refresh
|
||||||
end
|
end
|
||||||
|
|
||||||
should "using array accessors should be the same as the method interface" do
|
should "using array accessors should be the same as the method interface" do
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/customers/test_customer").
|
stub_request(:get, "#{Stripe.api_base}/v1/customers/test_customer").
|
||||||
to_return(body: JSON.generate(make_customer))
|
to_return(body: JSON.generate(API_FIXTURES.fetch(:customer)))
|
||||||
c = Stripe::Customer.new("test_customer")
|
c = Stripe::Customer.new("test_customer")
|
||||||
c.refresh
|
c.refresh
|
||||||
assert_equal c.created, c[:created]
|
assert_equal c.created, c[:created]
|
||||||
@ -227,7 +234,7 @@ module Stripe
|
|||||||
should "accessing a property other than id or parent on an unfetched object should fetch it" do
|
should "accessing a property other than id or parent on an unfetched object should fetch it" do
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/charges").
|
stub_request(:get, "#{Stripe.api_base}/v1/charges").
|
||||||
with(query: { customer: "test_customer" }).
|
with(query: { customer: "test_customer" }).
|
||||||
to_return(body: JSON.generate(make_customer))
|
to_return(body: JSON.generate(API_FIXTURES.fetch(:customer)))
|
||||||
c = Stripe::Customer.new("test_customer")
|
c = Stripe::Customer.new("test_customer")
|
||||||
c.charges
|
c.charges
|
||||||
end
|
end
|
||||||
@ -235,8 +242,8 @@ module Stripe
|
|||||||
should "updating an object should issue a POST request with only the changed properties" do
|
should "updating an object should issue a POST request with only the changed properties" do
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/customers/c_test_customer").
|
stub_request(:post, "#{Stripe.api_base}/v1/customers/c_test_customer").
|
||||||
with(body: { 'description' => 'another_mn' }).
|
with(body: { 'description' => 'another_mn' }).
|
||||||
to_return(body: JSON.generate(make_customer))
|
to_return(body: JSON.generate(API_FIXTURES.fetch(:customer)))
|
||||||
c = Stripe::Customer.construct_from(make_customer)
|
c = Stripe::Customer.construct_from(API_FIXTURES.fetch(:customer))
|
||||||
c.description = "another_mn"
|
c.description = "another_mn"
|
||||||
c.save
|
c.save
|
||||||
end
|
end
|
||||||
@ -244,7 +251,7 @@ module Stripe
|
|||||||
should "updating should merge in returned properties" do
|
should "updating should merge in returned properties" do
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/customers/c_test_customer").
|
stub_request(:post, "#{Stripe.api_base}/v1/customers/c_test_customer").
|
||||||
with(body: { 'description' => 'another_mn' }).
|
with(body: { 'description' => 'another_mn' }).
|
||||||
to_return(body: JSON.generate(make_customer))
|
to_return(body: JSON.generate(API_FIXTURES.fetch(:customer)))
|
||||||
c = Stripe::Customer.new("c_test_customer")
|
c = Stripe::Customer.new("c_test_customer")
|
||||||
c.description = "another_mn"
|
c.description = "another_mn"
|
||||||
c.save
|
c.save
|
||||||
@ -261,7 +268,7 @@ module Stripe
|
|||||||
should "updating should use the supplied api_key" do
|
should "updating should use the supplied api_key" do
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/customers").
|
stub_request(:post, "#{Stripe.api_base}/v1/customers").
|
||||||
with(headers: {"Authorization" => "Bearer sk_test_local"}).
|
with(headers: {"Authorization" => "Bearer sk_test_local"}).
|
||||||
to_return(body: JSON.generate(make_customer))
|
to_return(body: JSON.generate(API_FIXTURES.fetch(:customer)))
|
||||||
c = Stripe::Customer.new
|
c = Stripe::Customer.new
|
||||||
c.save({}, { :api_key => 'sk_test_local' })
|
c.save({}, { :api_key => 'sk_test_local' })
|
||||||
assert_equal false, c.livemode
|
assert_equal false, c.livemode
|
||||||
@ -270,47 +277,37 @@ module Stripe
|
|||||||
should "deleting should send no props and result in an object that has no props other deleted" do
|
should "deleting should send no props and result in an object that has no props other deleted" do
|
||||||
stub_request(:delete, "#{Stripe.api_base}/v1/customers/c_test_customer").
|
stub_request(:delete, "#{Stripe.api_base}/v1/customers/c_test_customer").
|
||||||
to_return(body: JSON.generate({ "id" => "test_customer", "deleted" => true }))
|
to_return(body: JSON.generate({ "id" => "test_customer", "deleted" => true }))
|
||||||
c = Stripe::Customer.construct_from(make_customer)
|
c = Stripe::Customer.construct_from(API_FIXTURES.fetch(:customer))
|
||||||
c.delete
|
c.delete
|
||||||
assert_equal true, c.deleted
|
|
||||||
|
|
||||||
assert_raises NoMethodError do
|
|
||||||
c.livemode
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
should "loading an object with properties that have specific types should instantiate those classes" do
|
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/charges/test_charge").
|
|
||||||
to_return(body: JSON.generate(make_charge))
|
|
||||||
c = Stripe::Charge.retrieve("test_charge")
|
|
||||||
assert c.card.kind_of?(Stripe::StripeObject) && c.card.object == 'card'
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "loading all of an APIResource should return an array of recursively instantiated objects" do
|
should "loading all of an APIResource should return an array of recursively instantiated objects" do
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/charges").
|
stub_request(:get, "#{Stripe.api_base}/v1/charges").
|
||||||
to_return(body: JSON.generate(make_charge_array))
|
to_return(body: JSON.generate({
|
||||||
c = Stripe::Charge.list.data
|
data: [API_FIXTURES.fetch(:charge)]
|
||||||
assert c.kind_of? Array
|
}))
|
||||||
assert c[0].kind_of? Stripe::Charge
|
charges = Stripe::Charge.list.data
|
||||||
assert c[0].card.kind_of?(Stripe::StripeObject) && c[0].card.object == 'card'
|
assert charges.kind_of? Array
|
||||||
|
assert charges[0].kind_of? Stripe::Charge
|
||||||
|
assert charges[0].card.kind_of?(Stripe::StripeObject)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "passing in a stripe_account header should pass it through on call" do
|
should "passing in a stripe_account header should pass it through on call" do
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/customers/c_test_customer").
|
stub_request(:get, "#{Stripe.api_base}/v1/customers/c_test_customer").
|
||||||
with(headers: {"Stripe-Account" => "acct_abc"}).
|
with(headers: {"Stripe-Account" => "acct_abc"}).
|
||||||
to_return(body: JSON.generate(make_customer))
|
to_return(body: JSON.generate(API_FIXTURES.fetch(:customer)))
|
||||||
Stripe::Customer.retrieve("c_test_customer", {:stripe_account => 'acct_abc'})
|
Stripe::Customer.retrieve("c_test_customer", {:stripe_account => 'acct_abc'})
|
||||||
end
|
end
|
||||||
|
|
||||||
should "passing in a stripe_account header should pass it through on save" do
|
should "passing in a stripe_account header should pass it through on save" do
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/customers/c_test_customer").
|
stub_request(:get, "#{Stripe.api_base}/v1/customers/c_test_customer").
|
||||||
with(headers: {"Stripe-Account" => "acct_abc"}).
|
with(headers: {"Stripe-Account" => "acct_abc"}).
|
||||||
to_return(body: JSON.generate(make_customer))
|
to_return(body: JSON.generate(API_FIXTURES.fetch(:customer)))
|
||||||
c = Stripe::Customer.retrieve("c_test_customer", {:stripe_account => 'acct_abc'})
|
c = Stripe::Customer.retrieve("c_test_customer", {:stripe_account => 'acct_abc'})
|
||||||
|
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/customers/c_test_customer").
|
stub_request(:post, "#{Stripe.api_base}/v1/customers/c_test_customer").
|
||||||
with(headers: {"Stripe-Account" => "acct_abc"}).
|
with(headers: {"Stripe-Account" => "acct_abc"}).
|
||||||
to_return(body: JSON.generate(make_customer))
|
to_return(body: JSON.generate(API_FIXTURES.fetch(:customer)))
|
||||||
c.description = 'FOO'
|
c.description = 'FOO'
|
||||||
c.save
|
c.save
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2,32 +2,32 @@ require File.expand_path('../../test_helper', __FILE__)
|
|||||||
|
|
||||||
module Stripe
|
module Stripe
|
||||||
class ApplePayDomainTest < Test::Unit::TestCase
|
class ApplePayDomainTest < Test::Unit::TestCase
|
||||||
should "create should return a new Apple Pay domain" do
|
FIXTURE = API_FIXTURES.fetch(:apple_pay_domain)
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/apple_pay/domains").
|
|
||||||
to_return(body: JSON.generate(make_apple_pay_domain))
|
|
||||||
d = Stripe::ApplePayDomain.create
|
|
||||||
assert_equal "apwc_test_domain", d.id
|
|
||||||
end
|
|
||||||
|
|
||||||
should "domains should be deletable" do
|
should "be listable" do
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/apple_pay/domains/apwc_test_domain").
|
|
||||||
to_return(body: JSON.generate(make_apple_pay_domain))
|
|
||||||
stub_request(:delete, "#{Stripe.api_base}/v1/apple_pay/domains/apwc_test_domain").
|
|
||||||
to_return(body: JSON.generate(make_apple_pay_domain(:deleted => true)))
|
|
||||||
domain = Stripe::ApplePayDomain.retrieve('apwc_test_domain')
|
|
||||||
domain.delete
|
|
||||||
assert domain.deleted
|
|
||||||
end
|
|
||||||
|
|
||||||
should "domains should be listable" do
|
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/apple_pay/domains").
|
|
||||||
to_return(body: JSON.generate(make_apple_pay_domain_array))
|
|
||||||
domains = Stripe::ApplePayDomain.list
|
domains = Stripe::ApplePayDomain.list
|
||||||
|
assert_requested :get, "#{Stripe.api_base}/v1/apple_pay/domains"
|
||||||
assert domains.data.kind_of?(Array)
|
assert domains.data.kind_of?(Array)
|
||||||
assert_equal 3, domains.data.length
|
assert domains.data[0].kind_of?(Stripe::ApplePayDomain)
|
||||||
domains.each do |domain|
|
end
|
||||||
assert domain.kind_of?(Stripe::ApplePayDomain)
|
|
||||||
end
|
should "be retrievable" do
|
||||||
|
domain = Stripe::ApplePayDomain.retrieve(FIXTURE[:id])
|
||||||
|
assert_requested :get, "#{Stripe.api_base}/v1/apple_pay/domains/#{FIXTURE[:id]}"
|
||||||
|
assert domain.kind_of?(Stripe::ApplePayDomain)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be creatable" do
|
||||||
|
domain = Stripe::ApplePayDomain.create(:domain_name => "example.com")
|
||||||
|
assert_requested :post, "#{Stripe.api_base}/v1/apple_pay/domains"
|
||||||
|
assert domain.kind_of?(Stripe::ApplePayDomain)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be deletable" do
|
||||||
|
domain = Stripe::ApplePayDomain.retrieve(FIXTURE[:id])
|
||||||
|
domain = domain.delete
|
||||||
|
assert_requested :delete, "#{Stripe.api_base}/v1/apple_pay/domains/#{FIXTURE[:id]}"
|
||||||
|
assert domain.kind_of?(Stripe::ApplePayDomain)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2,43 +2,37 @@ require File.expand_path('../../test_helper', __FILE__)
|
|||||||
|
|
||||||
module Stripe
|
module Stripe
|
||||||
class ApplicationFeeRefundTest < Test::Unit::TestCase
|
class ApplicationFeeRefundTest < Test::Unit::TestCase
|
||||||
should "refunds should be listable" do
|
FIXTURE = API_FIXTURES.fetch(:fee_refund)
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/application_fees/test_application_fee").
|
|
||||||
to_return(body: JSON.generate(make_application_fee))
|
|
||||||
|
|
||||||
application_fee = Stripe::ApplicationFee.retrieve('test_application_fee')
|
setup do
|
||||||
|
application_fee_fixture = API_FIXTURES.fetch(:platform_earning)
|
||||||
assert application_fee.refunds.first.kind_of?(Stripe::ApplicationFeeRefund)
|
@fee = Stripe::ApplicationFee.retrieve(application_fee_fixture[:id])
|
||||||
end
|
end
|
||||||
|
|
||||||
should "refunds should be updateable" do
|
should "be listable" do
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/application_fees/test_application_fee").
|
refunds = @fee.refunds
|
||||||
to_return(body: JSON.generate(make_application_fee))
|
|
||||||
|
|
||||||
application_fee = Stripe::ApplicationFee.retrieve('test_application_fee')
|
# notably this *doesn't* make an API call
|
||||||
refund = application_fee.refunds.first
|
assert_not_requested :get,
|
||||||
|
"#{Stripe.api_base}/v1/application_fees/#{@fee.id}/refunds"
|
||||||
|
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/application_fees/#{refund.fee}/refunds/#{refund.id}").
|
assert refunds.data.kind_of?(Array)
|
||||||
to_return(body: JSON.generate(make_application_fee_refund(:metadata => {'key' => 'value'})))
|
assert refunds.first.kind_of?(Stripe::ApplicationFeeRefund)
|
||||||
|
end
|
||||||
|
|
||||||
assert_equal nil, refund.metadata['key']
|
should "be creatable" do
|
||||||
|
refund = @fee.refunds.create
|
||||||
|
assert_requested :post,
|
||||||
|
"#{Stripe.api_base}/v1/application_fees/#{@fee.id}/refunds"
|
||||||
|
assert refund.kind_of?(Stripe::ApplicationFeeRefund)
|
||||||
|
end
|
||||||
|
|
||||||
refund.metadata['key'] = 'valu'
|
should "be saveable" do
|
||||||
|
refund = @fee.refunds.first
|
||||||
|
refund.metadata['key'] = 'value'
|
||||||
refund.save
|
refund.save
|
||||||
|
assert_requested :post,
|
||||||
assert_equal 'value', refund.metadata['key']
|
"#{Stripe.api_base}/v1/application_fees/#{@fee.id}/refunds/#{FIXTURE[:id]}"
|
||||||
end
|
|
||||||
|
|
||||||
should "create should return a new refund" do
|
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/application_fees/test_application_fee").
|
|
||||||
to_return(body: JSON.generate(make_application_fee))
|
|
||||||
application_fee = Stripe::ApplicationFee.retrieve('test_application_fee')
|
|
||||||
|
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/application_fees/#{application_fee.id}/refunds").
|
|
||||||
to_return(body: JSON.generate(make_application_fee_refund(:id => 'test_new_refund')))
|
|
||||||
|
|
||||||
refund = application_fee.refunds.create(:amount => 20)
|
|
||||||
assert_equal 'test_new_refund', refund.id
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2,24 +2,13 @@ require File.expand_path('../../test_helper', __FILE__)
|
|||||||
|
|
||||||
module Stripe
|
module Stripe
|
||||||
class ApplicationFeeTest < Test::Unit::TestCase
|
class ApplicationFeeTest < Test::Unit::TestCase
|
||||||
should "application fees should be listable" do
|
FIXTURE = API_FIXTURES.fetch(:platform_earning)
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/application_fees").
|
|
||||||
to_return(body: JSON.generate(make_application_fee_array))
|
should "be listable" do
|
||||||
fees = Stripe::ApplicationFee.list
|
fees = Stripe::ApplicationFee.list
|
||||||
assert fees.data.kind_of? Array
|
assert_requested :get, "#{Stripe.api_base}/v1/application_fees"
|
||||||
fees.each do |fee|
|
assert fees.data.kind_of?(Array)
|
||||||
assert fee.kind_of?(Stripe::ApplicationFee)
|
assert fees.data[0].kind_of?(Stripe::ApplicationFee)
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
should "application fees should be refundable" do
|
|
||||||
fee = Stripe::ApplicationFee.construct_from(make_application_fee)
|
|
||||||
|
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/application_fees/#{fee.id}/refunds").
|
|
||||||
to_return(body: JSON.generate(make_application_fee_refund))
|
|
||||||
|
|
||||||
refund = fee.refunds.create
|
|
||||||
assert refund.is_a?(Stripe::ApplicationFeeRefund)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2,11 +2,10 @@ require File.expand_path('../../test_helper', __FILE__)
|
|||||||
|
|
||||||
module Stripe
|
module Stripe
|
||||||
class BalanceTest < Test::Unit::TestCase
|
class BalanceTest < Test::Unit::TestCase
|
||||||
should "balance should be retrievable" do
|
should "be retrievable" do
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/balance").
|
|
||||||
to_return(body: JSON.generate(make_balance))
|
|
||||||
balance = Stripe::Balance.retrieve
|
balance = Stripe::Balance.retrieve
|
||||||
assert_equal('balance', balance['object'])
|
assert_requested :get, "#{Stripe.api_base}/v1/balance"
|
||||||
|
assert balance.kind_of?(Stripe::Balance)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2,19 +2,40 @@ require File.expand_path('../../test_helper', __FILE__)
|
|||||||
|
|
||||||
module Stripe
|
module Stripe
|
||||||
class BankAccountTest < Test::Unit::TestCase
|
class BankAccountTest < Test::Unit::TestCase
|
||||||
|
FIXTURE = API_FIXTURES.fetch(:external_account_source)
|
||||||
|
|
||||||
should 'be verifiable' do
|
context "#resource_url" do
|
||||||
bank = Stripe::BankAccount.construct_from({
|
should "return an external account URL" do
|
||||||
:id => 'ba_foo',
|
account_id = API_FIXTURES.fetch(:account)[:id]
|
||||||
:customer => 'cus_bar'
|
bank_account = Stripe::BankAccount.construct_from(
|
||||||
})
|
account: account_id,
|
||||||
|
id: FIXTURE[:id]
|
||||||
|
)
|
||||||
|
assert_equal "/v1/accounts/#{account_id}/external_accounts/#{FIXTURE[:id]}",
|
||||||
|
bank_account.resource_url
|
||||||
|
end
|
||||||
|
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/customers/#{bank.customer}/sources/#{bank.id}/verify").
|
should "return a customer URL" do
|
||||||
with(body: { 'amounts' => ['1', '2'] }).
|
customer_id = API_FIXTURES.fetch(:customer)[:id]
|
||||||
to_return(body: JSON.generate(:status => 'verified'))
|
bank_account = Stripe::BankAccount.construct_from(
|
||||||
|
customer: customer_id,
|
||||||
bank.verify(:amounts => [1,2])
|
id: FIXTURE[:id]
|
||||||
|
)
|
||||||
|
assert_equal "/v1/customers/#{customer_id}/sources/#{FIXTURE[:id]}",
|
||||||
|
bank_account.resource_url
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "#verify" do
|
||||||
|
should 'verify the account' do
|
||||||
|
customer_id = API_FIXTURES.fetch(:customer)[:id]
|
||||||
|
bank_account = Stripe::BankAccount.construct_from({
|
||||||
|
customer: customer_id,
|
||||||
|
id: FIXTURE[:id]
|
||||||
|
})
|
||||||
|
bank_account = bank_account.verify(amounts: [1,2])
|
||||||
|
assert bank_account.kind_of?(Stripe::BankAccount)
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2,62 +2,69 @@ require File.expand_path('../../test_helper', __FILE__)
|
|||||||
|
|
||||||
module Stripe
|
module Stripe
|
||||||
class BitcoinReceiverTest < Test::Unit::TestCase
|
class BitcoinReceiverTest < Test::Unit::TestCase
|
||||||
should "retrieve should retrieve bitcoin receiver" do
|
FIXTURE = API_FIXTURES.fetch(:bitcoin_receiver)
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/bitcoin/receivers/btcrcv_test_receiver").
|
|
||||||
to_return(body: JSON.generate(make_bitcoin_receiver))
|
|
||||||
receiver = Stripe::BitcoinReceiver.retrieve('btcrcv_test_receiver')
|
|
||||||
assert_equal 'btcrcv_test_receiver', receiver.id
|
|
||||||
end
|
|
||||||
|
|
||||||
should "create should create a bitcoin receiver" do
|
should "be listable" do
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/bitcoin/receivers").
|
|
||||||
to_return(body: JSON.generate(make_bitcoin_receiver))
|
|
||||||
receiver = Stripe::BitcoinReceiver.create
|
|
||||||
assert_equal "btcrcv_test_receiver", receiver.id
|
|
||||||
end
|
|
||||||
|
|
||||||
should "all should list bitcoin receivers" do
|
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/bitcoin/receivers").
|
|
||||||
to_return(body: JSON.generate(make_bitcoin_receiver_array))
|
|
||||||
receivers = Stripe::BitcoinReceiver.list
|
receivers = Stripe::BitcoinReceiver.list
|
||||||
assert_equal 3, receivers.data.length
|
assert_requested :get, "#{Stripe.api_base}/v1/bitcoin/receivers"
|
||||||
assert receivers.data.kind_of? Array
|
assert receivers.data.kind_of?(Array)
|
||||||
receivers.each do |receiver|
|
assert receivers.first.kind_of?(Stripe::BitcoinReceiver)
|
||||||
assert receiver.kind_of?(Stripe::BitcoinReceiver)
|
|
||||||
receiver.transactions.data.each do |transaction|
|
|
||||||
assert transaction.kind_of?(Stripe::BitcoinTransaction)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "update should update a bitcoin receiver" do
|
should "be retrievable" do
|
||||||
receiver = Stripe::BitcoinReceiver.construct_from(make_bitcoin_receiver)
|
receiver = Stripe::BitcoinReceiver.retrieve(FIXTURE[:id])
|
||||||
|
assert_requested :get,
|
||||||
|
"#{Stripe.api_base}/v1/bitcoin/receivers/#{FIXTURE[:id]}"
|
||||||
|
assert receiver.kind_of?(Stripe::BitcoinReceiver)
|
||||||
|
end
|
||||||
|
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/bitcoin/receivers/#{receiver.id}").
|
should "be creatable" do
|
||||||
to_return(body: JSON.generate(make_bitcoin_receiver))
|
receiver = Stripe::BitcoinReceiver.create(amount: 100, currency: "USD")
|
||||||
receiver.refresh
|
assert_requested :post, "#{Stripe.api_base}/v1/bitcoin/receivers"
|
||||||
|
assert receiver.kind_of?(Stripe::BitcoinReceiver)
|
||||||
|
end
|
||||||
|
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/bitcoin/receivers/#{receiver.id}").
|
should "be saveable" do
|
||||||
with(body: { description: "details" }).
|
receiver = Stripe::BitcoinReceiver.retrieve(FIXTURE[:id])
|
||||||
to_return(body: JSON.generate(make_bitcoin_receiver))
|
receiver.metadata['key'] = 'value'
|
||||||
receiver.description = "details"
|
|
||||||
receiver.save
|
receiver.save
|
||||||
|
assert_requested :post,
|
||||||
|
"#{Stripe.api_base}/v1/bitcoin/receivers/#{FIXTURE[:id]}"
|
||||||
end
|
end
|
||||||
|
|
||||||
should "delete a bitcoin receiver with no customer through top-level API" do
|
should "be updateable" do
|
||||||
receiver = Stripe::BitcoinReceiver.construct_from(make_bitcoin_receiver)
|
receiver = Stripe::BitcoinReceiver.update(FIXTURE[:id], metadata: { key: 'value' })
|
||||||
stub_request(:delete, "#{Stripe.api_base}/v1/bitcoin/receivers/#{receiver.id}").
|
assert_requested :post,
|
||||||
to_return(body: JSON.generate({:deleted => true, :id => "btcrcv_test_receiver"}))
|
"#{Stripe.api_base}/v1/bitcoin/receivers/#{FIXTURE[:id]}"
|
||||||
receiver.delete
|
assert receiver.kind_of?(Stripe::BitcoinReceiver)
|
||||||
assert(receiver.deleted)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "delete a bitcoin receiver with a customer through customer's subresource API" do
|
should "be deletable" do
|
||||||
receiver = Stripe::BitcoinReceiver.construct_from(make_bitcoin_receiver(:customer => 'customer_foo'))
|
receiver = Stripe::BitcoinReceiver.retrieve(FIXTURE[:id])
|
||||||
stub_request(:delete, "#{Stripe.api_base}/v1/customers/customer_foo/sources/#{receiver.id}").
|
receiver = receiver.delete
|
||||||
to_return(body: JSON.generate({:deleted => true, :id => "btcrcv_test_receiver"}))
|
assert_requested :delete,
|
||||||
receiver.delete
|
"#{Stripe.api_base}/v1/bitcoin/receivers/#{FIXTURE[:id]}"
|
||||||
assert(receiver.deleted)
|
assert receiver.kind_of?(Stripe::BitcoinReceiver)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "#resource_url" do
|
||||||
|
should "return a customer URL" do
|
||||||
|
customer_id = API_FIXTURES.fetch(:customer)[:id]
|
||||||
|
receiver = Stripe::BitcoinReceiver.construct_from(
|
||||||
|
customer: customer_id,
|
||||||
|
id: FIXTURE[:id]
|
||||||
|
)
|
||||||
|
assert_equal "/v1/customers/#{customer_id}/sources/#{FIXTURE[:id]}",
|
||||||
|
receiver.resource_url
|
||||||
|
end
|
||||||
|
|
||||||
|
should "return an absolute URL" do
|
||||||
|
receiver = Stripe::BitcoinReceiver.construct_from(
|
||||||
|
id: FIXTURE[:id]
|
||||||
|
)
|
||||||
|
assert_equal "/v1/bitcoin/receivers/#{FIXTURE[:id]}",
|
||||||
|
receiver.resource_url
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2,24 +2,20 @@ require File.expand_path('../../test_helper', __FILE__)
|
|||||||
|
|
||||||
module Stripe
|
module Stripe
|
||||||
class BitcoinTransactionTest < Test::Unit::TestCase
|
class BitcoinTransactionTest < Test::Unit::TestCase
|
||||||
TEST_ID = "btctxn_test_transaction".freeze
|
FIXTURE = API_FIXTURES.fetch(:bitcoin_transaction)
|
||||||
|
|
||||||
should "retrieve should retrieve bitcoin receiver" do
|
should "be listable" do
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/bitcoin/transactions/#{TEST_ID}").
|
transactions = Stripe::BitcoinTransaction.list
|
||||||
to_return(body: JSON.generate(make_bitcoin_transaction))
|
assert_requested :get, "#{Stripe.api_base}/v1/bitcoin/transactions"
|
||||||
receiver = Stripe::BitcoinTransaction.retrieve(TEST_ID)
|
assert transactions.data.kind_of?(Array)
|
||||||
assert_equal TEST_ID, receiver.id
|
assert transactions.first.kind_of?(Stripe::BitcoinTransaction)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "all should list bitcoin transactions" do
|
should "be retrievable" do
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/bitcoin/transactions").
|
transaction = Stripe::BitcoinTransaction.retrieve(FIXTURE[:id])
|
||||||
to_return(body: JSON.generate(make_bitcoin_transaction_array))
|
assert_requested :get,
|
||||||
transactions = Stripe::BitcoinTransaction.list
|
"#{Stripe.api_base}/v1/bitcoin/transactions/#{FIXTURE[:id]}"
|
||||||
|
assert transaction.kind_of?(Stripe::BitcoinTransaction)
|
||||||
assert transactions.data.kind_of? Array
|
|
||||||
transactions.each do |transaction|
|
|
||||||
assert transaction.kind_of?(Stripe::BitcoinTransaction)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,61 +0,0 @@
|
|||||||
require File.expand_path('../../test_helper', __FILE__)
|
|
||||||
|
|
||||||
module Stripe
|
|
||||||
class ChargeRefundTest < Test::Unit::TestCase
|
|
||||||
should "refunds should be listable" do
|
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/charges/test_charge").
|
|
||||||
to_return(body: JSON.generate(make_charge))
|
|
||||||
charge = Stripe::Charge.retrieve('test_charge')
|
|
||||||
|
|
||||||
assert charge.refunds.first.kind_of?(Stripe::Refund)
|
|
||||||
end
|
|
||||||
|
|
||||||
should "refunds should be refreshable" do
|
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/charges/test_charge").
|
|
||||||
to_return(body: JSON.generate(make_charge))
|
|
||||||
charge = Stripe::Charge.retrieve('test_charge')
|
|
||||||
refund = charge.refunds.first
|
|
||||||
|
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/refunds/#{refund.id}").
|
|
||||||
to_return(body: JSON.generate(make_refund))
|
|
||||||
refund.refresh
|
|
||||||
end
|
|
||||||
|
|
||||||
should "refunds should be updateable" do
|
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/charges/test_charge").
|
|
||||||
to_return(body: JSON.generate(make_charge))
|
|
||||||
charge = Stripe::Charge.retrieve('test_charge')
|
|
||||||
refund = charge.refunds.first
|
|
||||||
|
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/refunds/#{refund.id}").
|
|
||||||
with(body: { metadata: { key: "value" } }).
|
|
||||||
to_return(body: JSON.generate(make_refund))
|
|
||||||
refund.metadata['key'] = 'value'
|
|
||||||
refund.save
|
|
||||||
end
|
|
||||||
|
|
||||||
should "create a new refund" do
|
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/charges/test_charge").
|
|
||||||
to_return(body: JSON.generate(make_charge))
|
|
||||||
charge = Stripe::Charge.retrieve('test_charge')
|
|
||||||
|
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/charges/#{charge.id}/refunds").
|
|
||||||
with(body: { amount: "20" }).
|
|
||||||
to_return(body: JSON.generate(make_refund))
|
|
||||||
_ = charge.refunds.create(:amount => 20)
|
|
||||||
end
|
|
||||||
|
|
||||||
should "create a new refund with the old helper" do
|
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/charges/test_charge").
|
|
||||||
to_return(body: JSON.generate(make_charge))
|
|
||||||
charge = Stripe::Charge.retrieve('test_charge')
|
|
||||||
|
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/charges/#{charge.id}").
|
|
||||||
to_return(body: JSON.generate(charge))
|
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/charges/#{charge.id}/refunds").
|
|
||||||
with(body: { amount: "20" }).
|
|
||||||
to_return(body: JSON.generate(make_refund))
|
|
||||||
charge.refund(:amount => 20)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@ -2,19 +2,18 @@ require File.expand_path('../../test_helper', __FILE__)
|
|||||||
|
|
||||||
module Stripe
|
module Stripe
|
||||||
class CountrySpecTest < Test::Unit::TestCase
|
class CountrySpecTest < Test::Unit::TestCase
|
||||||
should "be listable" do
|
FIXTURE = API_FIXTURES.fetch(:country_spec)
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/country_specs").
|
|
||||||
to_return(body: JSON.generate(make_country_spec_array))
|
|
||||||
c = Stripe::CountrySpec.list
|
|
||||||
|
|
||||||
assert(c.data.kind_of?(Array))
|
should "be listable" do
|
||||||
assert(c.data[0].kind_of?(Stripe::CountrySpec))
|
c = Stripe::CountrySpec.list
|
||||||
|
assert_requested :get, "#{Stripe.api_base}/v1/country_specs"
|
||||||
|
assert c.data.kind_of?(Array)
|
||||||
|
assert c.data[0].kind_of?(Stripe::CountrySpec)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "be retrievable" do
|
should "be retrievable" do
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/country_specs/US").
|
s = Stripe::CountrySpec.retrieve(FIXTURE[:id])
|
||||||
to_return(body: JSON.generate(make_country_spec))
|
assert_requested :get, "#{Stripe.api_base}/v1/country_specs/#{FIXTURE[:id]}"
|
||||||
s = Stripe::CountrySpec.retrieve('US')
|
|
||||||
assert(s.kind_of?(Stripe::CountrySpec))
|
assert(s.kind_of?(Stripe::CountrySpec))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2,29 +2,38 @@ require File.expand_path('../../test_helper', __FILE__)
|
|||||||
|
|
||||||
module Stripe
|
module Stripe
|
||||||
class CouponTest < Test::Unit::TestCase
|
class CouponTest < Test::Unit::TestCase
|
||||||
should "create should return a new coupon" do
|
FIXTURE = API_FIXTURES.fetch(:coupon)
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/coupons").
|
|
||||||
to_return(body: JSON.generate(make_coupon))
|
should "be listable" do
|
||||||
_ = Stripe::Coupon.create
|
coupons = Stripe::Coupon.list
|
||||||
|
assert_requested :get, "#{Stripe.api_base}/v1/coupons"
|
||||||
|
assert coupons.data.kind_of?(Array)
|
||||||
|
assert coupons.first.kind_of?(Stripe::Coupon)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "coupons should be saveable" do
|
should "be retrievable" do
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/coupons/test_coupon").
|
coupon = Stripe::Coupon.retrieve(FIXTURE[:id])
|
||||||
to_return(body: JSON.generate(make_coupon))
|
assert_requested :get, "#{Stripe.api_base}/v1/coupons/#{FIXTURE[:id]}"
|
||||||
c = Stripe::Coupon.retrieve("test_coupon")
|
assert coupon.kind_of?(Stripe::Coupon)
|
||||||
|
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/coupons/#{c.id}").
|
|
||||||
with(body: { metadata: { foo: "bar" } }).
|
|
||||||
to_return(body: JSON.generate(make_customer))
|
|
||||||
c.metadata['foo'] = 'bar'
|
|
||||||
c.save
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "coupons should be updateable" do
|
should "be creatable" do
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/coupons/test_coupon").
|
coupon = Stripe::Coupon.create(:charge => API_FIXTURES[:charge][:id])
|
||||||
with(body: { metadata: { foo: "bar" } }).
|
assert_requested :post, "#{Stripe.api_base}/v1/coupons"
|
||||||
to_return(body: JSON.generate(make_customer))
|
assert coupon.kind_of?(Stripe::Coupon)
|
||||||
_ = Stripe::Coupon.update("test_coupon", metadata: {foo: 'bar'})
|
end
|
||||||
|
|
||||||
|
should "be saveable" do
|
||||||
|
coupon = Stripe::Coupon.retrieve(FIXTURE[:id])
|
||||||
|
coupon.metadata['key'] = 'value'
|
||||||
|
coupon.save
|
||||||
|
assert_requested :post, "#{Stripe.api_base}/v1/coupons/#{FIXTURE[:id]}"
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be updateable" do
|
||||||
|
coupon = Stripe::Coupon.update(FIXTURE[:id], metadata: { key: 'value' })
|
||||||
|
assert_requested :post, "#{Stripe.api_base}/v1/coupons/#{FIXTURE[:id]}"
|
||||||
|
assert coupon.kind_of?(Stripe::Coupon)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2,62 +2,41 @@ require File.expand_path('../../test_helper', __FILE__)
|
|||||||
|
|
||||||
module Stripe
|
module Stripe
|
||||||
class CustomerCardTest < Test::Unit::TestCase
|
class CustomerCardTest < Test::Unit::TestCase
|
||||||
def customer
|
FIXTURE = API_FIXTURES.fetch(:source)
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/customers/test_customer").
|
|
||||||
to_return(body: JSON.generate(make_customer))
|
setup do
|
||||||
Stripe::Customer.retrieve('test_customer')
|
@customer =
|
||||||
|
Stripe::Customer.retrieve(API_FIXTURES.fetch(:customer)[:id])
|
||||||
end
|
end
|
||||||
|
|
||||||
should "customer cards should be listable" do
|
should "be listable" do
|
||||||
c = customer
|
sources = @customer.sources.list
|
||||||
|
assert sources.data.kind_of?(Array)
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/customers/#{c.id}/sources").
|
# because of the terrible :wildcard nature of sources, the API stub
|
||||||
with(query: { object: "card" }).
|
# cannot currently replace this response with anything meaningful so we
|
||||||
to_return(body: JSON.generate(make_customer_card_array(customer.id)))
|
# don't assert on the type of individual items like we do in other tests
|
||||||
cards = c.sources.list(:object => "card").data
|
|
||||||
assert cards.kind_of? Array
|
|
||||||
assert cards[0].kind_of? Stripe::Card
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "customer cards should be deletable" do
|
should "be creatable" do
|
||||||
c = customer
|
card = @customer.sources.create(
|
||||||
|
source: API_FIXTURES.fetch(:token)[:id]
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/customers/#{c.id}/sources/card").
|
)
|
||||||
to_return(body: JSON.generate(make_card))
|
assert_requested :post, "#{Stripe.api_base}/v1/customers/#{@customer.id}/sources"
|
||||||
card = c.sources.retrieve('card')
|
assert card.kind_of?(Stripe::BankAccount)
|
||||||
|
|
||||||
stub_request(:delete, "#{Stripe.api_base}/v1/customers/#{card.customer}/sources/#{card.id}").
|
|
||||||
to_return(body: JSON.generate(make_card(:deleted => true)))
|
|
||||||
_ = card.delete
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "customer cards should be updateable" do
|
should "be deletable" do
|
||||||
c = customer
|
card = Stripe::Card.construct_from(FIXTURE.merge(customer: @customer.id))
|
||||||
|
card = card.delete
|
||||||
|
assert_requested :delete, "#{Stripe.api_base}/v1/customers/#{@customer.id}/sources/#{FIXTURE[:id]}"
|
||||||
|
assert card.kind_of?(Stripe::Card)
|
||||||
|
end
|
||||||
|
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/customers/#{c.id}/sources/card").
|
should "be saveable" do
|
||||||
to_return(body: JSON.generate(make_card))
|
card = Stripe::Card.construct_from(FIXTURE.merge(customer: @customer.id))
|
||||||
card = c.sources.retrieve('card')
|
card.metadata['key'] = 'value'
|
||||||
|
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/customers/#{card.customer}/sources/#{card.id}").
|
|
||||||
with(body: { exp_year: "2100" }).
|
|
||||||
to_return(body: JSON.generate(make_card))
|
|
||||||
card.exp_year = "2100"
|
|
||||||
card.save
|
card.save
|
||||||
end
|
assert_requested :post, "#{Stripe.api_base}/v1/customers/#{@customer.id}/sources/#{FIXTURE[:id]}"
|
||||||
|
|
||||||
should "create should return a new customer card" do
|
|
||||||
c = customer
|
|
||||||
|
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/customers/#{c.id}/sources").
|
|
||||||
with(body: { source: "tok_41YJ05ijAaWaFS" }).
|
|
||||||
to_return(body: JSON.generate(make_card))
|
|
||||||
_ = c.sources.create(:source => "tok_41YJ05ijAaWaFS")
|
|
||||||
end
|
|
||||||
|
|
||||||
should "raise if accessing Stripe::Card.retrieve directly" do
|
|
||||||
assert_raises NotImplementedError do
|
|
||||||
Stripe::Card.retrieve "card_12345"
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2,112 +2,114 @@ require File.expand_path('../../test_helper', __FILE__)
|
|||||||
|
|
||||||
module Stripe
|
module Stripe
|
||||||
class CustomerTest < Test::Unit::TestCase
|
class CustomerTest < Test::Unit::TestCase
|
||||||
should "customers should be listable" do
|
FIXTURE = API_FIXTURES.fetch(:customer)
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/customers").
|
|
||||||
to_return(body: JSON.generate(make_customer_array))
|
should "be listable" do
|
||||||
c = Stripe::Customer.list.data
|
customers = Stripe::Customer.list
|
||||||
assert c.kind_of? Array
|
assert_requested :get, "#{Stripe.api_base}/v1/customers"
|
||||||
assert c[0].kind_of? Stripe::Customer
|
assert customers.data.kind_of?(Array)
|
||||||
|
assert customers.first.kind_of?(Stripe::Customer)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "customers should be deletable" do
|
should "be retrievable" do
|
||||||
stub_request(:delete, "#{Stripe.api_base}/v1/customers/test_customer").
|
customer = Stripe::Customer.retrieve(FIXTURE[:id])
|
||||||
to_return(body: JSON.generate(make_customer))
|
assert_requested :get, "#{Stripe.api_base}/v1/customers/#{FIXTURE[:id]}"
|
||||||
c = Stripe::Customer.new("test_customer")
|
assert customer.kind_of?(Stripe::Customer)
|
||||||
c.delete
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "customers should be saveable" do
|
should "be creatable" do
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/customers/test_customer").
|
customer = Stripe::Customer.create
|
||||||
to_return(body: JSON.generate(make_customer))
|
assert_requested :post, "#{Stripe.api_base}/v1/customers"
|
||||||
c = Stripe::Customer.retrieve("test_customer")
|
assert customer.kind_of?(Stripe::Customer)
|
||||||
|
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/customers/#{c.id}").
|
|
||||||
with(body: { mnemonic: "bar" }).
|
|
||||||
to_return(body: JSON.generate(make_customer))
|
|
||||||
c.mnemonic = "bar"
|
|
||||||
c.save
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "customers should be updateable" do
|
should "be saveable" do
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/customers/test_customer").
|
customer = Stripe::Customer.retrieve(FIXTURE[:id])
|
||||||
with(body: { mnemonic: "bar" }).
|
customer.metadata['key'] = 'value'
|
||||||
to_return(body: JSON.generate(make_customer))
|
customer.save
|
||||||
_ = Stripe::Customer.update("test_customer", mnemonic: "bar")
|
assert_requested :post, "#{Stripe.api_base}/v1/customers/#{FIXTURE[:id]}"
|
||||||
end
|
end
|
||||||
|
|
||||||
should "create should return a new customer" do
|
should "be updateable" do
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/customers").
|
customer = Stripe::Customer.update(FIXTURE[:id], metadata: { key: 'value' })
|
||||||
to_return(body: JSON.generate(make_customer))
|
assert_requested :post, "#{Stripe.api_base}/v1/customers/#{FIXTURE[:id]}"
|
||||||
_ = Stripe::Customer.create
|
assert customer.kind_of?(Stripe::Customer)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "create_upcoming_invoice should create a new invoice" do
|
should "be deletable" do
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/invoices").
|
customer = Stripe::Customer.retrieve(FIXTURE[:id])
|
||||||
with(body: { customer: "test_customer" }).
|
customer = customer.delete
|
||||||
to_return(body: JSON.generate(make_customer))
|
assert_requested :delete, "#{Stripe.api_base}/v1/customers/#{FIXTURE[:id]}"
|
||||||
_ = Stripe::Customer.new("test_customer").create_upcoming_invoice
|
assert customer.kind_of?(Stripe::Customer)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "be able to update a customer's subscription" do
|
context "#create_subscription" do
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/customers/test_customer").
|
should "create a new subscription" do
|
||||||
to_return(body: JSON.generate(make_customer))
|
customer = Stripe::Customer.retrieve(FIXTURE[:id])
|
||||||
c = Stripe::Customer.retrieve("test_customer")
|
subscription = customer.create_subscription({:plan => 'silver'})
|
||||||
|
assert subscription.kind_of?(Stripe::Subscription)
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/customers/#{c.id}/subscription").
|
end
|
||||||
with(body: { plan: "silver" }).
|
|
||||||
to_return(body: JSON.generate(make_subscription))
|
|
||||||
_ = c.update_subscription({:plan => 'silver'})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "be able to cancel a customer's subscription" do
|
context "#create_upcoming_invoice" do
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/customers/test_customer").
|
should "create a new invoice" do
|
||||||
to_return(body: JSON.generate(make_customer))
|
customer = Stripe::Customer.retrieve(FIXTURE[:id])
|
||||||
c = Stripe::Customer.retrieve("test_customer")
|
invoice = customer.create_upcoming_invoice
|
||||||
|
assert invoice.kind_of?(Stripe::Invoice)
|
||||||
# Not an accurate response, but whatever
|
end
|
||||||
|
|
||||||
stub_request(:delete, "#{Stripe.api_base}/v1/customers/#{c.id}/subscription").
|
|
||||||
with(query: { at_period_end: "true" }).
|
|
||||||
to_return(body: JSON.generate(make_subscription))
|
|
||||||
c.cancel_subscription({:at_period_end => 'true'})
|
|
||||||
|
|
||||||
stub_request(:delete, "#{Stripe.api_base}/v1/customers/#{c.id}/subscription").
|
|
||||||
to_return(body: JSON.generate(make_subscription))
|
|
||||||
c.cancel_subscription
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "be able to create a subscription for a customer" do
|
context "#update_subscription" do
|
||||||
c = Stripe::Customer.new("test_customer")
|
should "update a subscription" do
|
||||||
|
customer = Stripe::Customer.retrieve(FIXTURE[:id])
|
||||||
|
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/customers/#{c.id}/subscriptions").
|
# deprecated API and not in schema
|
||||||
with(body: { plan: "silver" }).
|
stub_request(:post, "#{Stripe.api_base}/v1/customers/#{customer.id}/subscription").
|
||||||
to_return(body: JSON.generate(make_subscription))
|
with(body: { plan: "silver" }).
|
||||||
_ = c.create_subscription({:plan => 'silver'})
|
to_return(body: JSON.generate(API_FIXTURES[:subscription]))
|
||||||
|
subscription = customer.update_subscription({:plan => 'silver'})
|
||||||
|
assert subscription.kind_of?(Stripe::Subscription)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
should "be able to delete a customer's discount" do
|
context "#cancel_subscription" do
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/customers/test_customer").
|
should "cancel a subscription" do
|
||||||
to_return(body: JSON.generate(make_customer))
|
customer = Stripe::Customer.retrieve(FIXTURE[:id])
|
||||||
c = Stripe::Customer.retrieve("test_customer")
|
|
||||||
|
|
||||||
stub_request(:delete, "#{Stripe.api_base}/v1/customers/#{c.id}/discount").
|
# deprecated API and not in schema
|
||||||
to_return(body: JSON.generate(make_delete_discount_response))
|
stub_request(:delete, "#{Stripe.api_base}/v1/customers/#{customer.id}/subscription").
|
||||||
c.delete_discount
|
with(query: { at_period_end: "true" }).
|
||||||
|
to_return(body: JSON.generate(API_FIXTURES[:subscription]))
|
||||||
|
subscription = customer.cancel_subscription({:at_period_end => 'true'})
|
||||||
|
assert subscription.kind_of?(Stripe::Subscription)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
should "can have a token source set" do
|
context "#delete_discount" do
|
||||||
c = Stripe::Customer.new("test_customer")
|
should "delete a discount" do
|
||||||
c.source = "tok_123"
|
customer = Stripe::Customer.retrieve(FIXTURE[:id])
|
||||||
assert_equal "tok_123", c.source
|
|
||||||
|
stub_request(:delete, "#{Stripe.api_base}/v1/customers/#{customer.id}/discount").
|
||||||
|
to_return(body: JSON.generate(API_FIXTURES[:discount]))
|
||||||
|
discount = customer.delete_discount
|
||||||
|
assert discount.kind_of?(Stripe::Customer)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
should "set a flag if given an object source" do
|
context "source field" do
|
||||||
c = Stripe::Customer.new("test_customer")
|
should "allow setting source with token" do
|
||||||
c.source = {
|
c = Stripe::Customer.new("test_customer")
|
||||||
:object => 'card'
|
c.source = "tok_123"
|
||||||
}
|
assert_equal "tok_123", c.source
|
||||||
assert_equal true, c.source.save_with_parent
|
end
|
||||||
|
|
||||||
|
should "allow setting source with hash and set flag" do
|
||||||
|
c = Stripe::Customer.new("test_customer")
|
||||||
|
c.source = {
|
||||||
|
:object => 'card'
|
||||||
|
}
|
||||||
|
assert_equal true, c.source.save_with_parent
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2,47 +2,41 @@ 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
|
FIXTURE = API_FIXTURES.fetch(:dispute)
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/disputes/dp_test_dispute").
|
|
||||||
to_return(body: JSON.generate(make_dispute))
|
should "be listable" do
|
||||||
d = Stripe::Dispute.retrieve('dp_test_dispute')
|
disputes = Stripe::Dispute.list
|
||||||
assert d.kind_of?(Stripe::Dispute)
|
assert_requested :get, "#{Stripe.api_base}/v1/disputes"
|
||||||
|
assert disputes.data.kind_of?(Array)
|
||||||
|
assert disputes.first.kind_of?(Stripe::Dispute)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "disputes should be listable" do
|
should "be retrievable" do
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/disputes").
|
dispute = Stripe::Dispute.retrieve(FIXTURE[:id])
|
||||||
to_return(body: JSON.generate(make_dispute_array))
|
assert_requested :get, "#{Stripe.api_base}/v1/disputes/#{FIXTURE[:id]}"
|
||||||
d = Stripe::Dispute.list
|
assert dispute.kind_of?(Stripe::Dispute)
|
||||||
assert d.data.kind_of? Array
|
end
|
||||||
d.each do |dispute|
|
|
||||||
assert dispute.kind_of?(Stripe::Dispute)
|
should "be saveable" do
|
||||||
|
dispute = Stripe::Dispute.retrieve(FIXTURE[:id])
|
||||||
|
dispute.metadata['key'] = 'value'
|
||||||
|
dispute.save
|
||||||
|
assert_requested :post, "#{Stripe.api_base}/v1/disputes/#{FIXTURE[:id]}"
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be updateable" do
|
||||||
|
dispute = Stripe::Dispute.update(FIXTURE[:id], metadata: { key: 'value' })
|
||||||
|
assert_requested :post, "#{Stripe.api_base}/v1/disputes/#{FIXTURE[:id]}"
|
||||||
|
assert dispute.kind_of?(Stripe::Dispute)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "#close" do
|
||||||
|
should "be closeable" do
|
||||||
|
dispute = Stripe::Dispute.retrieve(FIXTURE[:id])
|
||||||
|
dispute.close
|
||||||
|
assert_requested :post,
|
||||||
|
"#{Stripe.api_base}/v1/disputes/#{FIXTURE[:id]}/close"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
should "disputes should be closeable" do
|
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/disputes/dp_test_dispute/close").
|
|
||||||
to_return(body: JSON.generate(make_dispute))
|
|
||||||
d = Stripe::Dispute.new('dp_test_dispute')
|
|
||||||
d.close
|
|
||||||
end
|
|
||||||
|
|
||||||
should "disputes should be updateable" do
|
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/disputes/dp_test_dispute").
|
|
||||||
with(body: { metadata: { foo: "bar" } }).
|
|
||||||
to_return(body: JSON.generate(make_dispute))
|
|
||||||
_ = Stripe::Dispute.update("dp_test_dispute", metadata: {foo: 'bar'})
|
|
||||||
end
|
|
||||||
|
|
||||||
should "disputes should be saveable" do
|
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/disputes/dp_test_dispute").
|
|
||||||
to_return(body: JSON.generate(make_dispute))
|
|
||||||
d = Stripe::Dispute.retrieve('dp_test_dispute')
|
|
||||||
|
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/disputes/dp_test_dispute").
|
|
||||||
with(body: { evidence: { customer_name: "customer" } }).
|
|
||||||
to_return(body: JSON.generate(make_dispute))
|
|
||||||
d.evidence['customer_name'] = 'customer'
|
|
||||||
d.save
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2,31 +2,46 @@ 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
|
# Note that these tests are written different from others because we
|
||||||
stub_request(:post, "#{Stripe.uploads_base}/v1/files").
|
# don't have anything on the uploads service in our OpenAPI spec. This is
|
||||||
to_return(body: JSON.generate(make_file))
|
# something that should be looked into at some point. We may need to ship
|
||||||
|
# a separate spec for it though, so it's high effort with low reward for
|
||||||
|
# the time being.
|
||||||
|
FIXTURE = {
|
||||||
|
id: "fil_15ABpV2eZvKYlo2C7vu7XS5l",
|
||||||
|
object: "file_upload",
|
||||||
|
}.freeze
|
||||||
|
|
||||||
f = Stripe::FileUpload.create({
|
should "be listable" do
|
||||||
:purpose => "dispute_evidence",
|
|
||||||
:file => File.new(__FILE__),
|
|
||||||
})
|
|
||||||
assert_equal "fil_test_file", f.id
|
|
||||||
end
|
|
||||||
|
|
||||||
should "files should be retrievable" do
|
|
||||||
stub_request(:get, "#{Stripe.uploads_base}/v1/files/fil_test_file").
|
|
||||||
to_return(body: JSON.generate(make_file))
|
|
||||||
|
|
||||||
_ = Stripe::FileUpload.retrieve("fil_test_file")
|
|
||||||
end
|
|
||||||
|
|
||||||
should "files should be listable" do
|
|
||||||
stub_request(:get, "#{Stripe.uploads_base}/v1/files").
|
stub_request(:get, "#{Stripe.uploads_base}/v1/files").
|
||||||
to_return(body: JSON.generate(make_file_array))
|
to_return(body: JSON.generate({
|
||||||
|
data: [FIXTURE],
|
||||||
|
object: 'list',
|
||||||
|
resource_url: '/v1/files'
|
||||||
|
}))
|
||||||
|
|
||||||
c = Stripe::FileUpload.list.data
|
files = Stripe::FileUpload.list
|
||||||
assert c.kind_of? Array
|
assert files.data.kind_of?(Array)
|
||||||
assert c[0].kind_of? Stripe::FileUpload
|
assert files.data[0].kind_of?(Stripe::FileUpload)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be retrievable" do
|
||||||
|
stub_request(:get, "#{Stripe.uploads_base}/v1/files/#{FIXTURE[:id]}").
|
||||||
|
to_return(body: JSON.generate(FIXTURE))
|
||||||
|
|
||||||
|
file = Stripe::FileUpload.retrieve(FIXTURE[:id])
|
||||||
|
assert file.kind_of?(Stripe::FileUpload)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be creatable" do
|
||||||
|
stub_request(:post, "#{Stripe.uploads_base}/v1/files").
|
||||||
|
to_return(body: JSON.generate(FIXTURE))
|
||||||
|
|
||||||
|
file = Stripe::FileUpload.create(
|
||||||
|
purpose: "dispute_evidence",
|
||||||
|
file: File.new(__FILE__),
|
||||||
|
)
|
||||||
|
assert file.kind_of?(Stripe::FileUpload)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2,17 +2,54 @@ 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
|
FIXTURE = API_FIXTURES.fetch(:invoice_item)
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/invoiceitems/ii_test_invoice_item").
|
|
||||||
to_return(body: JSON.generate(make_invoice_item))
|
should "be listable" do
|
||||||
_ = Stripe::InvoiceItem.retrieve('ii_test_invoice_item')
|
invoiceitems = Stripe::InvoiceItem.list
|
||||||
|
assert_requested :get, "#{Stripe.api_base}/v1/invoiceitems"
|
||||||
|
assert invoiceitems.data.kind_of?(Array)
|
||||||
|
assert invoiceitems.first.kind_of?(Stripe::InvoiceItem)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "invoice items should be updateable" do
|
should "be retrievable" do
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/invoiceitems/ii_test_invoice_item").
|
item = Stripe::InvoiceItem.retrieve(FIXTURE[:id])
|
||||||
with(body: { metadata: { foo: "bar" } }).
|
assert_requested :get,
|
||||||
to_return(body: JSON.generate(make_invoice_item))
|
"#{Stripe.api_base}/v1/invoiceitems/#{FIXTURE[:id]}"
|
||||||
_ = Stripe::InvoiceItem.update("ii_test_invoice_item", metadata: {foo: 'bar'})
|
assert item.kind_of?(Stripe::InvoiceItem)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be creatable" do
|
||||||
|
item = Stripe::InvoiceItem.create(
|
||||||
|
amount: 100,
|
||||||
|
currency: "USD",
|
||||||
|
customer: API_FIXTURES[:customer][:id]
|
||||||
|
)
|
||||||
|
assert_requested :post,
|
||||||
|
"#{Stripe.api_base}/v1/invoiceitems"
|
||||||
|
assert item.kind_of?(Stripe::InvoiceItem)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be saveable" do
|
||||||
|
item = Stripe::InvoiceItem.retrieve(FIXTURE[:id])
|
||||||
|
item.metadata['key'] = 'value'
|
||||||
|
item.save
|
||||||
|
assert_requested :post,
|
||||||
|
"#{Stripe.api_base}/v1/invoiceitems/#{FIXTURE[:id]}"
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be updateable" do
|
||||||
|
item = Stripe::InvoiceItem.update(FIXTURE[:id], metadata: { key: 'value' })
|
||||||
|
assert_requested :post,
|
||||||
|
"#{Stripe.api_base}/v1/invoiceitems/#{FIXTURE[:id]}"
|
||||||
|
assert item.kind_of?(Stripe::InvoiceItem)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be deletable" do
|
||||||
|
item = Stripe::InvoiceItem.retrieve(FIXTURE[:id])
|
||||||
|
item = item.delete
|
||||||
|
assert_requested :delete,
|
||||||
|
"#{Stripe.api_base}/v1/invoiceitems/#{FIXTURE[:id]}"
|
||||||
|
assert item.kind_of?(Stripe::InvoiceItem)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2,47 +2,65 @@ 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
|
FIXTURE = API_FIXTURES.fetch(:invoice)
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/invoices/in_test_invoice").
|
|
||||||
to_return(body: JSON.generate(make_invoice))
|
should "be listable" do
|
||||||
i = Stripe::Invoice.retrieve('in_test_invoice')
|
invoices = Stripe::Invoice.list
|
||||||
assert_equal 'in_test_invoice', i.id
|
assert_requested :get, "#{Stripe.api_base}/v1/invoices"
|
||||||
|
assert invoices.data.kind_of?(Array)
|
||||||
|
assert invoices.first.kind_of?(Stripe::Invoice)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "create should create a new invoice" do
|
should "be retrievable" do
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/invoices").
|
invoice = Stripe::Invoice.retrieve(FIXTURE[:id])
|
||||||
to_return(body: JSON.generate(make_invoice))
|
assert_requested :get, "#{Stripe.api_base}/v1/invoices/#{FIXTURE[:id]}"
|
||||||
_ = Stripe::Invoice.create
|
assert invoice.kind_of?(Stripe::Invoice)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "pay should pay an invoice" do
|
should "be creatable" do
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/invoices/in_test_invoice").
|
invoice = Stripe::Invoice.create(
|
||||||
to_return(body: JSON.generate(make_invoice))
|
:customer => API_FIXTURES[:customer][:id]
|
||||||
i = Stripe::Invoice.retrieve('in_test_invoice')
|
|
||||||
|
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/invoices/#{i.id}/pay").
|
|
||||||
to_return(body: JSON.generate(make_invoice))
|
|
||||||
i.pay
|
|
||||||
end
|
|
||||||
|
|
||||||
should "invoices should be updateable" do
|
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/invoices/test_invoice").
|
|
||||||
with(body: { metadata: { foo: "bar" } }).
|
|
||||||
to_return(body: JSON.generate(make_invoice))
|
|
||||||
_ = Stripe::Invoice.update("test_invoice", metadata: {foo: 'bar'})
|
|
||||||
end
|
|
||||||
|
|
||||||
should "be able to retrieve upcoming invoices" do
|
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/invoices/upcoming").
|
|
||||||
with(query: {
|
|
||||||
:customer => 'c_test_customer',
|
|
||||||
:subscription => 's_test_subscription',
|
|
||||||
}).
|
|
||||||
to_return(body: JSON.generate(make_invoice))
|
|
||||||
_ = Stripe::Invoice.upcoming(
|
|
||||||
:customer => 'c_test_customer',
|
|
||||||
:subscription => 's_test_subscription',
|
|
||||||
)
|
)
|
||||||
|
assert_requested :post, "#{Stripe.api_base}/v1/invoices"
|
||||||
|
assert invoice.kind_of?(Stripe::Invoice)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be saveable" do
|
||||||
|
invoice = Stripe::Invoice.retrieve(FIXTURE[:id])
|
||||||
|
invoice.metadata['key'] = 'value'
|
||||||
|
invoice.save
|
||||||
|
assert_requested :post, "#{Stripe.api_base}/v1/invoices/#{FIXTURE[:id]}"
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be updateable" do
|
||||||
|
invoice = Stripe::Invoice.update(FIXTURE[:id], metadata: { key: 'value' })
|
||||||
|
assert_requested :post, "#{Stripe.api_base}/v1/invoices/#{FIXTURE[:id]}"
|
||||||
|
assert invoice.kind_of?(Stripe::Invoice)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "#pay" do
|
||||||
|
should "pay invoice" do
|
||||||
|
invoice = Stripe::Invoice.retrieve(FIXTURE[:id])
|
||||||
|
invoice = invoice.pay
|
||||||
|
assert_requested :post,
|
||||||
|
"#{Stripe.api_base}/v1/invoices/#{FIXTURE[:id]}/pay"
|
||||||
|
assert invoice.kind_of?(Stripe::Invoice)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "#upcoming" do
|
||||||
|
should "retrieve upcoming invoices" do
|
||||||
|
invoice = Stripe::Invoice.upcoming(
|
||||||
|
customer: API_FIXTURES[:customer][:id],
|
||||||
|
subscription: API_FIXTURES[:subscription][:id]
|
||||||
|
)
|
||||||
|
assert_requested :get, "#{Stripe.api_base}/v1/invoices/upcoming",
|
||||||
|
query: {
|
||||||
|
customer: API_FIXTURES[:customer][:id],
|
||||||
|
subscription: API_FIXTURES[:subscription][:id]
|
||||||
|
}
|
||||||
|
assert invoice.kind_of?(Stripe::Invoice)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -8,8 +8,10 @@ module Stripe
|
|||||||
end
|
end
|
||||||
|
|
||||||
should "provide #count via enumerable" do
|
should "provide #count via enumerable" do
|
||||||
list = Stripe::ListObject.construct_from(make_charge_array)
|
list = Stripe::ListObject.construct_from({
|
||||||
assert_equal 3, list.count
|
data: [API_FIXTURES.fetch(:charge)]
|
||||||
|
})
|
||||||
|
assert_equal 1, list.count
|
||||||
end
|
end
|
||||||
|
|
||||||
should "provide #each" do
|
should "provide #each" do
|
||||||
@ -152,8 +154,6 @@ 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
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/charges").
|
|
||||||
to_return(body: JSON.generate(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)
|
||||||
|
|||||||
@ -2,25 +2,20 @@ 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
|
FIXTURE = API_FIXTURES.fetch(:order_return)
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/order_returns").
|
|
||||||
to_return(body: JSON.generate(make_order_return_array))
|
should "be listable" do
|
||||||
returns = Stripe::OrderReturn.list
|
order_returns = Stripe::OrderReturn.list
|
||||||
assert returns.data.kind_of?(Array)
|
assert_requested :get, "#{Stripe.api_base}/v1/order_returns"
|
||||||
returns.each do |ret|
|
assert order_returns.data.kind_of?(Array)
|
||||||
assert ret.kind_of?(Stripe::OrderReturn)
|
assert order_returns.data[0].kind_of?(Stripe::OrderReturn)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "returns should not be deletable" do
|
should "be retrievable" do
|
||||||
p = Stripe::OrderReturn.new("test_order")
|
order_return = Stripe::OrderReturn.retrieve(FIXTURE[:id])
|
||||||
assert_raises(NoMethodError) { p.delete }
|
assert_requested :get,
|
||||||
end
|
"#{Stripe.api_base}/v1/order_returns/#{FIXTURE[:id]}"
|
||||||
|
assert order_return.kind_of?(Stripe::OrderReturn)
|
||||||
should "returns should be immutable" do
|
|
||||||
p = Stripe::OrderReturn.new("test_order")
|
|
||||||
p.items = []
|
|
||||||
assert_raises(NoMethodError) { p.save }
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2,65 +2,58 @@ 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
|
FIXTURE = API_FIXTURES.fetch(:order)
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/orders").
|
|
||||||
to_return(body: JSON.generate(make_order_array))
|
should "be listable" do
|
||||||
orders = Stripe::Order.list
|
orders = Stripe::Order.list
|
||||||
|
assert_requested :get, "#{Stripe.api_base}/v1/orders"
|
||||||
assert orders.data.kind_of?(Array)
|
assert orders.data.kind_of?(Array)
|
||||||
orders.each do |order|
|
assert orders.first.kind_of?(Stripe::Order)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be retrievable" do
|
||||||
|
order = Stripe::Order.retrieve(FIXTURE[:id])
|
||||||
|
assert_requested :get, "#{Stripe.api_base}/v1/orders/#{FIXTURE[:id]}"
|
||||||
|
assert order.kind_of?(Stripe::Order)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be creatable" do
|
||||||
|
order = Stripe::Order.create(
|
||||||
|
currency: "USD"
|
||||||
|
)
|
||||||
|
assert_requested :post, "#{Stripe.api_base}/v1/orders"
|
||||||
|
assert order.kind_of?(Stripe::Order)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be saveable" do
|
||||||
|
order = Stripe::Order.retrieve(FIXTURE[:id])
|
||||||
|
order.metadata['key'] = 'value'
|
||||||
|
order.save
|
||||||
|
assert_requested :post, "#{Stripe.api_base}/v1/orders/#{FIXTURE[:id]}"
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be updateable" do
|
||||||
|
order = Stripe::Order.update(FIXTURE[:id], metadata: { key: 'value' })
|
||||||
|
assert_requested :post, "#{Stripe.api_base}/v1/orders/#{FIXTURE[:id]}"
|
||||||
|
assert order.kind_of?(Stripe::Order)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "#pay" do
|
||||||
|
should "pay an order" do
|
||||||
|
order = Stripe::Order.retrieve(FIXTURE[:id])
|
||||||
|
order = order.pay(token: API_FIXTURES.fetch(:token)[:id])
|
||||||
assert order.kind_of?(Stripe::Order)
|
assert order.kind_of?(Stripe::Order)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
should "orders should not be deletable" do
|
context "#return_order" do
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/orders/or_test_order").
|
should "return an order" do
|
||||||
to_return(body: JSON.generate(make_order))
|
order = Stripe::Order.retrieve(FIXTURE[:id])
|
||||||
p = Stripe::Order.retrieve("or_test_order")
|
order = order.return_order(:orders => [
|
||||||
|
{ parent: API_FIXTURES.fetch(:sku)[:id] }
|
||||||
assert_raises NoMethodError do
|
])
|
||||||
p.delete
|
assert order.kind_of?(Stripe::OrderReturn)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
should "orders should be saveable" do
|
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/orders/or_test_order").
|
|
||||||
to_return(body: JSON.generate(make_order))
|
|
||||||
p = Stripe::Order.retrieve("or_test_order")
|
|
||||||
|
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/orders/#{p.id}").
|
|
||||||
with(body: { status: "fulfilled" }).
|
|
||||||
to_return(body: JSON.generate(make_order))
|
|
||||||
p.status = "fulfilled"
|
|
||||||
p.save
|
|
||||||
end
|
|
||||||
|
|
||||||
should "orders should be updateable" do
|
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/orders/or_test_order").
|
|
||||||
with(body: { status: "fulfilled" }).
|
|
||||||
to_return(body: JSON.generate(make_order))
|
|
||||||
_ = Stripe::Order.update("or_test_order", status: 'fulfilled')
|
|
||||||
end
|
|
||||||
|
|
||||||
should "pay should pay an order" do
|
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/orders/or_test_order").
|
|
||||||
to_return(body: JSON.generate(make_order))
|
|
||||||
order = Stripe::Order.retrieve('or_test_order')
|
|
||||||
|
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/orders/#{order.id}/pay").
|
|
||||||
with(body: { token: "test_token" }).
|
|
||||||
to_return(body: JSON.generate(make_order))
|
|
||||||
order.pay(:token => 'test_token')
|
|
||||||
end
|
|
||||||
|
|
||||||
should "return an order" do
|
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/orders/or_test_order").
|
|
||||||
to_return(body: JSON.generate(make_order))
|
|
||||||
order = Stripe::Order.retrieve('or_test_order')
|
|
||||||
|
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/orders/#{order.id}/returns").
|
|
||||||
with(body: { items: [{ parent: "sku_foo" }] }).
|
|
||||||
to_return(body: JSON.generate(make_order))
|
|
||||||
_ = order.return_order(:items => [{:parent => 'sku_foo'}])
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2,33 +2,45 @@ 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
|
FIXTURE = API_FIXTURES.fetch(:plan)
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/plans").
|
|
||||||
to_return(body: JSON.generate(make_plan_array))
|
should "be listable" do
|
||||||
plans = Stripe::Plan.list
|
plans = Stripe::Plan.list
|
||||||
|
assert_requested :get, "#{Stripe.api_base}/v1/plans"
|
||||||
assert plans.data.kind_of?(Array)
|
assert plans.data.kind_of?(Array)
|
||||||
plans.each do |plan|
|
assert plans.data[0].kind_of?(Stripe::Plan)
|
||||||
assert plan.kind_of?(Stripe::Plan)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "plans should be saveable" do
|
should "be retrievable" do
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/plans/test_plan").
|
plan = Stripe::Plan.retrieve(FIXTURE[:id])
|
||||||
to_return(body: JSON.generate(make_plan))
|
assert_requested :get, "#{Stripe.api_base}/v1/plans/#{FIXTURE[:id]}"
|
||||||
p = Stripe::Plan.retrieve("test_plan")
|
assert plan.kind_of?(Stripe::Plan)
|
||||||
|
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/plans/#{p.id}").
|
|
||||||
with(body: { metadata: { foo: "bar" } }).
|
|
||||||
to_return(body: JSON.generate(make_plan))
|
|
||||||
p.metadata['foo'] = 'bar'
|
|
||||||
p.save
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "plans should be updateable" do
|
should "be creatable" do
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/plans/test_plan").
|
plan = Stripe::Plan.create(:metadata => {})
|
||||||
with(body: { metadata: { foo: "bar" } }).
|
assert_requested :post, "#{Stripe.api_base}/v1/plans"
|
||||||
to_return(body: JSON.generate(make_plan))
|
assert plan.kind_of?(Stripe::Plan)
|
||||||
_ = Stripe::Plan.update("test_plan", metadata: {foo: 'bar'})
|
end
|
||||||
|
|
||||||
|
should "be saveable" do
|
||||||
|
plan = Stripe::Plan.retrieve(FIXTURE[:id])
|
||||||
|
plan.metadata['key'] = 'value'
|
||||||
|
plan.save
|
||||||
|
assert_requested :post, "#{Stripe.api_base}/v1/plans/#{FIXTURE[:id]}"
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be updateable" do
|
||||||
|
plan = Stripe::Plan.update(FIXTURE[:id], metadata: {foo: 'bar'})
|
||||||
|
assert_requested :post, "#{Stripe.api_base}/v1/plans/#{FIXTURE[:id]}"
|
||||||
|
assert plan.kind_of?(Stripe::Plan)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be deletable" do
|
||||||
|
plan = Stripe::Plan.retrieve(FIXTURE[:id])
|
||||||
|
plan = plan.delete
|
||||||
|
assert_requested :delete, "#{Stripe.api_base}/v1/plans/#{FIXTURE[:id]}"
|
||||||
|
assert plan.kind_of?(Stripe::Plan)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2,44 +2,46 @@ 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
|
FIXTURE = API_FIXTURES.fetch(:product)
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/products").
|
|
||||||
to_return(body: JSON.generate(make_product_array))
|
should "be listable" do
|
||||||
products = Stripe::Product.list
|
products = Stripe::Product.list
|
||||||
|
assert_requested :get, "#{Stripe.api_base}/v1/products"
|
||||||
assert products.data.kind_of?(Array)
|
assert products.data.kind_of?(Array)
|
||||||
products.each do |product|
|
assert products.data[0].kind_of?(Stripe::Product)
|
||||||
assert product.kind_of?(Stripe::Product)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "products should be deletable" do
|
should "be retrievable" do
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/products/test_product").
|
product = Stripe::Product.retrieve(FIXTURE[:id])
|
||||||
to_return(body: JSON.generate(make_product))
|
assert_requested :get, "#{Stripe.api_base}/v1/products/#{FIXTURE[:id]}"
|
||||||
p = Stripe::Product.retrieve("test_product")
|
assert product.kind_of?(Stripe::Product)
|
||||||
|
|
||||||
stub_request(:delete, "#{Stripe.api_base}/v1/products/#{p.id}").
|
|
||||||
to_return(body: JSON.generate(make_product))
|
|
||||||
p.delete
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "products should be saveable" do
|
should "be creatable" do
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/products/test_product").
|
_ = Stripe::Product.create(
|
||||||
to_return(body: JSON.generate(make_product))
|
name: "My Product"
|
||||||
p = Stripe::Product.new("test_product")
|
)
|
||||||
p.refresh
|
assert_requested :post, "#{Stripe.api_base}/v1/products"
|
||||||
|
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/products/#{p.id}").
|
|
||||||
with(body: { :description => "update" }).
|
|
||||||
to_return(body: JSON.generate(make_product))
|
|
||||||
p.description = "update"
|
|
||||||
p.save
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "products should be updateable" do
|
should "be saveable" do
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/products/test_product").
|
product = Stripe::Product.retrieve(FIXTURE[:id])
|
||||||
with(body: { :description => "update" }).
|
product.metadata['key'] = 'value'
|
||||||
to_return(body: JSON.generate(make_product))
|
product.save
|
||||||
_ = Stripe::Product.update("test_product", description: "update")
|
assert_requested :post, "#{Stripe.api_base}/v1/products/#{FIXTURE[:id]}"
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be updateable" do
|
||||||
|
product = Stripe::Product.update(FIXTURE[:id], metadata: {foo: 'bar'})
|
||||||
|
assert_requested :post, "#{Stripe.api_base}/v1/products/#{FIXTURE[:id]}"
|
||||||
|
assert product.kind_of?(Stripe::Product)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be deletable" do
|
||||||
|
product = Stripe::Product.retrieve(FIXTURE[:id])
|
||||||
|
product = product.delete
|
||||||
|
assert_requested :delete, "#{Stripe.api_base}/v1/products/#{FIXTURE[:id]}"
|
||||||
|
assert product.kind_of?(Stripe::Product)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2,55 +2,39 @@ require File.expand_path('../../test_helper', __FILE__)
|
|||||||
|
|
||||||
module Stripe
|
module Stripe
|
||||||
class RecipientCardTest < Test::Unit::TestCase
|
class RecipientCardTest < Test::Unit::TestCase
|
||||||
def recipient
|
FIXTURE = API_FIXTURES.fetch(:source)
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/recipients/test_recipient").
|
|
||||||
to_return(body: JSON.generate(make_recipient))
|
setup do
|
||||||
Stripe::Recipient.retrieve('test_recipient')
|
@recipient =
|
||||||
|
Stripe::Recipient.retrieve(API_FIXTURES.fetch(:transfer_recipient)[:id])
|
||||||
end
|
end
|
||||||
|
|
||||||
should "recipient cards should be listable" do
|
should "be listable" do
|
||||||
c = recipient
|
cards = @recipient.cards.list
|
||||||
|
assert cards.data.kind_of?(Array)
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/recipients/#{c.id}/cards").
|
assert cards.data[0].kind_of?(Stripe::Token)
|
||||||
to_return(body: JSON.generate(make_recipient_card_array(recipient.id)))
|
|
||||||
cards = c.cards.list.data
|
|
||||||
assert cards.kind_of? Array
|
|
||||||
assert cards[0].kind_of? Stripe::Card
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "recipient cards should be deletable" do
|
should "be creatable" do
|
||||||
c = recipient
|
card = @recipient.cards.create(
|
||||||
|
card: API_FIXTURES.fetch(:token)[:id]
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/recipients/#{c.id}/cards/card").
|
)
|
||||||
to_return(body: JSON.generate(make_card(:recipient => 'test_recipient')))
|
assert_requested :post, "#{Stripe.api_base}/v1/recipients/#{@recipient.id}/cards"
|
||||||
card = c.cards.retrieve('card')
|
assert card.kind_of?(Stripe::Token)
|
||||||
|
|
||||||
stub_request(:delete, "#{Stripe.api_base}/v1/recipients/#{card.recipient}/cards/#{card.id}").
|
|
||||||
to_return(body: JSON.generate(make_card(:deleted => true)))
|
|
||||||
_ = card.delete
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "recipient cards should be updateable" do
|
should "be deletable" do
|
||||||
c = recipient
|
card = Stripe::Card.construct_from(FIXTURE.merge(recipient: @recipient.id))
|
||||||
|
card = card.delete
|
||||||
|
assert_requested :delete, "#{Stripe.api_base}/v1/recipients/#{@recipient.id}/cards/#{FIXTURE[:id]}"
|
||||||
|
assert card.kind_of?(Stripe::Card)
|
||||||
|
end
|
||||||
|
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/recipients/#{c.id}/cards/card").
|
should "be saveable" do
|
||||||
to_return(body: JSON.generate(make_card(:recipient => 'test_recipient')))
|
card = Stripe::Card.construct_from(FIXTURE.merge(recipient: @recipient.id))
|
||||||
card = c.cards.retrieve('card')
|
card.metadata['key'] = 'value'
|
||||||
|
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/recipients/#{card.recipient}/cards/#{card.id}").
|
|
||||||
with(body: { exp_year: "2100" }).
|
|
||||||
to_return(body: JSON.generate(make_card))
|
|
||||||
card.exp_year = "2100"
|
|
||||||
card.save
|
card.save
|
||||||
end
|
assert_requested :post, "#{Stripe.api_base}/v1/recipients/#{@recipient.id}/cards/#{FIXTURE[:id]}"
|
||||||
|
|
||||||
should "create should return a new recipient card" do
|
|
||||||
c = recipient
|
|
||||||
|
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/recipients/#{c.id}/cards").
|
|
||||||
with(body: { card: "tok_41YJ05ijAaWaFS" }).
|
|
||||||
to_return(body: JSON.generate(make_card))
|
|
||||||
_ = c.cards.create(:card => "tok_41YJ05ijAaWaFS")
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2,17 +2,48 @@ require File.expand_path('../../test_helper', __FILE__)
|
|||||||
|
|
||||||
module Stripe
|
module Stripe
|
||||||
class RecipientTest < Test::Unit::TestCase
|
class RecipientTest < Test::Unit::TestCase
|
||||||
should "recipient should be retrievable" do
|
FIXTURE = API_FIXTURES.fetch(:transfer_recipient)
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/recipients/test_recipient").
|
|
||||||
to_return(body: JSON.generate(make_recipient))
|
should "be listable" do
|
||||||
_ = Stripe::Recipient.retrieve('test_recipient')
|
recipients = Stripe::Recipient.list
|
||||||
|
assert_requested :get, "#{Stripe.api_base}/v1/recipients"
|
||||||
|
assert recipients.data.kind_of?(Array)
|
||||||
|
assert recipients.data[0].kind_of?(Stripe::Recipient)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "recipient should be updateable" do
|
should "be retrievable" do
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/recipients/test_recipient").
|
recipient = Stripe::Recipient.retrieve(FIXTURE[:id])
|
||||||
with(body: { metadata: { key: "value" } }).
|
assert_requested :get, "#{Stripe.api_base}/v1/recipients/#{FIXTURE[:id]}"
|
||||||
to_return(body: JSON.generate(make_refund))
|
assert recipient.kind_of?(Stripe::Recipient)
|
||||||
_ = Stripe::Recipient.update('test_recipient', metadata: { key: 'value' })
|
end
|
||||||
|
|
||||||
|
should "be creatable" do
|
||||||
|
recipient = Stripe::Recipient.create(
|
||||||
|
name: "Noah Jackson",
|
||||||
|
type: "individual"
|
||||||
|
)
|
||||||
|
assert_requested :post, "#{Stripe.api_base}/v1/recipients"
|
||||||
|
assert recipient.kind_of?(Stripe::Recipient)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be saveable" do
|
||||||
|
recipient = Stripe::Recipient.retrieve(FIXTURE[:id])
|
||||||
|
recipient.metadata['key'] = 'value'
|
||||||
|
recipient.save
|
||||||
|
assert_requested :post, "#{Stripe.api_base}/v1/recipients/#{FIXTURE[:id]}"
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be updateable" do
|
||||||
|
recipient = Stripe::Recipient.update(FIXTURE[:id], metadata: {foo: 'bar'})
|
||||||
|
assert_requested :post, "#{Stripe.api_base}/v1/recipients/#{FIXTURE[:id]}"
|
||||||
|
assert recipient.kind_of?(Stripe::Recipient)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be deletable" do
|
||||||
|
recipient = Stripe::Recipient.retrieve(FIXTURE[:id])
|
||||||
|
recipient = recipient.delete
|
||||||
|
assert_requested :delete, "#{Stripe.api_base}/v1/recipients/#{FIXTURE[:id]}"
|
||||||
|
assert recipient.kind_of?(Stripe::Recipient)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2,37 +2,38 @@ require File.expand_path('../../test_helper', __FILE__)
|
|||||||
|
|
||||||
module Stripe
|
module Stripe
|
||||||
class RefundTest < Test::Unit::TestCase
|
class RefundTest < Test::Unit::TestCase
|
||||||
should "refunds should be listable" do
|
FIXTURE = API_FIXTURES.fetch(:refund)
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/refunds").
|
|
||||||
to_return(body: JSON.generate(make_refund_array))
|
should "be listable" do
|
||||||
refunds = Stripe::Refund.list
|
refunds = Stripe::Refund.list
|
||||||
|
assert_requested :get, "#{Stripe.api_base}/v1/refunds"
|
||||||
|
assert refunds.data.kind_of?(Array)
|
||||||
assert refunds.first.kind_of?(Stripe::Refund)
|
assert refunds.first.kind_of?(Stripe::Refund)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "refunds should be saveable" do
|
should "be retrievable" do
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/refunds/get_refund").
|
refund = Stripe::Refund.retrieve(FIXTURE[:id])
|
||||||
to_return(body: JSON.generate(make_refund))
|
assert_requested :get, "#{Stripe.api_base}/v1/refunds/#{FIXTURE[:id]}"
|
||||||
refund = Stripe::Refund.retrieve('get_refund')
|
assert refund.kind_of?(Stripe::Refund)
|
||||||
|
end
|
||||||
|
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/refunds/#{refund.id}").
|
should "be creatable" do
|
||||||
with(body: { metadata: { key: "value" } }).
|
refund = Stripe::Refund.create(:charge => API_FIXTURES[:charge][:id])
|
||||||
to_return(body: JSON.generate(make_refund))
|
assert_requested :post, "#{Stripe.api_base}/v1/refunds"
|
||||||
|
assert refund.kind_of?(Stripe::Refund)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be saveable" do
|
||||||
|
refund = Stripe::Refund.retrieve(FIXTURE[:id])
|
||||||
refund.metadata['key'] = 'value'
|
refund.metadata['key'] = 'value'
|
||||||
refund.save
|
refund.save
|
||||||
|
assert_requested :post, "#{Stripe.api_base}/v1/refunds/#{FIXTURE[:id]}"
|
||||||
end
|
end
|
||||||
|
|
||||||
should "refunds should be updateable" do
|
should "be updateable" do
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/refunds/update_refund").
|
refund = Stripe::Refund.update(FIXTURE[:id], metadata: { key: 'value' })
|
||||||
with(body: { metadata: { key: "value" } }).
|
assert_requested :post, "#{Stripe.api_base}/v1/refunds/#{FIXTURE[:id]}"
|
||||||
to_return(body: JSON.generate(make_refund))
|
assert refund.kind_of?(Stripe::Refund)
|
||||||
_ = Stripe::Refund.update('update_refund', metadata: { key: 'value' })
|
|
||||||
end
|
|
||||||
|
|
||||||
should "create should return a new refund" do
|
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/refunds").
|
|
||||||
with(body: { charge: "test_charge" }).
|
|
||||||
to_return(body: JSON.generate(make_refund))
|
|
||||||
_ = Stripe::Refund.create(:charge => 'test_charge')
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2,35 +2,42 @@ require File.expand_path('../../test_helper', __FILE__)
|
|||||||
|
|
||||||
module Stripe
|
module Stripe
|
||||||
class ReversalTest < Test::Unit::TestCase
|
class ReversalTest < Test::Unit::TestCase
|
||||||
should "reversals should be listable" do
|
FIXTURE = API_FIXTURES.fetch(:transfer_reversal)
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/transfers/test_transfer").
|
|
||||||
to_return(body: JSON.generate(make_transfer))
|
setup do
|
||||||
transfer = Stripe::Transfer.retrieve('test_transfer')
|
@transfer = Stripe::Transfer.retrieve(API_FIXTURES.fetch(:transfer)[:id])
|
||||||
assert transfer.reversals.first.kind_of?(Stripe::Reversal)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "reversals should be updateable" do
|
should "be listable" do
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/transfers/test_transfer").
|
reversals = @transfer.reversals.list
|
||||||
to_return(body: JSON.generate(make_transfer))
|
assert_requested :get,
|
||||||
transfer = Stripe::Transfer.retrieve('test_transfer')
|
"#{Stripe.api_base}/v1/transfers/#{@transfer.id}/reversals"
|
||||||
reversal = transfer.reversals.first
|
assert reversals.data.kind_of?(Array)
|
||||||
|
assert reversals.data[0].kind_of?(Stripe::Reversal)
|
||||||
|
end
|
||||||
|
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/transfers/#{transfer.id}/reversals/#{reversal.id}").
|
should "be retrievable" do
|
||||||
with(body: { metadata: { key: "value" } }).
|
reversal = @transfer.reversals.retrieve(FIXTURE[:id])
|
||||||
to_return(body: JSON.generate(make_reversal))
|
assert_requested :get,
|
||||||
|
"#{Stripe.api_base}/v1/transfers/#{@transfer.id}/reversals/#{FIXTURE[:id]}"
|
||||||
|
assert reversal.kind_of?(Stripe::Reversal)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be creatable" do
|
||||||
|
reversal = @transfer.reversals.create(
|
||||||
|
amount: 100
|
||||||
|
)
|
||||||
|
assert_requested :post,
|
||||||
|
"#{Stripe.api_base}/v1/transfers/#{@transfer.id}/reversals"
|
||||||
|
assert reversal.kind_of?(Stripe::Reversal)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be saveable" do
|
||||||
|
reversal = @transfer.reversals.retrieve(FIXTURE[:id])
|
||||||
reversal.metadata['key'] = 'value'
|
reversal.metadata['key'] = 'value'
|
||||||
reversal.save
|
reversal.save
|
||||||
end
|
assert_requested :post,
|
||||||
|
"#{Stripe.api_base}/v1/transfers/#{@transfer.id}/reversals/#{FIXTURE[:id]}"
|
||||||
should "create should return a new reversal" do
|
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/transfers/test_transfer").
|
|
||||||
to_return(body: JSON.generate(make_transfer))
|
|
||||||
transfer = Stripe::Transfer.retrieve('test_transfer')
|
|
||||||
|
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/transfers/#{transfer.id}/reversals").
|
|
||||||
with(body: { amount: "20" }).
|
|
||||||
to_return(body: JSON.generate(make_reversal))
|
|
||||||
_ = transfer.reversals.create(:amount => 20)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2,32 +2,49 @@ require File.expand_path('../../test_helper', __FILE__)
|
|||||||
|
|
||||||
module Stripe
|
module Stripe
|
||||||
class SKUTest < Test::Unit::TestCase
|
class SKUTest < Test::Unit::TestCase
|
||||||
should "SKUs should be listable" do
|
FIXTURE = API_FIXTURES.fetch(:sku)
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/skus").
|
|
||||||
to_return(body: JSON.generate(make_sku_array("test_product")))
|
should "be listable" do
|
||||||
skus = Stripe::SKU.list
|
skus = Stripe::SKU.list
|
||||||
assert skus.data.kind_of? Array
|
assert_requested :get, "#{Stripe.api_base}/v1/skus"
|
||||||
skus.each do |sku|
|
assert skus.data.kind_of?(Array)
|
||||||
assert sku.kind_of?(Stripe::SKU)
|
assert skus.data[0].kind_of?(Stripe::SKU)
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "SKUs should be updateable" do
|
should "be retrievable" do
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/skus/test_sku").
|
sku = Stripe::SKU.retrieve(FIXTURE[:id])
|
||||||
with(body: { metadata: { foo: "bar" } }).
|
assert_requested :get, "#{Stripe.api_base}/v1/skus/#{FIXTURE[:id]}"
|
||||||
to_return(body: JSON.generate(make_sku))
|
assert sku.kind_of?(Stripe::SKU)
|
||||||
_ = Stripe::SKU.update("test_sku", metadata: {foo: 'bar'})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "SKUs should be deletable" do
|
should "be creatable" do
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/skus/test_sku").
|
_ = Stripe::SKU.create(
|
||||||
to_return(body: JSON.generate(make_sku))
|
currency: "USD",
|
||||||
s = Stripe::SKU.retrieve("test_sku")
|
inventory: { type: "finite", quantity: 500 },
|
||||||
|
price: 100,
|
||||||
stub_request(:delete, "#{Stripe.api_base}/v1/skus/#{s.id}").
|
product: API_FIXTURES.fetch(:product)[:id]
|
||||||
to_return(body: JSON.generate(make_sku(:deleted => true)))
|
)
|
||||||
s.delete
|
assert_requested :post, "#{Stripe.api_base}/v1/skus"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "be saveable" do
|
||||||
|
sku = Stripe::SKU.retrieve(FIXTURE[:id])
|
||||||
|
sku.metadata['key'] = 'value'
|
||||||
|
sku.save
|
||||||
|
assert_requested :post, "#{Stripe.api_base}/v1/skus/#{FIXTURE[:id]}"
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be updateable" do
|
||||||
|
sku = Stripe::SKU.update(FIXTURE[:id], metadata: {foo: 'bar'})
|
||||||
|
assert_requested :post, "#{Stripe.api_base}/v1/skus/#{FIXTURE[:id]}"
|
||||||
|
assert sku.kind_of?(Stripe::SKU)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be deletable" do
|
||||||
|
sku = Stripe::SKU.retrieve(FIXTURE[:id])
|
||||||
|
sku = sku.delete
|
||||||
|
assert_requested :delete, "#{Stripe.api_base}/v1/skus/#{FIXTURE[:id]}"
|
||||||
|
assert sku.kind_of?(Stripe::SKU)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2,66 +2,42 @@ require File.expand_path('../../test_helper', __FILE__)
|
|||||||
|
|
||||||
module Stripe
|
module Stripe
|
||||||
class SourceTest < Test::Unit::TestCase
|
class SourceTest < Test::Unit::TestCase
|
||||||
should 'be creatable' do
|
FIXTURE = API_FIXTURES.fetch(:source)
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/sources").
|
|
||||||
with(body: { type: 'card', token: 'tok_test' }).
|
should "be retrievable" do
|
||||||
to_return(body: JSON.generate(make_source_card))
|
source = Stripe::Source.retrieve(FIXTURE[:id])
|
||||||
_ = Stripe::Source.create(
|
assert_requested :get, "#{Stripe.api_base}/v1/sources/#{FIXTURE[:id]}"
|
||||||
|
assert source.kind_of?(Stripe::Source)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "be creatable" do
|
||||||
|
source = Stripe::Source.create(
|
||||||
type: 'card',
|
type: 'card',
|
||||||
token: 'tok_test',
|
token: API_FIXTURES.fetch(:token)[:id]
|
||||||
)
|
)
|
||||||
|
assert_requested :post, "#{Stripe.api_base}/v1/sources"
|
||||||
|
assert source.kind_of?(Stripe::Card)
|
||||||
end
|
end
|
||||||
|
|
||||||
should 'be retrievable' do
|
should "be saveable" do
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/sources/source_test_card").
|
source = Stripe::Source.retrieve(FIXTURE[:id])
|
||||||
to_return(body: JSON.generate(make_source_card))
|
source.metadata['key'] = 'value'
|
||||||
_ = Stripe::Source.retrieve('source_test_card')
|
|
||||||
end
|
|
||||||
|
|
||||||
should 'be updatable' do
|
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/sources/source_test_card").
|
|
||||||
with(body: { metadata: { foo: "bar" } }).
|
|
||||||
to_return(body: JSON.generate(make_source_card))
|
|
||||||
_ = Stripe::Source.update('source_test_card', metadata: {foo: 'bar'})
|
|
||||||
end
|
|
||||||
|
|
||||||
should 'be saveable' do
|
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/sources/source_test_card").
|
|
||||||
to_return(body: JSON.generate(make_source_card))
|
|
||||||
source = Stripe::Source.retrieve('source_test_card')
|
|
||||||
|
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/sources/#{source.id}").
|
|
||||||
with(body: { metadata: { foo: "bar" } }).
|
|
||||||
to_return(body: JSON.generate(make_source_card))
|
|
||||||
source.metadata['foo'] = 'bar'
|
|
||||||
source.save
|
source.save
|
||||||
|
assert_requested :post, "#{Stripe.api_base}/v1/sources/#{FIXTURE[:id]}"
|
||||||
end
|
end
|
||||||
|
|
||||||
should 'not be deletable' do
|
should "be updateable" do
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/sources/source_test_card").
|
source = Stripe::Source.update(FIXTURE[:id], metadata: {foo: 'bar'})
|
||||||
to_return(body: JSON.generate(make_source_card))
|
assert_requested :post, "#{Stripe.api_base}/v1/sources/#{FIXTURE[:id]}"
|
||||||
source = Stripe::Source.retrieve('source_test_card')
|
assert source.kind_of?(Stripe::Card)
|
||||||
|
end
|
||||||
|
|
||||||
assert_raises NoMethodError do
|
context "#verify" do
|
||||||
source.delete
|
should "verify the source" do
|
||||||
|
source = Stripe::Source.retrieve(FIXTURE[:id])
|
||||||
|
source = source.verify(:values => [1,2])
|
||||||
|
assert source.kind_of?(Stripe::Source)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
should 'not be listable' do
|
|
||||||
assert_raises NoMethodError do
|
|
||||||
Stripe::Source.list
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
should 'be verifiable' do
|
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/sources/source_test_card").
|
|
||||||
to_return(body: JSON.generate(make_source_card))
|
|
||||||
source = Stripe::Source.retrieve('source_test_card')
|
|
||||||
|
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/sources/#{source.id}/verify").
|
|
||||||
with(body: { amounts: ["1", "2"] }).
|
|
||||||
to_return(body: JSON.generate(make_source_card))
|
|
||||||
source.verify(:amounts => [1,2])
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -121,7 +121,7 @@ module Stripe
|
|||||||
should "support literal headers" do
|
should "support literal headers" do
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/account").
|
stub_request(:post, "#{Stripe.api_base}/v1/account").
|
||||||
with(headers: { "Stripe-Account" => "bar" }).
|
with(headers: { "Stripe-Account" => "bar" }).
|
||||||
to_return(body: JSON.generate(make_account))
|
to_return(body: JSON.generate(API_FIXTURES.fetch(:account)))
|
||||||
|
|
||||||
client = StripeClient.new
|
client = StripeClient.new
|
||||||
client.execute_request(:post, '/v1/account',
|
client.execute_request(:post, '/v1/account',
|
||||||
@ -132,7 +132,7 @@ module Stripe
|
|||||||
should "support RestClient-style header keys" do
|
should "support RestClient-style header keys" do
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/account").
|
stub_request(:post, "#{Stripe.api_base}/v1/account").
|
||||||
with(headers: { "Stripe-Account" => "bar" }).
|
with(headers: { "Stripe-Account" => "bar" }).
|
||||||
to_return(body: JSON.generate(make_account))
|
to_return(body: JSON.generate(API_FIXTURES.fetch(:account)))
|
||||||
|
|
||||||
client = StripeClient.new
|
client = StripeClient.new
|
||||||
client.execute_request(:post, '/v1/account',
|
client.execute_request(:post, '/v1/account',
|
||||||
@ -147,7 +147,7 @@ module Stripe
|
|||||||
|
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/account").
|
stub_request(:post, "#{Stripe.api_base}/v1/account").
|
||||||
with(headers: {"Stripe-Account" => Stripe.stripe_account}).
|
with(headers: {"Stripe-Account" => Stripe.stripe_account}).
|
||||||
to_return(body: JSON.generate(make_account))
|
to_return(body: JSON.generate(API_FIXTURES.fetch(:account)))
|
||||||
|
|
||||||
client = StripeClient.new
|
client = StripeClient.new
|
||||||
client.execute_request(:post, '/v1/account')
|
client.execute_request(:post, '/v1/account')
|
||||||
@ -157,7 +157,7 @@ module Stripe
|
|||||||
stripe_account = "acct_0000"
|
stripe_account = "acct_0000"
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/account").
|
stub_request(:post, "#{Stripe.api_base}/v1/account").
|
||||||
with(headers: {"Stripe-Account" => stripe_account}).
|
with(headers: {"Stripe-Account" => stripe_account}).
|
||||||
to_return(body: JSON.generate(make_account))
|
to_return(body: JSON.generate(API_FIXTURES.fetch(:account)))
|
||||||
|
|
||||||
client = StripeClient.new
|
client = StripeClient.new
|
||||||
client.execute_request(:post, '/v1/account',
|
client.execute_request(:post, '/v1/account',
|
||||||
@ -169,7 +169,7 @@ module Stripe
|
|||||||
stub_request(:post, "#{Stripe.api_base}/v1/account").
|
stub_request(:post, "#{Stripe.api_base}/v1/account").
|
||||||
with { |req|
|
with { |req|
|
||||||
req.headers["Stripe-Account"].nil?
|
req.headers["Stripe-Account"].nil?
|
||||||
}.to_return(body: JSON.generate(make_charge))
|
}.to_return(body: JSON.generate(API_FIXTURES.fetch(:account)))
|
||||||
|
|
||||||
client = StripeClient.new
|
client = StripeClient.new
|
||||||
client.execute_request(:post, '/v1/account')
|
client.execute_request(:post, '/v1/account')
|
||||||
@ -287,30 +287,30 @@ module Stripe
|
|||||||
|
|
||||||
should 'not add an idempotency key to GET requests' do
|
should 'not add an idempotency key to GET requests' do
|
||||||
SecureRandom.expects(:uuid).times(0)
|
SecureRandom.expects(:uuid).times(0)
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/charges").
|
stub_request(:get, "#{Stripe.api_base}/v1/charges/#{API_FIXTURES.fetch(:charge)[:id]}").
|
||||||
with { |req|
|
with { |req|
|
||||||
req.headers['Idempotency-Key'].nil?
|
req.headers['Idempotency-Key'].nil?
|
||||||
}.to_return(body: JSON.generate(make_charge_array))
|
}.to_return(body: JSON.generate(API_FIXTURES.fetch(:charge)))
|
||||||
client = StripeClient.new
|
client = StripeClient.new
|
||||||
client.execute_request(:get, '/v1/charges')
|
client.execute_request(:get, "/v1/charges/#{API_FIXTURES.fetch(:charge)[:id]}")
|
||||||
end
|
end
|
||||||
|
|
||||||
should 'ensure there is always an idempotency_key on POST requests' do
|
should 'ensure there is always an idempotency_key on POST requests' do
|
||||||
SecureRandom.expects(:uuid).at_least_once.returns("random_key")
|
SecureRandom.expects(:uuid).at_least_once.returns("random_key")
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/charges").
|
stub_request(:post, "#{Stripe.api_base}/v1/charges").
|
||||||
with(headers: {"Idempotency-Key" => "random_key"}).
|
with(headers: {"Idempotency-Key" => "random_key"}).
|
||||||
to_return(body: JSON.generate(make_charge))
|
to_return(body: JSON.generate(API_FIXTURES.fetch(:charge)))
|
||||||
client = StripeClient.new
|
client = StripeClient.new
|
||||||
client.execute_request(:post, '/v1/charges')
|
client.execute_request(:post, "/v1/charges")
|
||||||
end
|
end
|
||||||
|
|
||||||
should 'ensure there is always an idempotency_key on DELETE requests' do
|
should 'ensure there is always an idempotency_key on DELETE requests' do
|
||||||
SecureRandom.expects(:uuid).at_least_once.returns("random_key")
|
SecureRandom.expects(:uuid).at_least_once.returns("random_key")
|
||||||
stub_request(:delete, "#{Stripe.api_base}/v1/charges").
|
stub_request(:delete, "#{Stripe.api_base}/v1/charges/#{API_FIXTURES.fetch(:charge)[:id]}").
|
||||||
with(headers: {"Idempotency-Key" => "random_key"}).
|
with(headers: {"Idempotency-Key" => "random_key"}).
|
||||||
to_return(body: JSON.generate(make_charge))
|
to_return(body: JSON.generate(API_FIXTURES.fetch(:charge)))
|
||||||
client = StripeClient.new
|
client = StripeClient.new
|
||||||
client.execute_request(:delete, '/v1/charges')
|
client.execute_request(:delete, "/v1/charges/#{API_FIXTURES.fetch(:charge)[:id]}")
|
||||||
end
|
end
|
||||||
|
|
||||||
should 'not override a provided idempotency_key' do
|
should 'not override a provided idempotency_key' do
|
||||||
@ -322,10 +322,10 @@ module Stripe
|
|||||||
# expected.
|
# expected.
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/charges").
|
stub_request(:post, "#{Stripe.api_base}/v1/charges").
|
||||||
with(headers: {"Idempotency-Key" => "provided_key"}).
|
with(headers: {"Idempotency-Key" => "provided_key"}).
|
||||||
to_return(body: JSON.generate(make_charge))
|
to_return(body: JSON.generate(API_FIXTURES.fetch(:charge)))
|
||||||
|
|
||||||
client = StripeClient.new
|
client = StripeClient.new
|
||||||
client.execute_request(:post, '/v1/charges',
|
client.execute_request(:post, "/v1/charges",
|
||||||
headers: {:idempotency_key => 'provided_key'})
|
headers: {:idempotency_key => 'provided_key'})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -370,7 +370,7 @@ module Stripe
|
|||||||
context "#request" do
|
context "#request" do
|
||||||
should "return a result and response object" do
|
should "return a result and response object" do
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/charges").
|
stub_request(:post, "#{Stripe.api_base}/v1/charges").
|
||||||
to_return(body: JSON.generate(make_charge))
|
to_return(body: JSON.generate(API_FIXTURES.fetch(:charge)))
|
||||||
|
|
||||||
client = StripeClient.new
|
client = StripeClient.new
|
||||||
charge, resp = client.request { Charge.create }
|
charge, resp = client.request { Charge.create }
|
||||||
|
|||||||
@ -116,9 +116,13 @@ module Stripe
|
|||||||
|
|
||||||
# customer comes with a `sources` list that makes a convenient object to
|
# customer comes with a `sources` list that makes a convenient object to
|
||||||
# perform tests on
|
# perform tests on
|
||||||
customer = Stripe::Customer.construct_from(make_customer, opts)
|
obj = Stripe::StripeObject.construct_from({
|
||||||
|
sources: [
|
||||||
|
{}
|
||||||
|
]
|
||||||
|
}, opts)
|
||||||
|
|
||||||
source = customer.sources.first
|
source = obj.sources.first
|
||||||
# Pulling `@opts` as an instance variable here is not ideal, but it's
|
# Pulling `@opts` as an instance variable here is not ideal, but it's
|
||||||
# important enough argument that the test here is worth it. we should
|
# important enough argument that the test here is worth it. we should
|
||||||
# consider exposing it publicly on a future pull (and possibly renaming
|
# consider exposing it publicly on a future pull (and possibly renaming
|
||||||
|
|||||||
@ -2,62 +2,53 @@ require File.expand_path('../../test_helper', __FILE__)
|
|||||||
|
|
||||||
module Stripe
|
module Stripe
|
||||||
class SubscriptionItemTest < Test::Unit::TestCase
|
class SubscriptionItemTest < Test::Unit::TestCase
|
||||||
should "subscription items should be retrievable" do
|
FIXTURE = API_FIXTURES.fetch(:subscription_item)
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/subscription_items/si_test_subscription_item").
|
|
||||||
to_return(body: JSON.generate(make_subscription_item))
|
|
||||||
sub_item = Stripe::SubscriptionItem.retrieve('si_test_subscription_item')
|
|
||||||
|
|
||||||
assert sub_item.kind_of?(Stripe::SubscriptionItem)
|
should "be listable" do
|
||||||
|
items = Stripe::SubscriptionItem.list(
|
||||||
|
subscription: API_FIXTURES.fetch(:subscription)[:id]
|
||||||
|
)
|
||||||
|
assert_requested :get, "#{Stripe.api_base}/v1/subscription_items",
|
||||||
|
query: { subscription: API_FIXTURES.fetch(:subscription)[:id] }
|
||||||
|
assert items.data.kind_of?(Array)
|
||||||
|
assert items.data[0].kind_of?(Stripe::SubscriptionItem)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "subscription items should be listable" do
|
should "be retrievable" do
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/subscription_items").
|
item = Stripe::SubscriptionItem.retrieve(FIXTURE[:id])
|
||||||
with(query: { subscription: "s_test_subscription", limit: "3" }).
|
assert_requested :get, "#{Stripe.api_base}/v1/subscription_items/#{FIXTURE[:id]}"
|
||||||
to_return(body: JSON.generate(make_subscription_item_array))
|
assert item.kind_of?(Stripe::SubscriptionItem)
|
||||||
sub_items = Stripe::SubscriptionItem.list(:subscription => 's_test_subscription', :limit => 3).data
|
|
||||||
|
|
||||||
assert sub_items.kind_of? Array
|
|
||||||
assert sub_items[0].kind_of? Stripe::SubscriptionItem
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "subscription items should be deletable" do
|
should "be creatable" do
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/subscription_items/si_test_subscription_item").
|
item = Stripe::SubscriptionItem.create(
|
||||||
to_return(body: JSON.generate(make_subscription_item))
|
item: 'silver',
|
||||||
sub_item = Stripe::SubscriptionItem.retrieve('si_test_subscription_item')
|
plan: API_FIXTURES.fetch(:plan)[:id],
|
||||||
|
quantity: 3,
|
||||||
stub_request(:delete, "#{Stripe.api_base}/v1/subscription_items/#{sub_item.id}").
|
subscription: API_FIXTURES.fetch(:subscription)[:id]
|
||||||
to_return(body: JSON.generate(make_subscription_item))
|
)
|
||||||
sub_item.delete
|
assert_requested :post, "#{Stripe.api_base}/v1/subscription_items"
|
||||||
|
assert item.kind_of?(Stripe::SubscriptionItem)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "subscription items should be updateable" do
|
should "be saveable" do
|
||||||
sid = 'si_test_subscription_item'
|
item = Stripe::SubscriptionItem.retrieve(FIXTURE[:id])
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/subscription_items/#{sid}").
|
item.quantity = 4
|
||||||
with(body: { plan: "silver", quantity: "3" }).
|
item.save
|
||||||
to_return(body: JSON.generate(make_subscription_item))
|
assert_requested :post, "#{Stripe.api_base}/v1/subscription_items/#{FIXTURE[:id]}"
|
||||||
|
|
||||||
_ = Stripe::SubscriptionItem.update(sid, {:plan => 'silver', :quantity => 3})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "subscription items should be saveable" do
|
should "be updateable" do
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/subscription_items/si_test_subscription_item").
|
item = Stripe::SubscriptionItem.update(FIXTURE[:id], metadata: {foo: 'bar'})
|
||||||
to_return(body: JSON.generate(make_subscription_item))
|
assert_requested :post, "#{Stripe.api_base}/v1/subscription_items/#{FIXTURE[:id]}"
|
||||||
sub_item = Stripe::SubscriptionItem.retrieve('si_test_subscription_item')
|
assert item.kind_of?(Stripe::SubscriptionItem)
|
||||||
|
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/subscription_items/#{sub_item.id}").
|
|
||||||
with(body: { plan: "silver", quantity: "3" }).
|
|
||||||
to_return(body: JSON.generate(make_subscription_item))
|
|
||||||
sub_item.plan = 'silver'
|
|
||||||
sub_item.quantity = 3
|
|
||||||
sub_item.save
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "create should return a new subscription item" do
|
should "be deletable" do
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/subscription_items").
|
item = Stripe::SubscriptionItem.retrieve(FIXTURE[:id])
|
||||||
with(body: { plan: "silver", quantity: "3" }).
|
item = item.delete
|
||||||
to_return(body: JSON.generate(make_subscription_item))
|
assert_requested :delete, "#{Stripe.api_base}/v1/subscription_items/#{FIXTURE[:id]}"
|
||||||
|
assert item.kind_of?(Stripe::SubscriptionItem)
|
||||||
_ = Stripe::SubscriptionItem.create(:plan => 'silver', :quantity => 3)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2,136 +2,59 @@ require File.expand_path('../../test_helper', __FILE__)
|
|||||||
|
|
||||||
module Stripe
|
module Stripe
|
||||||
class SubscriptionTest < Test::Unit::TestCase
|
class SubscriptionTest < Test::Unit::TestCase
|
||||||
should "subscriptions should be retrievable by customer" do
|
FIXTURE = API_FIXTURES.fetch(:subscription)
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/customers/c_test_customer").
|
|
||||||
to_return(body: JSON.generate(make_customer))
|
|
||||||
customer = Stripe::Customer.retrieve('c_test_customer')
|
|
||||||
|
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/customers/c_test_customer/subscriptions/s_test_subscription").
|
should "be listable" do
|
||||||
to_return(body: JSON.generate(make_subscription))
|
subscriptions = Stripe::Subscription.list
|
||||||
_ = customer.subscriptions.retrieve('s_test_subscription')
|
assert_requested :get, "#{Stripe.api_base}/v1/subscriptions"
|
||||||
|
assert subscriptions.data.kind_of?(Array)
|
||||||
|
assert subscriptions.data[0].kind_of?(Stripe::Subscription)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "subscriptions should be listable by customer" do
|
should "be retrievable" do
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/customers/c_test_customer").
|
subscription = Stripe::Subscription.retrieve(FIXTURE[:id])
|
||||||
to_return(body: JSON.generate(make_customer))
|
assert_requested :get,
|
||||||
customer = Stripe::Customer.retrieve('c_test_customer')
|
"#{Stripe.api_base}/v1/subscriptions/#{FIXTURE[:id]}"
|
||||||
|
assert subscription.kind_of?(Stripe::Subscription)
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/customers/c_test_customer/subscriptions").
|
|
||||||
to_return(body: JSON.generate(make_customer_subscription_array('c_test_customer')))
|
|
||||||
subs = customer.subscriptions.list
|
|
||||||
|
|
||||||
assert subs.kind_of?(Stripe::ListObject)
|
|
||||||
assert subs.data.kind_of?(Array)
|
|
||||||
assert subs.data[0].kind_of? Stripe::Subscription
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "subscriptions should be creatable by customer" do
|
should "be creatable" do
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/customers/c_test_customer").
|
subscription = Stripe::Subscription.create(
|
||||||
to_return(body: JSON.generate(make_customer))
|
customer: API_FIXTURES.fetch(:customer)[:id]
|
||||||
customer = Stripe::Customer.retrieve('c_test_customer')
|
)
|
||||||
|
assert_requested :post, "#{Stripe.api_base}/v1/subscriptions"
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/customers/c_test_customer/subscriptions").
|
assert subscription.kind_of?(Stripe::Subscription)
|
||||||
with(body: { plan: "silver" }).
|
|
||||||
to_return(body: JSON.generate(make_subscription))
|
|
||||||
_ = customer.subscriptions.create(:plan => 'silver')
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "subscriptions should be retrievable" do
|
should "be saveable" do
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/subscriptions/s_test_subscription").
|
subscription = Stripe::Subscription.retrieve(FIXTURE[:id])
|
||||||
to_return(body: JSON.generate(make_subscription))
|
subscription.metadata['key'] = 'value'
|
||||||
sub = Stripe::Subscription.retrieve('s_test_subscription')
|
subscription.save
|
||||||
|
assert_requested :post,
|
||||||
assert sub.kind_of?(Stripe::Subscription)
|
"#{Stripe.api_base}/v1/subscriptions/#{FIXTURE[:id]}"
|
||||||
end
|
end
|
||||||
|
|
||||||
should "subscriptions should be listable" do
|
should "be updateable" do
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/subscriptions").
|
subscription = Stripe::Subscription.update(FIXTURE[:id], metadata: {foo: 'bar'})
|
||||||
to_return(body: JSON.generate(make_subscription_array))
|
assert_requested :post,
|
||||||
subs = Stripe::Subscription.list.data
|
"#{Stripe.api_base}/v1/subscriptions/#{FIXTURE[:id]}"
|
||||||
|
assert subscription.kind_of?(Stripe::Subscription)
|
||||||
assert subs.kind_of? Array
|
|
||||||
assert subs[0].kind_of? Stripe::Subscription
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "subscriptions should be listable with filters" do
|
should "be deletable" do
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/subscriptions").
|
subscription = Stripe::Subscription.retrieve(FIXTURE[:id])
|
||||||
with(query: { customer: "c_test_customer", limit: "3", plan: "gold" }).
|
subscription = subscription.delete
|
||||||
to_return(body: JSON.generate(make_subscription_array))
|
assert_requested :delete,
|
||||||
subs = Stripe::Subscription.all(:customer => 'c_test_customer', :limit => 3, :plan => 'gold')
|
"#{Stripe.api_base}/v1/subscriptions/#{FIXTURE[:id]}"
|
||||||
|
assert subscription.kind_of?(Stripe::Subscription)
|
||||||
assert subs.kind_of?(Stripe::ListObject)
|
|
||||||
assert subs.data.kind_of?(Array)
|
|
||||||
assert subs.data[0].kind_of? Stripe::Subscription
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "subscriptions should be refreshable" do
|
context "#delete_discount" do
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/subscriptions/s_test_subscription").
|
should "be able to delete a subscriptions's discount" do
|
||||||
to_return(body: JSON.generate(make_subscription))
|
subscription = Stripe::Subscription.retrieve(FIXTURE[:id])
|
||||||
sub = Stripe::Subscription.retrieve('s_test_subscription')
|
subscription = subscription.delete_discount
|
||||||
sub.refresh
|
assert subscription.kind_of?(Stripe::Subscription)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "subscriptions should be deletable" do
|
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/subscriptions/s_test_subscription").
|
|
||||||
to_return(body: JSON.generate(make_subscription))
|
|
||||||
sub = Stripe::Subscription.retrieve('s_test_subscription')
|
|
||||||
|
|
||||||
stub_request(:delete, "#{Stripe.api_base}/v1/subscriptions/#{sub.id}").
|
|
||||||
with(query: { at_period_end: "true" }).
|
|
||||||
to_return(body: JSON.generate(make_subscription))
|
|
||||||
sub.delete :at_period_end => true
|
|
||||||
|
|
||||||
stub_request(:delete, "#{Stripe.api_base}/v1/subscriptions/#{sub.id}").
|
|
||||||
to_return(body: JSON.generate(make_subscription))
|
|
||||||
sub.delete
|
|
||||||
end
|
|
||||||
|
|
||||||
should "subscriptions should be updateable" do
|
|
||||||
sid = 's_test_subscription'
|
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/subscriptions/#{sid}").
|
|
||||||
with(body: { status: "active" }).
|
|
||||||
to_return(body: JSON.generate(make_subscription))
|
|
||||||
_ = Stripe::Subscription.update(sid, :status => 'active')
|
|
||||||
end
|
|
||||||
|
|
||||||
should "subscription items should be updateable" do
|
|
||||||
sid = 's_test_subscription'
|
|
||||||
|
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/subscriptions/#{sid}").
|
|
||||||
with(body: { items: [{plan: "gold", quantity: "1"}, {plan: "silver", quantity: "2" }] }).
|
|
||||||
to_return(body: JSON.generate(make_subscription))
|
|
||||||
_ = Stripe::Subscription.update(sid, :items => [{:plan => 'gold', :quantity =>1}, {:plan => 'silver', :quantity =>2}])
|
|
||||||
end
|
|
||||||
|
|
||||||
should "subscriptions should be saveable" do
|
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/subscriptions/s_test_subscription").
|
|
||||||
to_return(body: JSON.generate(make_subscription))
|
|
||||||
sub = Stripe::Subscription.retrieve('s_test_subscription')
|
|
||||||
|
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/subscriptions/#{sub.id}").
|
|
||||||
with(body: { status: "active" }).
|
|
||||||
to_return(body: JSON.generate(make_subscription))
|
|
||||||
sub.status = 'active'
|
|
||||||
sub.save
|
|
||||||
end
|
|
||||||
|
|
||||||
should "create should return a new subscription" do
|
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/subscriptions").
|
|
||||||
with(body: { customer: "c_test_customer", plan: "gold" }).
|
|
||||||
to_return(body: JSON.generate(make_subscription))
|
|
||||||
_ = Stripe::Subscription.create(:plan => 'gold', :customer => 'c_test_customer')
|
|
||||||
end
|
|
||||||
|
|
||||||
should "be able to delete a subscriptions's discount" do
|
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/subscriptions").
|
|
||||||
to_return(body: JSON.generate(make_subscription))
|
|
||||||
sub = Stripe::Subscription.create(:plan => 'gold', :customer => 'c_test_customer', coupon: 'forever')
|
|
||||||
|
|
||||||
stub_request(:delete, "#{Stripe.api_base}/v1/subscriptions/#{sub.id}/discount").
|
|
||||||
to_return(body: JSON.generate(make_delete_discount_response))
|
|
||||||
sub.delete_discount
|
|
||||||
assert_equal nil, sub.discount
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2,23 +2,22 @@ require File.expand_path('../../test_helper', __FILE__)
|
|||||||
|
|
||||||
module Stripe
|
module Stripe
|
||||||
class ThreeDSecureTest < Test::Unit::TestCase
|
class ThreeDSecureTest < Test::Unit::TestCase
|
||||||
should "retrieve an existing 3D Secure object" do
|
FIXTURE = API_FIXTURES.fetch(:three_d_secure)
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/3d_secure/tdsrc_test").
|
|
||||||
to_return(body: JSON.generate(make_three_d_secure))
|
should "be retrievable" do
|
||||||
tds = Stripe::ThreeDSecure.retrieve("tdsrc_test")
|
secure = Stripe::ThreeDSecure.retrieve(FIXTURE[:id])
|
||||||
assert_equal "tdsrc_test", tds.id
|
assert_requested :get, "#{Stripe.api_base}/v1/3d_secure/#{FIXTURE[:id]}"
|
||||||
|
assert secure.kind_of?(Stripe::ThreeDSecure)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "create should return a new 3D Secure object" do
|
should "be creatable" do
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/3d_secure").
|
|
||||||
with(body: { card: "tok_test", amount: "1500", currency: "usd", return_url: "https://example.org/3d-secure-result" }).
|
|
||||||
to_return(body: JSON.generate(make_three_d_secure))
|
|
||||||
_ = Stripe::ThreeDSecure.create(
|
_ = Stripe::ThreeDSecure.create(
|
||||||
:card => "tok_test",
|
card: API_FIXTURES.fetch(:token)[:id],
|
||||||
:amount => 1500,
|
amount: 1500,
|
||||||
:currency => "usd",
|
currency: "usd",
|
||||||
:return_url => "https://example.org/3d-secure-result"
|
return_url: "https://example.org/3d-secure-result"
|
||||||
)
|
)
|
||||||
|
assert_requested :post, "#{Stripe.api_base}/v1/3d_secure"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2,35 +2,49 @@ require File.expand_path('../../test_helper', __FILE__)
|
|||||||
|
|
||||||
module Stripe
|
module Stripe
|
||||||
class TransferTest < Test::Unit::TestCase
|
class TransferTest < Test::Unit::TestCase
|
||||||
should "retrieve should retrieve transfer" do
|
FIXTURE = API_FIXTURES.fetch(:transfer)
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/transfers/tr_test_transfer").
|
|
||||||
to_return(body: JSON.generate(make_transfer))
|
should "be listable" do
|
||||||
transfer = Stripe::Transfer.retrieve('tr_test_transfer')
|
transfers = Stripe::Transfer.list
|
||||||
assert_equal 'tr_test_transfer', transfer.id
|
assert_requested :get, "#{Stripe.api_base}/v1/transfers"
|
||||||
|
assert transfers.data.kind_of?(Array)
|
||||||
|
assert transfers.data[0].kind_of?(Stripe::Transfer)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "create should create a transfer" do
|
should "be retrievable" do
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/transfers").
|
transfer = Stripe::Transfer.retrieve(FIXTURE[:id])
|
||||||
to_return(body: JSON.generate(make_transfer))
|
assert_requested :get, "#{Stripe.api_base}/v1/transfers/#{FIXTURE[:id]}"
|
||||||
transfer = Stripe::Transfer.create
|
assert transfer.kind_of?(Stripe::Transfer)
|
||||||
assert_equal "tr_test_transfer", transfer.id
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "create should update a transfer" do
|
should "be creatable" do
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/transfers/test_transfer").
|
transfer = Stripe::Transfer.create(
|
||||||
with(body: { metadata: { foo: "bar" } }).
|
amount: 100,
|
||||||
to_return(body: JSON.generate(make_transfer))
|
currency: "USD"
|
||||||
Stripe::Transfer.update("test_transfer", metadata: {foo: 'bar'})
|
)
|
||||||
|
assert_requested :post, "#{Stripe.api_base}/v1/transfers"
|
||||||
|
assert transfer.kind_of?(Stripe::Transfer)
|
||||||
end
|
end
|
||||||
|
|
||||||
should "cancel should cancel a transfer" do
|
should "be saveable" do
|
||||||
stub_request(:get, "#{Stripe.api_base}/v1/transfers/tr_test_transfer").
|
transfer = Stripe::Transfer.retrieve(FIXTURE[:id])
|
||||||
to_return(body: JSON.generate(make_transfer))
|
transfer.metadata['key'] = 'value'
|
||||||
transfer = Stripe::Transfer.retrieve('tr_test_transfer')
|
transfer.save
|
||||||
|
assert_requested :post, "#{Stripe.api_base}/v1/transfers/#{FIXTURE[:id]}"
|
||||||
|
end
|
||||||
|
|
||||||
stub_request(:post, "#{Stripe.api_base}/v1/transfers/tr_test_transfer/cancel").
|
should "be updateable" do
|
||||||
to_return(body: JSON.generate(make_canceled_transfer))
|
transfer = Stripe::Transfer.update(FIXTURE[:id], metadata: {foo: 'bar'})
|
||||||
transfer.cancel
|
assert_requested :post, "#{Stripe.api_base}/v1/transfers/#{FIXTURE[:id]}"
|
||||||
|
assert transfer.kind_of?(Stripe::Transfer)
|
||||||
|
end
|
||||||
|
|
||||||
|
context "#cancel" do
|
||||||
|
should "cancel a transfer" do
|
||||||
|
transfer = Stripe::Transfer.retrieve(FIXTURE[:id])
|
||||||
|
transfer = transfer.cancel
|
||||||
|
assert transfer.kind_of?(Stripe::Transfer)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user