mirror of
https://github.com/stripe/stripe-ruby.git
synced 2025-10-06 00:02:18 -04:00
80 lines
2.6 KiB
Ruby
80 lines
2.6 KiB
Ruby
require File.expand_path('../../test_helper', __FILE__)
|
|
|
|
module Stripe
|
|
class InvoiceTest < Test::Unit::TestCase
|
|
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 "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 "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
|
|
|
|
should "pay invoice with a specific source" do
|
|
invoice = Stripe::Invoice.retrieve(FIXTURE[:id])
|
|
invoice = invoice.pay(
|
|
source: API_FIXTURES[:customer][:sources][:data][0][:id]
|
|
)
|
|
assert_requested :post,
|
|
"#{Stripe.api_base}/v1/invoices/#{FIXTURE[:id]}/pay",
|
|
body: {
|
|
source: API_FIXTURES[:customer][:sources][:data][0][:id]
|
|
}
|
|
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
|