test/stripe/bitcoin_receiver_test.rb in stripe-1.58.0 vs test/stripe/bitcoin_receiver_test.rb in stripe-2.0.0
- old
+ new
@@ -1,61 +1,70 @@
require File.expand_path('../../test_helper', __FILE__)
module Stripe
class BitcoinReceiverTest < Test::Unit::TestCase
- should "retrieve should retrieve bitcoin receiver" do
- @mock.expects(:get).once.returns(make_response(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
- @mock.expects(:post).once.returns(make_response(make_bitcoin_receiver))
- receiver = Stripe::BitcoinReceiver.create
- assert_equal "btcrcv_test_receiver", receiver.id
+ should "be listable" do
+ receivers = Stripe::BitcoinReceiver.list
+ assert_requested :get, "#{Stripe.api_base}/v1/bitcoin/receivers"
+ assert receivers.data.kind_of?(Array)
+ assert receivers.first.kind_of?(Stripe::BitcoinReceiver)
end
- should "all should list bitcoin receivers" do
- @mock.expects(:get).once.returns(make_response(make_bitcoin_receiver_array))
- 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
+ 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
- should "maintain bitcoin transaction sublist" do
- @mock.expects(:get).with("#{Stripe.api_base}/v1/bitcoin/receivers/btcrcv_test_receiver", nil, nil).once.returns(make_response(make_bitcoin_receiver))
- receiver = Stripe::BitcoinReceiver.retrieve('btcrcv_test_receiver')
- @mock.expects(:get).with("#{Stripe.api_base}/v1/bitcoin/receivers/btcrcv_test_receiver/transactions", nil, nil).once.returns(make_response(make_bitcoin_transaction_array))
- transactions = receiver.transactions.list
- assert_equal(3, transactions.data.length)
+ 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
- should "update should update a bitcoin receiver" do
- @mock.expects(:get).once.returns(make_response(make_bitcoin_receiver))
- @mock.expects(:post).with("#{Stripe.api_base}/v1/bitcoin/receivers/btcrcv_test_receiver", nil, "description=details").once.returns(make_response(make_bitcoin_receiver))
- receiver = Stripe::BitcoinReceiver.construct_from(make_bitcoin_receiver)
- receiver.refresh
- 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
- @mock.expects(:delete).with("#{Stripe.api_base}/v1/bitcoin/receivers/btcrcv_test_receiver", nil, nil).once.returns(make_response({:deleted => true, :id => "btcrcv_test_receiver"}))
- receiver = Stripe::BitcoinReceiver.construct_from(make_bitcoin_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
- @mock.expects(:delete).with("#{Stripe.api_base}/v1/customers/customer_foo/sources/btcrcv_test_receiver", nil, nil).once.returns(make_response({:deleted => true, :id => "btcrcv_test_receiver"}))
- receiver = Stripe::BitcoinReceiver.construct_from(make_bitcoin_receiver(:customer => 'customer_foo'))
- 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