require File.dirname(__FILE__) + '/../remote_helper' class RemoteOrderTest < ActiveSupport::TestCase def setup MuckCommerce::Configure.enable_live_test_gateway end context "Remote Order" do setup do @options = { :description => 'A store purchase' } @amount = rand(10000) # This helps prevent 'duplicate transaction' errors from the live gateway @coupons = [] end context "valid credit card" do setup do @order = Order.new @user, @billing_information = setup_live_user_and_billing end teardown do cleanup_cim(@billing_information) end should "succesfully checkout" do assert_difference "Order.count", 1 do success, purchase_made, purchase = @order.checkout(@billing_information, @amount, @coupons, @options) assert success assert purchase_made assert purchase.success? assert @order.order_transactions.count > 0 end @user.reload assert !@user.orders.empty? end end context "invalid credit card" do # This uses an empty cart to send in a 0 value to the test gateway. # In response the gateway will return declined instead of throwing an exception setup do @order = Order.new @user, @billing_information = setup_live_user_and_billing(:credit_card_number => MuckCommerceTestDefinitions::BRAIN_MASTERCARD) end should "fail checkout" do assert_no_difference "Order.count" do assert_no_difference "OrderTransaction.count" do assert_raise(MuckCommerce::Exceptions::PaymentGatewayError, 'There was a problem processing your order') do success, purchase_made, purchase = @order.checkout(@billing_information, @amount, @coupons, @options) assert !success assert !purchase_made assert !purchase.success? end end end end end context "exception credit card" do setup do @order = Order.new @user, @billing_information = setup_live_user_and_billing(:credit_card_number => MuckCommerceTestDefinitions::EXCEPTION_CARD) end should "throw exception during checkout" do assert_no_difference "Order.count" do assert_raise(MuckCommerce::Exceptions::PaymentGatewayError, 'Invalid credit card information') do @order.checkout(@billing_information, @amount, @coupons, @options) end end end end end end