require File.dirname(__FILE__) + '/../remote_helper' class RemoteOrdersControllerTest < ActionController::TestCase tests Muck::OrdersController should_require_login :index => :get, :login_url => '/login' context "orders controller" do setup do MuckCommerce::Configure.enable_live_test_gateway end teardown do MuckCommerce::Configure.disable_live_test_gateway end context "logged in without billing information" do setup do @user = Factory(:user) populate_cart(@user) activate_authlogic login_as @user end context "POST create order with new billing information" do setup do post_create_live_billing end teardown do cleanup_cim(assigns(:billing_information)) end should_not_set_the_flash should_redirect_to("new order path") { user_order_path(@user, assigns(:order), :new_order => true) } should "not have errors on the billing object" do assert assigns(:billing_information).errors.empty?, assigns(:billing_information).errors.full_messages.to_sentence end end context "POST create with bad verification value" do setup do post_create_live_billing(:verification_value => '') end should_respond_with :success should_render_template :new should "have errors on the billing object" do assert assigns(:billing_information).errors.on(:verification_value), assigns(:billing_information).errors.full_messages.to_sentence end end context "POST create with bad credit card" do setup do post_create_live_billing(:credit_card_number => '') end should_respond_with :success should_render_template :new should "have errors on the billing object" do assert assigns(:billing_information).errors.on(:credit_card_number), assigns(:billing_information).errors.full_messages.to_sentence end end end context "user logged in with existing billing information" do setup do @user, @billing_information = setup_live_user_and_billing # send billing info to the CIM response = try_cim(@user, @billing_information) { |user, billing_information| OrderTransaction.cim_create(user, billing_information) } assert response.success?, response.message assert @user.customer_profile_id assert @billing_information.customer_payment_profile_id assert @billing_information.has_billing_profile? @user.order_transactions.push(response) @user.reload populate_cart(@user) activate_authlogic login_as @user end teardown do cleanup_cim(@billing_information) end should "assign billing information" do assert @billing_information.billable == @user, "Billing user is #{@billing_information.billable.login} but user is #{@user}" end context "POST create order with existing billing information" do setup do try_cim_post do post :create, :amount => 1000 end end should_not_set_the_flash should "have valid CIM profile ids" do assert @user.billing_information, "User does not have any billing information." assert @billing_information.has_billing_profile? end should_redirect_to("user order path") { user_order_path(@user, assigns(:order), :new_order => true) } should "not have errors on the billing object" do assert assigns(:billing_information).errors.empty?, assigns(:billing_information).errors.full_messages.to_sentence end end context "POST create order with updated billing information" do setup do post_create_live_billing({:telephone => '777-555-2222'}, true) end teardown do cleanup_cim(assigns(:billing_information)) end should_not_set_the_flash should_redirect_to("user order path") { user_order_path(assigns(:user), assigns(:order), :new_order => true) } should "not have errors on the billing object" do assert assigns(:billing_information).errors.empty?, assigns(:billing_information).errors.full_messages.to_sentence end end context "POST create order with bad credit card" do setup do post_create_live_billing({:credit_card_type => 'bogus', :credit_card_number => '2232'}, true) end should_respond_with :success should_render_template :new should "have errors on the billing object" do assert assigns(:billing_information).errors.on(:credit_card_number), assigns(:billing_information).errors.full_messages.to_sentence end end end # TODO add these tests after adding ach support # create order with ach information # update billing during checkout with bad ach end end