require File.dirname(__FILE__) + "/../test_helper" class TransporterTest < Test::Unit::TestCase def test_invalid_transport_type txn = ::EWS::Transaction::Request.new({ :transaction_type => :purchase, :amount => "10.13", :cardholder_name => "Simon Brown", :cc_number => "4111111111111111", :cc_expiry => "1012", :reference_no => "987987", }.merge(@@credentials.current_gateway)) tr = ::EWS::Transporter.new(@@credentials.config['location']) # should raise an exception when transport_type is not one of :json, :rest or :soap assert_raises(ArgumentError) { tr.submit(txn, :banana) } end def test_no_errors_thrown txn = ::EWS::Transaction::Request.new({ :transaction_type => :purchase, :amount => "10.13", :cardholder_name => "Simon Brown", :cc_number => "4111111111111111", :cc_expiry => "1012", :reference_no => "987987", }.merge(@@credentials.current_gateway)) assert_nothing_raised { tr = ::EWS::Transporter.new(@@credentials.config['location']) tr.submit(txn) } end def test_returns_response_object_on_server_failure req = ::EWS::Transaction::Request.new({ :transaction_type => :transaction_details }.merge(@@credentials.current_gateway)) req.transaction_tag = 9000 # non-existent txn tr = ::EWS::Transporter.new(@@credentials.config['location']) resp = tr.submit(req, :json) assert_not_nil resp assert_equal 404, resp.error_number assert_equal "Not Found", resp.error_description.strip end def test_uses_supplied_certificates req = ::EWS::Transaction::Request.new({ :transaction_type => :purchase, :amount => "10.13", :cardholder_name => "Simon Brown", :cc_number => "4111111111111111", :cc_expiry => "1012", :reference_no => "987987", }.merge(@@credentials.current_gateway)) tr = ::EWS::Transporter.new(@@credentials.config['location'], { :issuer_cert => File.dirname(__FILE__)+"/../../certs/valicert_class2_root.crt", :server_cert => File.dirname(__FILE__)+"/../../certs/e-xact.com.crt" }) resp = tr.submit(req, :json) assert_not_nil resp assert resp.approved? end end