require File.dirname(__FILE__) + "/../test_helper" class PurchaseTest < Test::Unit::TestCase def setup @transporter = EWS::Transporter.new(LOCATION) end def test_mandatory request = EWS::Transaction::Request.new(:transaction_type => :purchase) assert !request.valid? assert_equal "gateway_id must be supplied", request.errors[:gateway_id] request.gateway_id = EMERGIS_BASIC_AUTH[:gateway_id] assert !request.valid? assert_equal "password must be supplied", request.errors[:password] request.password = EMERGIS_BASIC_AUTH[: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 request = EWS::Transaction::Request.new(cc_number_params.merge(:transaction_type => :purchase)) 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 request = EWS::Transaction::Request.new(track1_params.merge(:transaction_type => :purchase)) 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 request = EWS::Transaction::Request.new(track2_params.merge(:transaction_type => :purchase)) 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