test/stripe/order_test.rb in stripe-1.58.0 vs test/stripe/order_test.rb in stripe-2.0.0

- old
+ new

@@ -1,72 +1,59 @@ require File.expand_path('../../test_helper', __FILE__) module Stripe class OrderTest < Test::Unit::TestCase - should "orders should be listable" do - @mock.expects(:get).once.returns(make_response(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 order.kind_of?(Stripe::Order) - end + assert orders.first.kind_of?(Stripe::Order) end - should "orders should not be deletable" do - assert_raises NoMethodError do - @mock.expects(:get).once.returns(make_response(make_order)) - p = Stripe::Order.retrieve("test_order") - p.delete - 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 "orders should be saveable" do - @mock.expects(:get).once.returns(make_response(make_order)) - @mock.expects(:post).once.returns(make_response(make_order)) - p = Stripe::Order.new("test_order") - p.refresh - p.status = "fulfilled" - p.save + 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 "orders should be updateable" do - @mock.expects(:post).once. - with('https://api.stripe.com/v1/orders/test_order', nil, 'status=fulfilled'). - returns(make_response(make_order(status: 'fulfilled'))) - ii = Stripe::Order.update("test_order", status: 'fulfilled') - assert_equal('fulfilled', ii.status) + 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 "orders should allow metadata updates" do - @mock.expects(:get).once.returns(make_response(make_order)) - @mock.expects(:post).once.returns(make_response(make_order)) - p = Stripe::Order.new("test_order") - p.refresh - p.metadata['key'] = 'value' - p.save + 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 - should "pay should pay an order" do - @mock.expects(:get).once. - returns(make_response(make_order(:id => 'or_test_order'))) - order = Stripe::Order.retrieve('or_test_order') - - @mock.expects(:post).once. - with('https://api.stripe.com/v1/orders/or_test_order/pay', nil, 'token=test_token'). - returns(make_response(make_paid_order)) - order.pay(:token => 'test_token') - assert_equal "paid", order.status + 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 "return an order" do - @mock.expects(:get).once. - returns(make_response(make_order(:id => 'or_test_order'))) - order = Stripe::Order.retrieve('or_test_order') - - @mock.expects(:post).once. - with('https://api.stripe.com/v1/orders/or_test_order/returns', nil, 'items[][parent]=sku_foo'). - returns(make_response(make_order_return({:order => order.id}))) - order_return = order.return_order(:items => [{:parent => 'sku_foo'}]) - assert_equal order.id, order_return.order + 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 end end