require File.dirname(__FILE__) + "/../test_helper" class PreAuthOnlyTest < Test::Unit::TestCase def setup @transporter = EWS::Transporter.new(@@credentials.config['location']) end def test_mandatory request = EWS::Transaction::Request.new(:transaction_type => :pre_auth_only) assert !request.valid? assert_equal "gateway_id must be supplied", request.errors[:gateway_id] request.gateway_id = @@credentials.current_gateway[:gateway_id] assert !request.valid? assert_equal "password must be supplied", request.errors[:password] request.password = @@credentials.current_gateway[:password] assert !request.valid? assert_equal "One of the following must be supplied: cc_number, track1, track2 or transaction_tag.", request.errors[:base] request.cc_number = "4111111111111111" assert !request.valid? assert_equal "cc_expiry must be supplied", request.errors[:cc_expiry] request.cc_expiry = "0913" assert !request.valid? assert_equal "cardholder_name must be supplied", request.errors[:cardholder_name] request.cardholder_name = "Simon Jones" assert !request.valid? assert_equal "amount must be supplied", request.errors[:amount] request.amount = 10 assert request.valid? end def test_by_credit_card return unless @@credentials.chase? || @@credentials.emergis? request = EWS::Transaction::Request.new(cc_number_params.merge(:transaction_type => :pre_auth_only)) request.amount = 11.25 assert request.valid?, request.errors.inspect assert_details_correct request, @transporter.submit(request, :json) assert_details_correct request, @transporter.submit(request, :rest) assert_details_correct request, @transporter.submit(request, :soap) end def test_by_track1 return unless @@credentials.chase? || @@credentials.emergis? request = EWS::Transaction::Request.new(track1_params.merge(:transaction_type => :pre_auth_only)) request.amount = 11.25 assert request.valid?, request.errors.inspect assert_details_correct request, @transporter.submit(request, :json) assert_details_correct request, @transporter.submit(request, :rest) assert_details_correct request, @transporter.submit(request, :soap) end def test_by_track2 return unless @@credentials.chase? || @@credentials.emergis? request = EWS::Transaction::Request.new(track2_params.merge(:transaction_type => :pre_auth_only)) request.amount = 11.25 assert request.valid?, request.errors.inspect assert_details_correct request, @transporter.submit(request, :json) assert_details_correct request, @transporter.submit(request, :rest) assert_details_correct request, @transporter.submit(request, :soap) end end