mirror of
https://github.com/stripe/stripe-ruby.git
synced 2025-05-29 00:01:51 -04: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
|
||||
|
||||
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)}"
|
||||
else
|
||||
"#{self.class.resource_url}/#{CGI.escape(id)}"
|
||||
|
@ -1,7 +1,6 @@
|
||||
module Stripe
|
||||
class Dispute < APIResource
|
||||
extend Stripe::APIOperations::List
|
||||
extend Stripe::APIOperations::Create
|
||||
include Stripe::APIOperations::Save
|
||||
|
||||
def close(params={}, opts={})
|
||||
|
@ -1,7 +1,7 @@
|
||||
module Stripe
|
||||
class Reversal < APIResource
|
||||
include Stripe::APIOperations::Save
|
||||
extend Stripe::APIOperations::List
|
||||
include Stripe::APIOperations::Save
|
||||
|
||||
def resource_url
|
||||
"#{Transfer.resource_url}/#{CGI.escape(transfer)}/reversals/#{CGI.escape(id)}"
|
||||
|
@ -2,50 +2,25 @@ require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
module Stripe
|
||||
class AccountTest < Test::Unit::TestCase
|
||||
should "be retrievable" do
|
||||
resp = make_account({
|
||||
:charges_enabled => false,
|
||||
:details_submitted => false,
|
||||
:email => "test+bindings@stripe.com",
|
||||
})
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/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
|
||||
FIXTURE = API_FIXTURES.fetch(:account)
|
||||
|
||||
should "be listable" do
|
||||
accounts = Stripe::Account.list
|
||||
assert_requested :get, "#{Stripe.api_base}/v1/accounts"
|
||||
assert accounts.data.kind_of?(Array)
|
||||
assert accounts.data[0].kind_of?(Stripe::Account)
|
||||
end
|
||||
|
||||
should "be retrievable via plural endpoint" do
|
||||
resp = make_account({
|
||||
:charges_enabled => false,
|
||||
:details_submitted => false,
|
||||
: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
|
||||
should "be retrievable using singular endpoint" do
|
||||
account = Stripe::Account.retrieve
|
||||
assert_requested :get, "#{Stripe.api_base}/v1/account"
|
||||
assert account.kind_of?(Stripe::Account)
|
||||
end
|
||||
|
||||
should "be retrievable using an API key as the only argument" do
|
||||
account = mock
|
||||
Stripe::Account.expects(:new).once.with(nil, {:api_key => 'sk_foobar'}).returns(account)
|
||||
account.expects(:refresh).once
|
||||
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
|
||||
should "be retrievable using plural endpoint" do
|
||||
account = Stripe::Account.retrieve(FIXTURE[:id])
|
||||
assert_requested :get, "#{Stripe.api_base}/v1/accounts/#{FIXTURE[:id]}"
|
||||
assert account.kind_of?(Stripe::Account)
|
||||
end
|
||||
|
||||
should "be rejectable" do
|
||||
@ -60,210 +35,30 @@ module Stripe
|
||||
account.reject(:reason => 'fraud')
|
||||
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
|
||||
resp = {
|
||||
:id => 'acct_foo',
|
||||
:legal_entity => {
|
||||
:address => {
|
||||
: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
|
||||
account = Stripe::Account.retrieve(FIXTURE[:id])
|
||||
account.metadata['key'] = 'value'
|
||||
account.save
|
||||
assert_requested :post, "#{Stripe.api_base}/v1/accounts/#{FIXTURE[:id]}"
|
||||
end
|
||||
|
||||
should "be updatable" do
|
||||
resp = {
|
||||
:id => 'acct_foo',
|
||||
:business_name => 'ACME Corp',
|
||||
}
|
||||
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)
|
||||
should "be updateable" do
|
||||
account = Stripe::Account.update(FIXTURE[:id], metadata: {foo: 'bar'})
|
||||
assert_requested :post, "#{Stripe.api_base}/v1/accounts/#{FIXTURE[:id]}"
|
||||
assert account.kind_of?(Stripe::Account)
|
||||
end
|
||||
|
||||
should 'disallow direct overrides of legal_entity' do
|
||||
account = Stripe::Account.construct_from(make_account({
|
||||
:keys => {
|
||||
:publishable => 'publishable-key',
|
||||
:secret => 'secret-key',
|
||||
},
|
||||
: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)
|
||||
should "be deletable" do
|
||||
account = Stripe::Account.retrieve(FIXTURE[:id])
|
||||
account = account.delete
|
||||
assert_requested :delete, "#{Stripe.api_base}/v1/accounts/#{FIXTURE[:id]}"
|
||||
assert account.kind_of?(Stripe::Account)
|
||||
end
|
||||
|
||||
context "#bank_account=" do
|
||||
@ -271,8 +66,8 @@ module Stripe
|
||||
old_stderr = $stderr
|
||||
$stderr = StringIO.new
|
||||
begin
|
||||
a = Stripe::Account.new("test_account")
|
||||
a.bank_account = "tok_123"
|
||||
account = Stripe::Account.retrieve(FIXTURE[:id])
|
||||
account.bank_account = "tok_123"
|
||||
message = "NOTE: Stripe::Account#bank_account= is " +
|
||||
"deprecated; use #external_account= instead"
|
||||
assert_match Regexp.new(message), $stderr.string
|
||||
@ -281,5 +76,129 @@ module Stripe
|
||||
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
|
||||
|
@ -2,9 +2,17 @@ require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
module Stripe
|
||||
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
|
||||
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
|
||||
|
@ -76,7 +76,7 @@ module Stripe
|
||||
should "send expand on fetch properly" do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/charges/ch_test_charge").
|
||||
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]})
|
||||
end
|
||||
@ -84,7 +84,7 @@ module Stripe
|
||||
should "preserve expand across refreshes" do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/charges/ch_test_charge").
|
||||
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.refresh
|
||||
@ -92,11 +92,11 @@ module Stripe
|
||||
|
||||
should "send expand when fetching through ListObject" do
|
||||
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").
|
||||
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.sources.retrieve({:id => 'cc_test_card', :expand => [:customer]})
|
||||
@ -107,7 +107,7 @@ module Stripe
|
||||
should "use the per-object credential when creating" do
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/charges").
|
||||
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'}},
|
||||
'sk_test_local')
|
||||
@ -126,7 +126,7 @@ module Stripe
|
||||
should "use the per-object credential when creating" do
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/charges").
|
||||
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'}},
|
||||
'local')
|
||||
@ -135,10 +135,10 @@ module Stripe
|
||||
should "use the per-object credential when retrieving and making other calls" do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/charges/ch_test_charge").
|
||||
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").
|
||||
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.refunds.create
|
||||
@ -150,33 +150,40 @@ module Stripe
|
||||
should "urlencode values in GET params" do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/charges").
|
||||
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
|
||||
assert charges.kind_of? Array
|
||||
end
|
||||
|
||||
should "construct URL properly with base query parameters" do
|
||||
response = JSON.generate(make_invoice_customer_array)
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/invoices").
|
||||
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')
|
||||
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/invoices").
|
||||
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)
|
||||
end
|
||||
|
||||
should "setting a nil value for a param should exclude that param from the request" do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/charges").
|
||||
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)
|
||||
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/charges").
|
||||
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 })
|
||||
end
|
||||
|
||||
@ -195,27 +202,27 @@ module Stripe
|
||||
should "making a GET request with parameters should have a query string and no body" do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/charges").
|
||||
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 })
|
||||
end
|
||||
|
||||
should "making a POST request with parameters should have a body and no query string" do
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/charges").
|
||||
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' })
|
||||
end
|
||||
|
||||
should "loading an object should issue a GET request" do
|
||||
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.refresh
|
||||
end
|
||||
|
||||
should "using array accessors should be the same as the method interface" do
|
||||
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.refresh
|
||||
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
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/charges").
|
||||
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.charges
|
||||
end
|
||||
@ -235,8 +242,8 @@ module Stripe
|
||||
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").
|
||||
with(body: { 'description' => 'another_mn' }).
|
||||
to_return(body: JSON.generate(make_customer))
|
||||
c = Stripe::Customer.construct_from(make_customer)
|
||||
to_return(body: JSON.generate(API_FIXTURES.fetch(:customer)))
|
||||
c = Stripe::Customer.construct_from(API_FIXTURES.fetch(:customer))
|
||||
c.description = "another_mn"
|
||||
c.save
|
||||
end
|
||||
@ -244,7 +251,7 @@ module Stripe
|
||||
should "updating should merge in returned properties" do
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/customers/c_test_customer").
|
||||
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.description = "another_mn"
|
||||
c.save
|
||||
@ -261,7 +268,7 @@ module Stripe
|
||||
should "updating should use the supplied api_key" do
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/customers").
|
||||
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.save({}, { :api_key => 'sk_test_local' })
|
||||
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
|
||||
stub_request(:delete, "#{Stripe.api_base}/v1/customers/c_test_customer").
|
||||
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
|
||||
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
|
||||
|
||||
should "loading all of an APIResource should return an array of recursively instantiated objects" do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/charges").
|
||||
to_return(body: JSON.generate(make_charge_array))
|
||||
c = Stripe::Charge.list.data
|
||||
assert c.kind_of? Array
|
||||
assert c[0].kind_of? Stripe::Charge
|
||||
assert c[0].card.kind_of?(Stripe::StripeObject) && c[0].card.object == 'card'
|
||||
to_return(body: JSON.generate({
|
||||
data: [API_FIXTURES.fetch(:charge)]
|
||||
}))
|
||||
charges = Stripe::Charge.list.data
|
||||
assert charges.kind_of? Array
|
||||
assert charges[0].kind_of? Stripe::Charge
|
||||
assert charges[0].card.kind_of?(Stripe::StripeObject)
|
||||
end
|
||||
|
||||
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").
|
||||
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'})
|
||||
end
|
||||
|
||||
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").
|
||||
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'})
|
||||
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/customers/c_test_customer").
|
||||
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.save
|
||||
end
|
||||
|
@ -2,32 +2,32 @@ require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
module Stripe
|
||||
class ApplePayDomainTest < Test::Unit::TestCase
|
||||
should "create should return a new Apple Pay domain" do
|
||||
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
|
||||
FIXTURE = API_FIXTURES.fetch(:apple_pay_domain)
|
||||
|
||||
should "domains should be deletable" 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))
|
||||
should "be listable" do
|
||||
domains = Stripe::ApplePayDomain.list
|
||||
assert_requested :get, "#{Stripe.api_base}/v1/apple_pay/domains"
|
||||
assert domains.data.kind_of?(Array)
|
||||
assert_equal 3, domains.data.length
|
||||
domains.each do |domain|
|
||||
assert domain.kind_of?(Stripe::ApplePayDomain)
|
||||
end
|
||||
assert domains.data[0].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
|
||||
|
@ -2,43 +2,37 @@ require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
module Stripe
|
||||
class ApplicationFeeRefundTest < Test::Unit::TestCase
|
||||
should "refunds should be listable" do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/application_fees/test_application_fee").
|
||||
to_return(body: JSON.generate(make_application_fee))
|
||||
FIXTURE = API_FIXTURES.fetch(:fee_refund)
|
||||
|
||||
application_fee = Stripe::ApplicationFee.retrieve('test_application_fee')
|
||||
|
||||
assert application_fee.refunds.first.kind_of?(Stripe::ApplicationFeeRefund)
|
||||
setup do
|
||||
application_fee_fixture = API_FIXTURES.fetch(:platform_earning)
|
||||
@fee = Stripe::ApplicationFee.retrieve(application_fee_fixture[:id])
|
||||
end
|
||||
|
||||
should "refunds should be updateable" do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/application_fees/test_application_fee").
|
||||
to_return(body: JSON.generate(make_application_fee))
|
||||
should "be listable" do
|
||||
refunds = @fee.refunds
|
||||
|
||||
application_fee = Stripe::ApplicationFee.retrieve('test_application_fee')
|
||||
refund = application_fee.refunds.first
|
||||
# notably this *doesn't* make an API call
|
||||
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}").
|
||||
to_return(body: JSON.generate(make_application_fee_refund(:metadata => {'key' => 'value'})))
|
||||
assert refunds.data.kind_of?(Array)
|
||||
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
|
||||
|
||||
assert_equal 'value', refund.metadata['key']
|
||||
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
|
||||
assert_requested :post,
|
||||
"#{Stripe.api_base}/v1/application_fees/#{@fee.id}/refunds/#{FIXTURE[:id]}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -2,24 +2,13 @@ require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
module Stripe
|
||||
class ApplicationFeeTest < Test::Unit::TestCase
|
||||
should "application fees should be listable" do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/application_fees").
|
||||
to_return(body: JSON.generate(make_application_fee_array))
|
||||
FIXTURE = API_FIXTURES.fetch(:platform_earning)
|
||||
|
||||
should "be listable" do
|
||||
fees = Stripe::ApplicationFee.list
|
||||
assert fees.data.kind_of? Array
|
||||
fees.each do |fee|
|
||||
assert fee.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)
|
||||
assert_requested :get, "#{Stripe.api_base}/v1/application_fees"
|
||||
assert fees.data.kind_of?(Array)
|
||||
assert fees.data[0].kind_of?(Stripe::ApplicationFee)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -2,11 +2,10 @@ require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
module Stripe
|
||||
class BalanceTest < Test::Unit::TestCase
|
||||
should "balance should be retrievable" do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/balance").
|
||||
to_return(body: JSON.generate(make_balance))
|
||||
should "be retrievable" do
|
||||
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
|
||||
|
@ -2,19 +2,40 @@ require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
module Stripe
|
||||
class BankAccountTest < Test::Unit::TestCase
|
||||
FIXTURE = API_FIXTURES.fetch(:external_account_source)
|
||||
|
||||
should 'be verifiable' do
|
||||
bank = Stripe::BankAccount.construct_from({
|
||||
:id => 'ba_foo',
|
||||
:customer => 'cus_bar'
|
||||
})
|
||||
context "#resource_url" do
|
||||
should "return an external account URL" do
|
||||
account_id = API_FIXTURES.fetch(:account)[:id]
|
||||
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").
|
||||
with(body: { 'amounts' => ['1', '2'] }).
|
||||
to_return(body: JSON.generate(:status => 'verified'))
|
||||
|
||||
bank.verify(:amounts => [1,2])
|
||||
should "return a customer URL" do
|
||||
customer_id = API_FIXTURES.fetch(:customer)[:id]
|
||||
bank_account = Stripe::BankAccount.construct_from(
|
||||
customer: customer_id,
|
||||
id: FIXTURE[:id]
|
||||
)
|
||||
assert_equal "/v1/customers/#{customer_id}/sources/#{FIXTURE[:id]}",
|
||||
bank_account.resource_url
|
||||
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
|
||||
|
@ -2,62 +2,69 @@ require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
module Stripe
|
||||
class BitcoinReceiverTest < Test::Unit::TestCase
|
||||
should "retrieve should retrieve bitcoin receiver" do
|
||||
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
|
||||
FIXTURE = API_FIXTURES.fetch(:bitcoin_receiver)
|
||||
|
||||
should "create should create a bitcoin receiver" 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))
|
||||
should "be listable" do
|
||||
receivers = Stripe::BitcoinReceiver.list
|
||||
assert_equal 3, receivers.data.length
|
||||
assert receivers.data.kind_of? Array
|
||||
receivers.each do |receiver|
|
||||
assert receiver.kind_of?(Stripe::BitcoinReceiver)
|
||||
receiver.transactions.data.each do |transaction|
|
||||
assert transaction.kind_of?(Stripe::BitcoinTransaction)
|
||||
end
|
||||
end
|
||||
assert_requested :get, "#{Stripe.api_base}/v1/bitcoin/receivers"
|
||||
assert receivers.data.kind_of?(Array)
|
||||
assert receivers.first.kind_of?(Stripe::BitcoinReceiver)
|
||||
end
|
||||
|
||||
should "update should update a bitcoin receiver" do
|
||||
receiver = Stripe::BitcoinReceiver.construct_from(make_bitcoin_receiver)
|
||||
should "be retrievable" do
|
||||
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}").
|
||||
to_return(body: JSON.generate(make_bitcoin_receiver))
|
||||
receiver.refresh
|
||||
should "be creatable" do
|
||||
receiver = Stripe::BitcoinReceiver.create(amount: 100, currency: "USD")
|
||||
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}").
|
||||
with(body: { description: "details" }).
|
||||
to_return(body: JSON.generate(make_bitcoin_receiver))
|
||||
receiver.description = "details"
|
||||
should "be saveable" do
|
||||
receiver = Stripe::BitcoinReceiver.retrieve(FIXTURE[:id])
|
||||
receiver.metadata['key'] = 'value'
|
||||
receiver.save
|
||||
assert_requested :post,
|
||||
"#{Stripe.api_base}/v1/bitcoin/receivers/#{FIXTURE[:id]}"
|
||||
end
|
||||
|
||||
should "delete a bitcoin receiver with no customer through top-level API" do
|
||||
receiver = Stripe::BitcoinReceiver.construct_from(make_bitcoin_receiver)
|
||||
stub_request(:delete, "#{Stripe.api_base}/v1/bitcoin/receivers/#{receiver.id}").
|
||||
to_return(body: JSON.generate({:deleted => true, :id => "btcrcv_test_receiver"}))
|
||||
receiver.delete
|
||||
assert(receiver.deleted)
|
||||
should "be updateable" do
|
||||
receiver = Stripe::BitcoinReceiver.update(FIXTURE[:id], metadata: { key: 'value' })
|
||||
assert_requested :post,
|
||||
"#{Stripe.api_base}/v1/bitcoin/receivers/#{FIXTURE[:id]}"
|
||||
assert receiver.kind_of?(Stripe::BitcoinReceiver)
|
||||
end
|
||||
|
||||
should "delete a bitcoin receiver with a customer through customer's subresource API" do
|
||||
receiver = Stripe::BitcoinReceiver.construct_from(make_bitcoin_receiver(:customer => 'customer_foo'))
|
||||
stub_request(:delete, "#{Stripe.api_base}/v1/customers/customer_foo/sources/#{receiver.id}").
|
||||
to_return(body: JSON.generate({:deleted => true, :id => "btcrcv_test_receiver"}))
|
||||
receiver.delete
|
||||
assert(receiver.deleted)
|
||||
should "be deletable" do
|
||||
receiver = Stripe::BitcoinReceiver.retrieve(FIXTURE[:id])
|
||||
receiver = receiver.delete
|
||||
assert_requested :delete,
|
||||
"#{Stripe.api_base}/v1/bitcoin/receivers/#{FIXTURE[:id]}"
|
||||
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
|
||||
|
@ -2,24 +2,20 @@ require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
module Stripe
|
||||
class BitcoinTransactionTest < Test::Unit::TestCase
|
||||
TEST_ID = "btctxn_test_transaction".freeze
|
||||
FIXTURE = API_FIXTURES.fetch(:bitcoin_transaction)
|
||||
|
||||
should "retrieve should retrieve bitcoin receiver" do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/bitcoin/transactions/#{TEST_ID}").
|
||||
to_return(body: JSON.generate(make_bitcoin_transaction))
|
||||
receiver = Stripe::BitcoinTransaction.retrieve(TEST_ID)
|
||||
assert_equal TEST_ID, receiver.id
|
||||
should "be listable" do
|
||||
transactions = Stripe::BitcoinTransaction.list
|
||||
assert_requested :get, "#{Stripe.api_base}/v1/bitcoin/transactions"
|
||||
assert transactions.data.kind_of?(Array)
|
||||
assert transactions.first.kind_of?(Stripe::BitcoinTransaction)
|
||||
end
|
||||
|
||||
should "all should list bitcoin transactions" do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/bitcoin/transactions").
|
||||
to_return(body: JSON.generate(make_bitcoin_transaction_array))
|
||||
transactions = Stripe::BitcoinTransaction.list
|
||||
|
||||
assert transactions.data.kind_of? Array
|
||||
transactions.each do |transaction|
|
||||
assert transaction.kind_of?(Stripe::BitcoinTransaction)
|
||||
end
|
||||
should "be retrievable" do
|
||||
transaction = Stripe::BitcoinTransaction.retrieve(FIXTURE[:id])
|
||||
assert_requested :get,
|
||||
"#{Stripe.api_base}/v1/bitcoin/transactions/#{FIXTURE[:id]}"
|
||||
assert transaction.kind_of?(Stripe::BitcoinTransaction)
|
||||
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
|
||||
class CountrySpecTest < Test::Unit::TestCase
|
||||
should "be listable" do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/country_specs").
|
||||
to_return(body: JSON.generate(make_country_spec_array))
|
||||
c = Stripe::CountrySpec.list
|
||||
FIXTURE = API_FIXTURES.fetch(:country_spec)
|
||||
|
||||
assert(c.data.kind_of?(Array))
|
||||
assert(c.data[0].kind_of?(Stripe::CountrySpec))
|
||||
should "be listable" do
|
||||
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
|
||||
|
||||
should "be retrievable" do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/country_specs/US").
|
||||
to_return(body: JSON.generate(make_country_spec))
|
||||
s = Stripe::CountrySpec.retrieve('US')
|
||||
s = Stripe::CountrySpec.retrieve(FIXTURE[:id])
|
||||
assert_requested :get, "#{Stripe.api_base}/v1/country_specs/#{FIXTURE[:id]}"
|
||||
assert(s.kind_of?(Stripe::CountrySpec))
|
||||
end
|
||||
end
|
||||
|
@ -2,29 +2,38 @@ require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
module Stripe
|
||||
class CouponTest < Test::Unit::TestCase
|
||||
should "create should return a new coupon" do
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/coupons").
|
||||
to_return(body: JSON.generate(make_coupon))
|
||||
_ = Stripe::Coupon.create
|
||||
FIXTURE = API_FIXTURES.fetch(:coupon)
|
||||
|
||||
should "be listable" do
|
||||
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
|
||||
|
||||
should "coupons should be saveable" do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/coupons/test_coupon").
|
||||
to_return(body: JSON.generate(make_coupon))
|
||||
c = Stripe::Coupon.retrieve("test_coupon")
|
||||
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/coupons/#{c.id}").
|
||||
with(body: { metadata: { foo: "bar" } }).
|
||||
to_return(body: JSON.generate(make_customer))
|
||||
c.metadata['foo'] = 'bar'
|
||||
c.save
|
||||
should "be retrievable" do
|
||||
coupon = Stripe::Coupon.retrieve(FIXTURE[:id])
|
||||
assert_requested :get, "#{Stripe.api_base}/v1/coupons/#{FIXTURE[:id]}"
|
||||
assert coupon.kind_of?(Stripe::Coupon)
|
||||
end
|
||||
|
||||
should "coupons should be updateable" do
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/coupons/test_coupon").
|
||||
with(body: { metadata: { foo: "bar" } }).
|
||||
to_return(body: JSON.generate(make_customer))
|
||||
_ = Stripe::Coupon.update("test_coupon", metadata: {foo: 'bar'})
|
||||
should "be creatable" do
|
||||
coupon = Stripe::Coupon.create(:charge => API_FIXTURES[:charge][:id])
|
||||
assert_requested :post, "#{Stripe.api_base}/v1/coupons"
|
||||
assert coupon.kind_of?(Stripe::Coupon)
|
||||
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
|
||||
|
@ -2,62 +2,41 @@ require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
module Stripe
|
||||
class CustomerCardTest < Test::Unit::TestCase
|
||||
def customer
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/customers/test_customer").
|
||||
to_return(body: JSON.generate(make_customer))
|
||||
Stripe::Customer.retrieve('test_customer')
|
||||
FIXTURE = API_FIXTURES.fetch(:source)
|
||||
|
||||
setup do
|
||||
@customer =
|
||||
Stripe::Customer.retrieve(API_FIXTURES.fetch(:customer)[:id])
|
||||
end
|
||||
|
||||
should "customer cards should be listable" do
|
||||
c = customer
|
||||
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/customers/#{c.id}/sources").
|
||||
with(query: { object: "card" }).
|
||||
to_return(body: JSON.generate(make_customer_card_array(customer.id)))
|
||||
cards = c.sources.list(:object => "card").data
|
||||
assert cards.kind_of? Array
|
||||
assert cards[0].kind_of? Stripe::Card
|
||||
should "be listable" do
|
||||
sources = @customer.sources.list
|
||||
assert sources.data.kind_of?(Array)
|
||||
# because of the terrible :wildcard nature of sources, the API stub
|
||||
# cannot currently replace this response with anything meaningful so we
|
||||
# don't assert on the type of individual items like we do in other tests
|
||||
end
|
||||
|
||||
should "customer cards should be deletable" do
|
||||
c = customer
|
||||
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/customers/#{c.id}/sources/card").
|
||||
to_return(body: JSON.generate(make_card))
|
||||
card = c.sources.retrieve('card')
|
||||
|
||||
stub_request(:delete, "#{Stripe.api_base}/v1/customers/#{card.customer}/sources/#{card.id}").
|
||||
to_return(body: JSON.generate(make_card(:deleted => true)))
|
||||
_ = card.delete
|
||||
should "be creatable" do
|
||||
card = @customer.sources.create(
|
||||
source: API_FIXTURES.fetch(:token)[:id]
|
||||
)
|
||||
assert_requested :post, "#{Stripe.api_base}/v1/customers/#{@customer.id}/sources"
|
||||
assert card.kind_of?(Stripe::BankAccount)
|
||||
end
|
||||
|
||||
should "customer cards should be updateable" do
|
||||
c = customer
|
||||
should "be deletable" do
|
||||
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").
|
||||
to_return(body: JSON.generate(make_card))
|
||||
card = c.sources.retrieve('card')
|
||||
|
||||
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"
|
||||
should "be saveable" do
|
||||
card = Stripe::Card.construct_from(FIXTURE.merge(customer: @customer.id))
|
||||
card.metadata['key'] = 'value'
|
||||
card.save
|
||||
end
|
||||
|
||||
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
|
||||
assert_requested :post, "#{Stripe.api_base}/v1/customers/#{@customer.id}/sources/#{FIXTURE[:id]}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -2,112 +2,114 @@ require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
module Stripe
|
||||
class CustomerTest < Test::Unit::TestCase
|
||||
should "customers should be listable" do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/customers").
|
||||
to_return(body: JSON.generate(make_customer_array))
|
||||
c = Stripe::Customer.list.data
|
||||
assert c.kind_of? Array
|
||||
assert c[0].kind_of? Stripe::Customer
|
||||
FIXTURE = API_FIXTURES.fetch(:customer)
|
||||
|
||||
should "be listable" do
|
||||
customers = Stripe::Customer.list
|
||||
assert_requested :get, "#{Stripe.api_base}/v1/customers"
|
||||
assert customers.data.kind_of?(Array)
|
||||
assert customers.first.kind_of?(Stripe::Customer)
|
||||
end
|
||||
|
||||
should "customers should be deletable" do
|
||||
stub_request(:delete, "#{Stripe.api_base}/v1/customers/test_customer").
|
||||
to_return(body: JSON.generate(make_customer))
|
||||
c = Stripe::Customer.new("test_customer")
|
||||
c.delete
|
||||
should "be retrievable" do
|
||||
customer = Stripe::Customer.retrieve(FIXTURE[:id])
|
||||
assert_requested :get, "#{Stripe.api_base}/v1/customers/#{FIXTURE[:id]}"
|
||||
assert customer.kind_of?(Stripe::Customer)
|
||||
end
|
||||
|
||||
should "customers should be saveable" do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/customers/test_customer").
|
||||
to_return(body: JSON.generate(make_customer))
|
||||
c = Stripe::Customer.retrieve("test_customer")
|
||||
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/customers/#{c.id}").
|
||||
with(body: { mnemonic: "bar" }).
|
||||
to_return(body: JSON.generate(make_customer))
|
||||
c.mnemonic = "bar"
|
||||
c.save
|
||||
should "be creatable" do
|
||||
customer = Stripe::Customer.create
|
||||
assert_requested :post, "#{Stripe.api_base}/v1/customers"
|
||||
assert customer.kind_of?(Stripe::Customer)
|
||||
end
|
||||
|
||||
should "customers should be updateable" do
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/customers/test_customer").
|
||||
with(body: { mnemonic: "bar" }).
|
||||
to_return(body: JSON.generate(make_customer))
|
||||
_ = Stripe::Customer.update("test_customer", mnemonic: "bar")
|
||||
should "be saveable" do
|
||||
customer = Stripe::Customer.retrieve(FIXTURE[:id])
|
||||
customer.metadata['key'] = 'value'
|
||||
customer.save
|
||||
assert_requested :post, "#{Stripe.api_base}/v1/customers/#{FIXTURE[:id]}"
|
||||
end
|
||||
|
||||
should "create should return a new customer" do
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/customers").
|
||||
to_return(body: JSON.generate(make_customer))
|
||||
_ = Stripe::Customer.create
|
||||
should "be updateable" do
|
||||
customer = Stripe::Customer.update(FIXTURE[:id], metadata: { key: 'value' })
|
||||
assert_requested :post, "#{Stripe.api_base}/v1/customers/#{FIXTURE[:id]}"
|
||||
assert customer.kind_of?(Stripe::Customer)
|
||||
end
|
||||
|
||||
should "create_upcoming_invoice should create a new invoice" do
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/invoices").
|
||||
with(body: { customer: "test_customer" }).
|
||||
to_return(body: JSON.generate(make_customer))
|
||||
_ = Stripe::Customer.new("test_customer").create_upcoming_invoice
|
||||
should "be deletable" do
|
||||
customer = Stripe::Customer.retrieve(FIXTURE[:id])
|
||||
customer = customer.delete
|
||||
assert_requested :delete, "#{Stripe.api_base}/v1/customers/#{FIXTURE[:id]}"
|
||||
assert customer.kind_of?(Stripe::Customer)
|
||||
end
|
||||
|
||||
should "be able to update a customer's subscription" do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/customers/test_customer").
|
||||
to_return(body: JSON.generate(make_customer))
|
||||
c = Stripe::Customer.retrieve("test_customer")
|
||||
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/customers/#{c.id}/subscription").
|
||||
with(body: { plan: "silver" }).
|
||||
to_return(body: JSON.generate(make_subscription))
|
||||
_ = c.update_subscription({:plan => 'silver'})
|
||||
context "#create_subscription" do
|
||||
should "create a new subscription" do
|
||||
customer = Stripe::Customer.retrieve(FIXTURE[:id])
|
||||
subscription = customer.create_subscription({:plan => 'silver'})
|
||||
assert subscription.kind_of?(Stripe::Subscription)
|
||||
end
|
||||
end
|
||||
|
||||
should "be able to cancel a customer's subscription" do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/customers/test_customer").
|
||||
to_return(body: JSON.generate(make_customer))
|
||||
c = Stripe::Customer.retrieve("test_customer")
|
||||
|
||||
# Not an accurate response, but whatever
|
||||
|
||||
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
|
||||
context "#create_upcoming_invoice" do
|
||||
should "create a new invoice" do
|
||||
customer = Stripe::Customer.retrieve(FIXTURE[:id])
|
||||
invoice = customer.create_upcoming_invoice
|
||||
assert invoice.kind_of?(Stripe::Invoice)
|
||||
end
|
||||
end
|
||||
|
||||
should "be able to create a subscription for a customer" do
|
||||
c = Stripe::Customer.new("test_customer")
|
||||
context "#update_subscription" do
|
||||
should "update a subscription" do
|
||||
customer = Stripe::Customer.retrieve(FIXTURE[:id])
|
||||
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/customers/#{c.id}/subscriptions").
|
||||
with(body: { plan: "silver" }).
|
||||
to_return(body: JSON.generate(make_subscription))
|
||||
_ = c.create_subscription({:plan => 'silver'})
|
||||
# deprecated API and not in schema
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/customers/#{customer.id}/subscription").
|
||||
with(body: { plan: "silver" }).
|
||||
to_return(body: JSON.generate(API_FIXTURES[:subscription]))
|
||||
subscription = customer.update_subscription({:plan => 'silver'})
|
||||
assert subscription.kind_of?(Stripe::Subscription)
|
||||
end
|
||||
end
|
||||
|
||||
should "be able to delete a customer's discount" do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/customers/test_customer").
|
||||
to_return(body: JSON.generate(make_customer))
|
||||
c = Stripe::Customer.retrieve("test_customer")
|
||||
context "#cancel_subscription" do
|
||||
should "cancel a subscription" do
|
||||
customer = Stripe::Customer.retrieve(FIXTURE[:id])
|
||||
|
||||
stub_request(:delete, "#{Stripe.api_base}/v1/customers/#{c.id}/discount").
|
||||
to_return(body: JSON.generate(make_delete_discount_response))
|
||||
c.delete_discount
|
||||
# deprecated API and not in schema
|
||||
stub_request(:delete, "#{Stripe.api_base}/v1/customers/#{customer.id}/subscription").
|
||||
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
|
||||
|
||||
should "can have a token source set" do
|
||||
c = Stripe::Customer.new("test_customer")
|
||||
c.source = "tok_123"
|
||||
assert_equal "tok_123", c.source
|
||||
context "#delete_discount" do
|
||||
should "delete a discount" do
|
||||
customer = Stripe::Customer.retrieve(FIXTURE[:id])
|
||||
|
||||
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
|
||||
|
||||
should "set a flag if given an object source" do
|
||||
c = Stripe::Customer.new("test_customer")
|
||||
c.source = {
|
||||
:object => 'card'
|
||||
}
|
||||
assert_equal true, c.source.save_with_parent
|
||||
context "source field" do
|
||||
should "allow setting source with token" do
|
||||
c = Stripe::Customer.new("test_customer")
|
||||
c.source = "tok_123"
|
||||
assert_equal "tok_123", c.source
|
||||
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
|
||||
|
@ -2,47 +2,41 @@ require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
module Stripe
|
||||
class DisputeTest < Test::Unit::TestCase
|
||||
should "disputes should be retrievable" 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')
|
||||
assert d.kind_of?(Stripe::Dispute)
|
||||
FIXTURE = API_FIXTURES.fetch(:dispute)
|
||||
|
||||
should "be listable" do
|
||||
disputes = Stripe::Dispute.list
|
||||
assert_requested :get, "#{Stripe.api_base}/v1/disputes"
|
||||
assert disputes.data.kind_of?(Array)
|
||||
assert disputes.first.kind_of?(Stripe::Dispute)
|
||||
end
|
||||
|
||||
should "disputes should be listable" do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/disputes").
|
||||
to_return(body: JSON.generate(make_dispute_array))
|
||||
d = Stripe::Dispute.list
|
||||
assert d.data.kind_of? Array
|
||||
d.each do |dispute|
|
||||
assert dispute.kind_of?(Stripe::Dispute)
|
||||
should "be retrievable" do
|
||||
dispute = Stripe::Dispute.retrieve(FIXTURE[:id])
|
||||
assert_requested :get, "#{Stripe.api_base}/v1/disputes/#{FIXTURE[:id]}"
|
||||
assert dispute.kind_of?(Stripe::Dispute)
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
@ -2,31 +2,46 @@ require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
module Stripe
|
||||
class FileUploadTest < Test::Unit::TestCase
|
||||
should "create should return a new file" do
|
||||
stub_request(:post, "#{Stripe.uploads_base}/v1/files").
|
||||
to_return(body: JSON.generate(make_file))
|
||||
# Note that these tests are written different from others because we
|
||||
# don't have anything on the uploads service in our OpenAPI spec. This is
|
||||
# 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({
|
||||
: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
|
||||
should "be listable" do
|
||||
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
|
||||
assert c.kind_of? Array
|
||||
assert c[0].kind_of? Stripe::FileUpload
|
||||
files = Stripe::FileUpload.list
|
||||
assert files.data.kind_of?(Array)
|
||||
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
|
||||
|
@ -2,17 +2,54 @@ require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
module Stripe
|
||||
class InvoiceItemTest < Test::Unit::TestCase
|
||||
should "retrieve should retrieve invoice items" do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/invoiceitems/ii_test_invoice_item").
|
||||
to_return(body: JSON.generate(make_invoice_item))
|
||||
_ = Stripe::InvoiceItem.retrieve('ii_test_invoice_item')
|
||||
FIXTURE = API_FIXTURES.fetch(:invoice_item)
|
||||
|
||||
should "be listable" do
|
||||
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
|
||||
|
||||
should "invoice items should be updateable" do
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/invoiceitems/ii_test_invoice_item").
|
||||
with(body: { metadata: { foo: "bar" } }).
|
||||
to_return(body: JSON.generate(make_invoice_item))
|
||||
_ = Stripe::InvoiceItem.update("ii_test_invoice_item", metadata: {foo: 'bar'})
|
||||
should "be retrievable" do
|
||||
item = Stripe::InvoiceItem.retrieve(FIXTURE[:id])
|
||||
assert_requested :get,
|
||||
"#{Stripe.api_base}/v1/invoiceitems/#{FIXTURE[:id]}"
|
||||
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
|
||||
|
@ -2,47 +2,65 @@ require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
module Stripe
|
||||
class InvoiceTest < Test::Unit::TestCase
|
||||
should "retrieve should retrieve invoices" do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/invoices/in_test_invoice").
|
||||
to_return(body: JSON.generate(make_invoice))
|
||||
i = Stripe::Invoice.retrieve('in_test_invoice')
|
||||
assert_equal 'in_test_invoice', i.id
|
||||
FIXTURE = API_FIXTURES.fetch(:invoice)
|
||||
|
||||
should "be listable" do
|
||||
invoices = Stripe::Invoice.list
|
||||
assert_requested :get, "#{Stripe.api_base}/v1/invoices"
|
||||
assert invoices.data.kind_of?(Array)
|
||||
assert invoices.first.kind_of?(Stripe::Invoice)
|
||||
end
|
||||
|
||||
should "create should create a new invoice" do
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/invoices").
|
||||
to_return(body: JSON.generate(make_invoice))
|
||||
_ = Stripe::Invoice.create
|
||||
should "be retrievable" do
|
||||
invoice = Stripe::Invoice.retrieve(FIXTURE[:id])
|
||||
assert_requested :get, "#{Stripe.api_base}/v1/invoices/#{FIXTURE[:id]}"
|
||||
assert invoice.kind_of?(Stripe::Invoice)
|
||||
end
|
||||
|
||||
should "pay should pay an invoice" do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/invoices/in_test_invoice").
|
||||
to_return(body: JSON.generate(make_invoice))
|
||||
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',
|
||||
should "be creatable" do
|
||||
invoice = Stripe::Invoice.create(
|
||||
:customer => API_FIXTURES[:customer][:id]
|
||||
)
|
||||
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
|
||||
|
@ -8,8 +8,10 @@ module Stripe
|
||||
end
|
||||
|
||||
should "provide #count via enumerable" do
|
||||
list = Stripe::ListObject.construct_from(make_charge_array)
|
||||
assert_equal 3, list.count
|
||||
list = Stripe::ListObject.construct_from({
|
||||
data: [API_FIXTURES.fetch(:charge)]
|
||||
})
|
||||
assert_equal 1, list.count
|
||||
end
|
||||
|
||||
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
|
||||
# in a list
|
||||
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
|
||||
assert c.kind_of?(Stripe::ListObject)
|
||||
assert_equal('/v1/charges', c.resource_url)
|
||||
|
@ -2,25 +2,20 @@ require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
module Stripe
|
||||
class OrderReturnTest < Test::Unit::TestCase
|
||||
should "returns should be listable" do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/order_returns").
|
||||
to_return(body: JSON.generate(make_order_return_array))
|
||||
returns = Stripe::OrderReturn.list
|
||||
assert returns.data.kind_of?(Array)
|
||||
returns.each do |ret|
|
||||
assert ret.kind_of?(Stripe::OrderReturn)
|
||||
end
|
||||
FIXTURE = API_FIXTURES.fetch(:order_return)
|
||||
|
||||
should "be listable" do
|
||||
order_returns = Stripe::OrderReturn.list
|
||||
assert_requested :get, "#{Stripe.api_base}/v1/order_returns"
|
||||
assert order_returns.data.kind_of?(Array)
|
||||
assert order_returns.data[0].kind_of?(Stripe::OrderReturn)
|
||||
end
|
||||
|
||||
should "returns should not be deletable" do
|
||||
p = Stripe::OrderReturn.new("test_order")
|
||||
assert_raises(NoMethodError) { p.delete }
|
||||
end
|
||||
|
||||
should "returns should be immutable" do
|
||||
p = Stripe::OrderReturn.new("test_order")
|
||||
p.items = []
|
||||
assert_raises(NoMethodError) { p.save }
|
||||
should "be retrievable" do
|
||||
order_return = Stripe::OrderReturn.retrieve(FIXTURE[:id])
|
||||
assert_requested :get,
|
||||
"#{Stripe.api_base}/v1/order_returns/#{FIXTURE[:id]}"
|
||||
assert order_return.kind_of?(Stripe::OrderReturn)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -2,65 +2,58 @@ require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
module Stripe
|
||||
class OrderTest < Test::Unit::TestCase
|
||||
should "orders should be listable" do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/orders").
|
||||
to_return(body: JSON.generate(make_order_array))
|
||||
FIXTURE = API_FIXTURES.fetch(:order)
|
||||
|
||||
should "be listable" do
|
||||
orders = Stripe::Order.list
|
||||
assert_requested :get, "#{Stripe.api_base}/v1/orders"
|
||||
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)
|
||||
end
|
||||
end
|
||||
|
||||
should "orders should not be deletable" 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")
|
||||
|
||||
assert_raises NoMethodError do
|
||||
p.delete
|
||||
context "#return_order" do
|
||||
should "return an order" do
|
||||
order = Stripe::Order.retrieve(FIXTURE[:id])
|
||||
order = order.return_order(:orders => [
|
||||
{ parent: API_FIXTURES.fetch(:sku)[:id] }
|
||||
])
|
||||
assert order.kind_of?(Stripe::OrderReturn)
|
||||
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
|
||||
|
@ -2,33 +2,45 @@ require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
module Stripe
|
||||
class PlanTest < Test::Unit::TestCase
|
||||
should "plans should be listable" do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/plans").
|
||||
to_return(body: JSON.generate(make_plan_array))
|
||||
FIXTURE = API_FIXTURES.fetch(:plan)
|
||||
|
||||
should "be listable" do
|
||||
plans = Stripe::Plan.list
|
||||
assert_requested :get, "#{Stripe.api_base}/v1/plans"
|
||||
assert plans.data.kind_of?(Array)
|
||||
plans.each do |plan|
|
||||
assert plan.kind_of?(Stripe::Plan)
|
||||
end
|
||||
assert plans.data[0].kind_of?(Stripe::Plan)
|
||||
end
|
||||
|
||||
should "plans should be saveable" do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/plans/test_plan").
|
||||
to_return(body: JSON.generate(make_plan))
|
||||
p = Stripe::Plan.retrieve("test_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
|
||||
should "be retrievable" do
|
||||
plan = Stripe::Plan.retrieve(FIXTURE[:id])
|
||||
assert_requested :get, "#{Stripe.api_base}/v1/plans/#{FIXTURE[:id]}"
|
||||
assert plan.kind_of?(Stripe::Plan)
|
||||
end
|
||||
|
||||
should "plans should be updateable" do
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/plans/test_plan").
|
||||
with(body: { metadata: { foo: "bar" } }).
|
||||
to_return(body: JSON.generate(make_plan))
|
||||
_ = Stripe::Plan.update("test_plan", metadata: {foo: 'bar'})
|
||||
should "be creatable" do
|
||||
plan = Stripe::Plan.create(:metadata => {})
|
||||
assert_requested :post, "#{Stripe.api_base}/v1/plans"
|
||||
assert plan.kind_of?(Stripe::Plan)
|
||||
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
|
||||
|
@ -2,44 +2,46 @@ require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
module Stripe
|
||||
class ProductTest < Test::Unit::TestCase
|
||||
should "products should be listable" do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/products").
|
||||
to_return(body: JSON.generate(make_product_array))
|
||||
FIXTURE = API_FIXTURES.fetch(:product)
|
||||
|
||||
should "be listable" do
|
||||
products = Stripe::Product.list
|
||||
assert_requested :get, "#{Stripe.api_base}/v1/products"
|
||||
assert products.data.kind_of?(Array)
|
||||
products.each do |product|
|
||||
assert product.kind_of?(Stripe::Product)
|
||||
end
|
||||
assert products.data[0].kind_of?(Stripe::Product)
|
||||
end
|
||||
|
||||
should "products should be deletable" do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/products/test_product").
|
||||
to_return(body: JSON.generate(make_product))
|
||||
p = Stripe::Product.retrieve("test_product")
|
||||
|
||||
stub_request(:delete, "#{Stripe.api_base}/v1/products/#{p.id}").
|
||||
to_return(body: JSON.generate(make_product))
|
||||
p.delete
|
||||
should "be retrievable" do
|
||||
product = Stripe::Product.retrieve(FIXTURE[:id])
|
||||
assert_requested :get, "#{Stripe.api_base}/v1/products/#{FIXTURE[:id]}"
|
||||
assert product.kind_of?(Stripe::Product)
|
||||
end
|
||||
|
||||
should "products should be saveable" do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/products/test_product").
|
||||
to_return(body: JSON.generate(make_product))
|
||||
p = Stripe::Product.new("test_product")
|
||||
p.refresh
|
||||
|
||||
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
|
||||
should "be creatable" do
|
||||
_ = Stripe::Product.create(
|
||||
name: "My Product"
|
||||
)
|
||||
assert_requested :post, "#{Stripe.api_base}/v1/products"
|
||||
end
|
||||
|
||||
should "products should be updateable" do
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/products/test_product").
|
||||
with(body: { :description => "update" }).
|
||||
to_return(body: JSON.generate(make_product))
|
||||
_ = Stripe::Product.update("test_product", description: "update")
|
||||
should "be saveable" do
|
||||
product = Stripe::Product.retrieve(FIXTURE[:id])
|
||||
product.metadata['key'] = 'value'
|
||||
product.save
|
||||
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
|
||||
|
@ -2,55 +2,39 @@ require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
module Stripe
|
||||
class RecipientCardTest < Test::Unit::TestCase
|
||||
def recipient
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/recipients/test_recipient").
|
||||
to_return(body: JSON.generate(make_recipient))
|
||||
Stripe::Recipient.retrieve('test_recipient')
|
||||
FIXTURE = API_FIXTURES.fetch(:source)
|
||||
|
||||
setup do
|
||||
@recipient =
|
||||
Stripe::Recipient.retrieve(API_FIXTURES.fetch(:transfer_recipient)[:id])
|
||||
end
|
||||
|
||||
should "recipient cards should be listable" do
|
||||
c = recipient
|
||||
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/recipients/#{c.id}/cards").
|
||||
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
|
||||
should "be listable" do
|
||||
cards = @recipient.cards.list
|
||||
assert cards.data.kind_of?(Array)
|
||||
assert cards.data[0].kind_of?(Stripe::Token)
|
||||
end
|
||||
|
||||
should "recipient cards should be deletable" do
|
||||
c = recipient
|
||||
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/recipients/#{c.id}/cards/card").
|
||||
to_return(body: JSON.generate(make_card(:recipient => 'test_recipient')))
|
||||
card = c.cards.retrieve('card')
|
||||
|
||||
stub_request(:delete, "#{Stripe.api_base}/v1/recipients/#{card.recipient}/cards/#{card.id}").
|
||||
to_return(body: JSON.generate(make_card(:deleted => true)))
|
||||
_ = card.delete
|
||||
should "be creatable" do
|
||||
card = @recipient.cards.create(
|
||||
card: API_FIXTURES.fetch(:token)[:id]
|
||||
)
|
||||
assert_requested :post, "#{Stripe.api_base}/v1/recipients/#{@recipient.id}/cards"
|
||||
assert card.kind_of?(Stripe::Token)
|
||||
end
|
||||
|
||||
should "recipient cards should be updateable" do
|
||||
c = recipient
|
||||
should "be deletable" do
|
||||
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").
|
||||
to_return(body: JSON.generate(make_card(:recipient => 'test_recipient')))
|
||||
card = c.cards.retrieve('card')
|
||||
|
||||
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"
|
||||
should "be saveable" do
|
||||
card = Stripe::Card.construct_from(FIXTURE.merge(recipient: @recipient.id))
|
||||
card.metadata['key'] = 'value'
|
||||
card.save
|
||||
end
|
||||
|
||||
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")
|
||||
assert_requested :post, "#{Stripe.api_base}/v1/recipients/#{@recipient.id}/cards/#{FIXTURE[:id]}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -2,17 +2,48 @@ require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
module Stripe
|
||||
class RecipientTest < Test::Unit::TestCase
|
||||
should "recipient should be retrievable" do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/recipients/test_recipient").
|
||||
to_return(body: JSON.generate(make_recipient))
|
||||
_ = Stripe::Recipient.retrieve('test_recipient')
|
||||
FIXTURE = API_FIXTURES.fetch(:transfer_recipient)
|
||||
|
||||
should "be listable" do
|
||||
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
|
||||
|
||||
should "recipient should be updateable" do
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/recipients/test_recipient").
|
||||
with(body: { metadata: { key: "value" } }).
|
||||
to_return(body: JSON.generate(make_refund))
|
||||
_ = Stripe::Recipient.update('test_recipient', metadata: { key: 'value' })
|
||||
should "be retrievable" do
|
||||
recipient = Stripe::Recipient.retrieve(FIXTURE[:id])
|
||||
assert_requested :get, "#{Stripe.api_base}/v1/recipients/#{FIXTURE[:id]}"
|
||||
assert recipient.kind_of?(Stripe::Recipient)
|
||||
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
|
||||
|
@ -2,37 +2,38 @@ require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
module Stripe
|
||||
class RefundTest < Test::Unit::TestCase
|
||||
should "refunds should be listable" do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/refunds").
|
||||
to_return(body: JSON.generate(make_refund_array))
|
||||
FIXTURE = API_FIXTURES.fetch(:refund)
|
||||
|
||||
should "be listable" do
|
||||
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)
|
||||
end
|
||||
|
||||
should "refunds should be saveable" do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/refunds/get_refund").
|
||||
to_return(body: JSON.generate(make_refund))
|
||||
refund = Stripe::Refund.retrieve('get_refund')
|
||||
should "be retrievable" do
|
||||
refund = Stripe::Refund.retrieve(FIXTURE[:id])
|
||||
assert_requested :get, "#{Stripe.api_base}/v1/refunds/#{FIXTURE[:id]}"
|
||||
assert refund.kind_of?(Stripe::Refund)
|
||||
end
|
||||
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/refunds/#{refund.id}").
|
||||
with(body: { metadata: { key: "value" } }).
|
||||
to_return(body: JSON.generate(make_refund))
|
||||
should "be creatable" do
|
||||
refund = Stripe::Refund.create(:charge => API_FIXTURES[:charge][:id])
|
||||
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.save
|
||||
assert_requested :post, "#{Stripe.api_base}/v1/refunds/#{FIXTURE[:id]}"
|
||||
end
|
||||
|
||||
should "refunds should be updateable" do
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/refunds/update_refund").
|
||||
with(body: { metadata: { key: "value" } }).
|
||||
to_return(body: JSON.generate(make_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')
|
||||
should "be updateable" do
|
||||
refund = Stripe::Refund.update(FIXTURE[:id], metadata: { key: 'value' })
|
||||
assert_requested :post, "#{Stripe.api_base}/v1/refunds/#{FIXTURE[:id]}"
|
||||
assert refund.kind_of?(Stripe::Refund)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -2,35 +2,42 @@ require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
module Stripe
|
||||
class ReversalTest < Test::Unit::TestCase
|
||||
should "reversals should be listable" do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/transfers/test_transfer").
|
||||
to_return(body: JSON.generate(make_transfer))
|
||||
transfer = Stripe::Transfer.retrieve('test_transfer')
|
||||
assert transfer.reversals.first.kind_of?(Stripe::Reversal)
|
||||
FIXTURE = API_FIXTURES.fetch(:transfer_reversal)
|
||||
|
||||
setup do
|
||||
@transfer = Stripe::Transfer.retrieve(API_FIXTURES.fetch(:transfer)[:id])
|
||||
end
|
||||
|
||||
should "reversals should be updateable" do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/transfers/test_transfer").
|
||||
to_return(body: JSON.generate(make_transfer))
|
||||
transfer = Stripe::Transfer.retrieve('test_transfer')
|
||||
reversal = transfer.reversals.first
|
||||
should "be listable" do
|
||||
reversals = @transfer.reversals.list
|
||||
assert_requested :get,
|
||||
"#{Stripe.api_base}/v1/transfers/#{@transfer.id}/reversals"
|
||||
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}").
|
||||
with(body: { metadata: { key: "value" } }).
|
||||
to_return(body: JSON.generate(make_reversal))
|
||||
should "be retrievable" do
|
||||
reversal = @transfer.reversals.retrieve(FIXTURE[:id])
|
||||
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.save
|
||||
end
|
||||
|
||||
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)
|
||||
assert_requested :post,
|
||||
"#{Stripe.api_base}/v1/transfers/#{@transfer.id}/reversals/#{FIXTURE[:id]}"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -2,32 +2,49 @@ require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
module Stripe
|
||||
class SKUTest < Test::Unit::TestCase
|
||||
should "SKUs should be listable" do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/skus").
|
||||
to_return(body: JSON.generate(make_sku_array("test_product")))
|
||||
FIXTURE = API_FIXTURES.fetch(:sku)
|
||||
|
||||
should "be listable" do
|
||||
skus = Stripe::SKU.list
|
||||
assert skus.data.kind_of? Array
|
||||
skus.each do |sku|
|
||||
assert sku.kind_of?(Stripe::SKU)
|
||||
end
|
||||
assert_requested :get, "#{Stripe.api_base}/v1/skus"
|
||||
assert skus.data.kind_of?(Array)
|
||||
assert skus.data[0].kind_of?(Stripe::SKU)
|
||||
end
|
||||
|
||||
should "SKUs should be updateable" do
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/skus/test_sku").
|
||||
with(body: { metadata: { foo: "bar" } }).
|
||||
to_return(body: JSON.generate(make_sku))
|
||||
_ = Stripe::SKU.update("test_sku", metadata: {foo: 'bar'})
|
||||
should "be retrievable" do
|
||||
sku = Stripe::SKU.retrieve(FIXTURE[:id])
|
||||
assert_requested :get, "#{Stripe.api_base}/v1/skus/#{FIXTURE[:id]}"
|
||||
assert sku.kind_of?(Stripe::SKU)
|
||||
end
|
||||
|
||||
should "SKUs should be deletable" do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/skus/test_sku").
|
||||
to_return(body: JSON.generate(make_sku))
|
||||
s = Stripe::SKU.retrieve("test_sku")
|
||||
|
||||
stub_request(:delete, "#{Stripe.api_base}/v1/skus/#{s.id}").
|
||||
to_return(body: JSON.generate(make_sku(:deleted => true)))
|
||||
s.delete
|
||||
should "be creatable" do
|
||||
_ = Stripe::SKU.create(
|
||||
currency: "USD",
|
||||
inventory: { type: "finite", quantity: 500 },
|
||||
price: 100,
|
||||
product: API_FIXTURES.fetch(:product)[:id]
|
||||
)
|
||||
assert_requested :post, "#{Stripe.api_base}/v1/skus"
|
||||
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
|
||||
|
@ -2,66 +2,42 @@ require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
module Stripe
|
||||
class SourceTest < Test::Unit::TestCase
|
||||
should 'be creatable' do
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/sources").
|
||||
with(body: { type: 'card', token: 'tok_test' }).
|
||||
to_return(body: JSON.generate(make_source_card))
|
||||
_ = Stripe::Source.create(
|
||||
FIXTURE = API_FIXTURES.fetch(:source)
|
||||
|
||||
should "be retrievable" do
|
||||
source = Stripe::Source.retrieve(FIXTURE[:id])
|
||||
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',
|
||||
token: 'tok_test',
|
||||
token: API_FIXTURES.fetch(:token)[:id]
|
||||
)
|
||||
assert_requested :post, "#{Stripe.api_base}/v1/sources"
|
||||
assert source.kind_of?(Stripe::Card)
|
||||
end
|
||||
|
||||
should 'be retrievable' do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/sources/source_test_card").
|
||||
to_return(body: JSON.generate(make_source_card))
|
||||
_ = 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'
|
||||
should "be saveable" do
|
||||
source = Stripe::Source.retrieve(FIXTURE[:id])
|
||||
source.metadata['key'] = 'value'
|
||||
source.save
|
||||
assert_requested :post, "#{Stripe.api_base}/v1/sources/#{FIXTURE[:id]}"
|
||||
end
|
||||
|
||||
should 'not be deletable' 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')
|
||||
should "be updateable" do
|
||||
source = Stripe::Source.update(FIXTURE[:id], metadata: {foo: 'bar'})
|
||||
assert_requested :post, "#{Stripe.api_base}/v1/sources/#{FIXTURE[:id]}"
|
||||
assert source.kind_of?(Stripe::Card)
|
||||
end
|
||||
|
||||
assert_raises NoMethodError do
|
||||
source.delete
|
||||
context "#verify" do
|
||||
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
|
||||
|
||||
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
|
||||
|
@ -121,7 +121,7 @@ module Stripe
|
||||
should "support literal headers" do
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/account").
|
||||
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.execute_request(:post, '/v1/account',
|
||||
@ -132,7 +132,7 @@ module Stripe
|
||||
should "support RestClient-style header keys" do
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/account").
|
||||
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.execute_request(:post, '/v1/account',
|
||||
@ -147,7 +147,7 @@ module Stripe
|
||||
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/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.execute_request(:post, '/v1/account')
|
||||
@ -157,7 +157,7 @@ module Stripe
|
||||
stripe_account = "acct_0000"
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/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.execute_request(:post, '/v1/account',
|
||||
@ -169,7 +169,7 @@ module Stripe
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/account").
|
||||
with { |req|
|
||||
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.execute_request(:post, '/v1/account')
|
||||
@ -287,30 +287,30 @@ module Stripe
|
||||
|
||||
should 'not add an idempotency key to GET requests' do
|
||||
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|
|
||||
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.execute_request(:get, '/v1/charges')
|
||||
client.execute_request(:get, "/v1/charges/#{API_FIXTURES.fetch(:charge)[:id]}")
|
||||
end
|
||||
|
||||
should 'ensure there is always an idempotency_key on POST requests' do
|
||||
SecureRandom.expects(:uuid).at_least_once.returns("random_key")
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/charges").
|
||||
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.execute_request(:post, '/v1/charges')
|
||||
client.execute_request(:post, "/v1/charges")
|
||||
end
|
||||
|
||||
should 'ensure there is always an idempotency_key on DELETE requests' do
|
||||
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"}).
|
||||
to_return(body: JSON.generate(make_charge))
|
||||
to_return(body: JSON.generate(API_FIXTURES.fetch(:charge)))
|
||||
client = StripeClient.new
|
||||
client.execute_request(:delete, '/v1/charges')
|
||||
client.execute_request(:delete, "/v1/charges/#{API_FIXTURES.fetch(:charge)[:id]}")
|
||||
end
|
||||
|
||||
should 'not override a provided idempotency_key' do
|
||||
@ -322,10 +322,10 @@ module Stripe
|
||||
# expected.
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/charges").
|
||||
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.execute_request(:post, '/v1/charges',
|
||||
client.execute_request(:post, "/v1/charges",
|
||||
headers: {:idempotency_key => 'provided_key'})
|
||||
end
|
||||
end
|
||||
@ -370,7 +370,7 @@ module Stripe
|
||||
context "#request" do
|
||||
should "return a result and response object" do
|
||||
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
|
||||
charge, resp = client.request { Charge.create }
|
||||
|
@ -116,9 +116,13 @@ module Stripe
|
||||
|
||||
# customer comes with a `sources` list that makes a convenient object to
|
||||
# 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
|
||||
# important enough argument that the test here is worth it. we should
|
||||
# consider exposing it publicly on a future pull (and possibly renaming
|
||||
|
@ -2,62 +2,53 @@ require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
module Stripe
|
||||
class SubscriptionItemTest < Test::Unit::TestCase
|
||||
should "subscription items should be retrievable" do
|
||||
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')
|
||||
FIXTURE = API_FIXTURES.fetch(: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
|
||||
|
||||
should "subscription items should be listable" do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/subscription_items").
|
||||
with(query: { subscription: "s_test_subscription", limit: "3" }).
|
||||
to_return(body: JSON.generate(make_subscription_item_array))
|
||||
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
|
||||
should "be retrievable" do
|
||||
item = Stripe::SubscriptionItem.retrieve(FIXTURE[:id])
|
||||
assert_requested :get, "#{Stripe.api_base}/v1/subscription_items/#{FIXTURE[:id]}"
|
||||
assert item.kind_of?(Stripe::SubscriptionItem)
|
||||
end
|
||||
|
||||
should "subscription items should be deletable" do
|
||||
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')
|
||||
|
||||
stub_request(:delete, "#{Stripe.api_base}/v1/subscription_items/#{sub_item.id}").
|
||||
to_return(body: JSON.generate(make_subscription_item))
|
||||
sub_item.delete
|
||||
should "be creatable" do
|
||||
item = Stripe::SubscriptionItem.create(
|
||||
item: 'silver',
|
||||
plan: API_FIXTURES.fetch(:plan)[:id],
|
||||
quantity: 3,
|
||||
subscription: API_FIXTURES.fetch(:subscription)[:id]
|
||||
)
|
||||
assert_requested :post, "#{Stripe.api_base}/v1/subscription_items"
|
||||
assert item.kind_of?(Stripe::SubscriptionItem)
|
||||
end
|
||||
|
||||
should "subscription items should be updateable" do
|
||||
sid = 'si_test_subscription_item'
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/subscription_items/#{sid}").
|
||||
with(body: { plan: "silver", quantity: "3" }).
|
||||
to_return(body: JSON.generate(make_subscription_item))
|
||||
|
||||
_ = Stripe::SubscriptionItem.update(sid, {:plan => 'silver', :quantity => 3})
|
||||
should "be saveable" do
|
||||
item = Stripe::SubscriptionItem.retrieve(FIXTURE[:id])
|
||||
item.quantity = 4
|
||||
item.save
|
||||
assert_requested :post, "#{Stripe.api_base}/v1/subscription_items/#{FIXTURE[:id]}"
|
||||
end
|
||||
|
||||
should "subscription items should be saveable" do
|
||||
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')
|
||||
|
||||
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
|
||||
should "be updateable" do
|
||||
item = Stripe::SubscriptionItem.update(FIXTURE[:id], metadata: {foo: 'bar'})
|
||||
assert_requested :post, "#{Stripe.api_base}/v1/subscription_items/#{FIXTURE[:id]}"
|
||||
assert item.kind_of?(Stripe::SubscriptionItem)
|
||||
end
|
||||
|
||||
should "create should return a new subscription item" do
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/subscription_items").
|
||||
with(body: { plan: "silver", quantity: "3" }).
|
||||
to_return(body: JSON.generate(make_subscription_item))
|
||||
|
||||
_ = Stripe::SubscriptionItem.create(:plan => 'silver', :quantity => 3)
|
||||
should "be deletable" do
|
||||
item = Stripe::SubscriptionItem.retrieve(FIXTURE[:id])
|
||||
item = item.delete
|
||||
assert_requested :delete, "#{Stripe.api_base}/v1/subscription_items/#{FIXTURE[:id]}"
|
||||
assert item.kind_of?(Stripe::SubscriptionItem)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -2,136 +2,59 @@ require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
module Stripe
|
||||
class SubscriptionTest < Test::Unit::TestCase
|
||||
should "subscriptions should be retrievable by customer" do
|
||||
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')
|
||||
FIXTURE = API_FIXTURES.fetch(:subscription)
|
||||
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/customers/c_test_customer/subscriptions/s_test_subscription").
|
||||
to_return(body: JSON.generate(make_subscription))
|
||||
_ = customer.subscriptions.retrieve('s_test_subscription')
|
||||
should "be listable" do
|
||||
subscriptions = Stripe::Subscription.list
|
||||
assert_requested :get, "#{Stripe.api_base}/v1/subscriptions"
|
||||
assert subscriptions.data.kind_of?(Array)
|
||||
assert subscriptions.data[0].kind_of?(Stripe::Subscription)
|
||||
end
|
||||
|
||||
should "subscriptions should be listable by customer" do
|
||||
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").
|
||||
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
|
||||
should "be retrievable" do
|
||||
subscription = Stripe::Subscription.retrieve(FIXTURE[:id])
|
||||
assert_requested :get,
|
||||
"#{Stripe.api_base}/v1/subscriptions/#{FIXTURE[:id]}"
|
||||
assert subscription.kind_of?(Stripe::Subscription)
|
||||
end
|
||||
|
||||
should "subscriptions should be creatable by customer" do
|
||||
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(:post, "#{Stripe.api_base}/v1/customers/c_test_customer/subscriptions").
|
||||
with(body: { plan: "silver" }).
|
||||
to_return(body: JSON.generate(make_subscription))
|
||||
_ = customer.subscriptions.create(:plan => 'silver')
|
||||
should "be creatable" do
|
||||
subscription = Stripe::Subscription.create(
|
||||
customer: API_FIXTURES.fetch(:customer)[:id]
|
||||
)
|
||||
assert_requested :post, "#{Stripe.api_base}/v1/subscriptions"
|
||||
assert subscription.kind_of?(Stripe::Subscription)
|
||||
end
|
||||
|
||||
should "subscriptions should be retrievable" 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')
|
||||
|
||||
assert sub.kind_of?(Stripe::Subscription)
|
||||
should "be saveable" do
|
||||
subscription = Stripe::Subscription.retrieve(FIXTURE[:id])
|
||||
subscription.metadata['key'] = 'value'
|
||||
subscription.save
|
||||
assert_requested :post,
|
||||
"#{Stripe.api_base}/v1/subscriptions/#{FIXTURE[:id]}"
|
||||
end
|
||||
|
||||
should "subscriptions should be listable" do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/subscriptions").
|
||||
to_return(body: JSON.generate(make_subscription_array))
|
||||
subs = Stripe::Subscription.list.data
|
||||
|
||||
assert subs.kind_of? Array
|
||||
assert subs[0].kind_of? Stripe::Subscription
|
||||
should "be updateable" do
|
||||
subscription = Stripe::Subscription.update(FIXTURE[:id], metadata: {foo: 'bar'})
|
||||
assert_requested :post,
|
||||
"#{Stripe.api_base}/v1/subscriptions/#{FIXTURE[:id]}"
|
||||
assert subscription.kind_of?(Stripe::Subscription)
|
||||
end
|
||||
|
||||
should "subscriptions should be listable with filters" do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/subscriptions").
|
||||
with(query: { customer: "c_test_customer", limit: "3", plan: "gold" }).
|
||||
to_return(body: JSON.generate(make_subscription_array))
|
||||
subs = Stripe::Subscription.all(:customer => 'c_test_customer', :limit => 3, :plan => 'gold')
|
||||
|
||||
assert subs.kind_of?(Stripe::ListObject)
|
||||
assert subs.data.kind_of?(Array)
|
||||
assert subs.data[0].kind_of? Stripe::Subscription
|
||||
should "be deletable" do
|
||||
subscription = Stripe::Subscription.retrieve(FIXTURE[:id])
|
||||
subscription = subscription.delete
|
||||
assert_requested :delete,
|
||||
"#{Stripe.api_base}/v1/subscriptions/#{FIXTURE[:id]}"
|
||||
assert subscription.kind_of?(Stripe::Subscription)
|
||||
end
|
||||
|
||||
should "subscriptions should be refreshable" 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')
|
||||
sub.refresh
|
||||
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
|
||||
context "#delete_discount" do
|
||||
should "be able to delete a subscriptions's discount" do
|
||||
subscription = Stripe::Subscription.retrieve(FIXTURE[:id])
|
||||
subscription = subscription.delete_discount
|
||||
assert subscription.kind_of?(Stripe::Subscription)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -2,23 +2,22 @@ require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
module Stripe
|
||||
class ThreeDSecureTest < Test::Unit::TestCase
|
||||
should "retrieve an existing 3D Secure object" do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/3d_secure/tdsrc_test").
|
||||
to_return(body: JSON.generate(make_three_d_secure))
|
||||
tds = Stripe::ThreeDSecure.retrieve("tdsrc_test")
|
||||
assert_equal "tdsrc_test", tds.id
|
||||
FIXTURE = API_FIXTURES.fetch(:three_d_secure)
|
||||
|
||||
should "be retrievable" do
|
||||
secure = Stripe::ThreeDSecure.retrieve(FIXTURE[:id])
|
||||
assert_requested :get, "#{Stripe.api_base}/v1/3d_secure/#{FIXTURE[:id]}"
|
||||
assert secure.kind_of?(Stripe::ThreeDSecure)
|
||||
end
|
||||
|
||||
should "create should return a new 3D Secure object" 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))
|
||||
should "be creatable" do
|
||||
_ = Stripe::ThreeDSecure.create(
|
||||
:card => "tok_test",
|
||||
:amount => 1500,
|
||||
:currency => "usd",
|
||||
:return_url => "https://example.org/3d-secure-result"
|
||||
card: API_FIXTURES.fetch(:token)[:id],
|
||||
amount: 1500,
|
||||
currency: "usd",
|
||||
return_url: "https://example.org/3d-secure-result"
|
||||
)
|
||||
assert_requested :post, "#{Stripe.api_base}/v1/3d_secure"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -2,35 +2,49 @@ require File.expand_path('../../test_helper', __FILE__)
|
||||
|
||||
module Stripe
|
||||
class TransferTest < Test::Unit::TestCase
|
||||
should "retrieve should retrieve transfer" do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/transfers/tr_test_transfer").
|
||||
to_return(body: JSON.generate(make_transfer))
|
||||
transfer = Stripe::Transfer.retrieve('tr_test_transfer')
|
||||
assert_equal 'tr_test_transfer', transfer.id
|
||||
FIXTURE = API_FIXTURES.fetch(:transfer)
|
||||
|
||||
should "be listable" do
|
||||
transfers = Stripe::Transfer.list
|
||||
assert_requested :get, "#{Stripe.api_base}/v1/transfers"
|
||||
assert transfers.data.kind_of?(Array)
|
||||
assert transfers.data[0].kind_of?(Stripe::Transfer)
|
||||
end
|
||||
|
||||
should "create should create a transfer" do
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/transfers").
|
||||
to_return(body: JSON.generate(make_transfer))
|
||||
transfer = Stripe::Transfer.create
|
||||
assert_equal "tr_test_transfer", transfer.id
|
||||
should "be retrievable" do
|
||||
transfer = Stripe::Transfer.retrieve(FIXTURE[:id])
|
||||
assert_requested :get, "#{Stripe.api_base}/v1/transfers/#{FIXTURE[:id]}"
|
||||
assert transfer.kind_of?(Stripe::Transfer)
|
||||
end
|
||||
|
||||
should "create should update a transfer" do
|
||||
stub_request(:post, "#{Stripe.api_base}/v1/transfers/test_transfer").
|
||||
with(body: { metadata: { foo: "bar" } }).
|
||||
to_return(body: JSON.generate(make_transfer))
|
||||
Stripe::Transfer.update("test_transfer", metadata: {foo: 'bar'})
|
||||
should "be creatable" do
|
||||
transfer = Stripe::Transfer.create(
|
||||
amount: 100,
|
||||
currency: "USD"
|
||||
)
|
||||
assert_requested :post, "#{Stripe.api_base}/v1/transfers"
|
||||
assert transfer.kind_of?(Stripe::Transfer)
|
||||
end
|
||||
|
||||
should "cancel should cancel a transfer" do
|
||||
stub_request(:get, "#{Stripe.api_base}/v1/transfers/tr_test_transfer").
|
||||
to_return(body: JSON.generate(make_transfer))
|
||||
transfer = Stripe::Transfer.retrieve('tr_test_transfer')
|
||||
should "be saveable" do
|
||||
transfer = Stripe::Transfer.retrieve(FIXTURE[:id])
|
||||
transfer.metadata['key'] = 'value'
|
||||
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").
|
||||
to_return(body: JSON.generate(make_canceled_transfer))
|
||||
transfer.cancel
|
||||
should "be updateable" do
|
||||
transfer = Stripe::Transfer.update(FIXTURE[:id], metadata: {foo: 'bar'})
|
||||
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
|
||||
|
Loading…
x
Reference in New Issue
Block a user