require 'test_helper'
require 'active_merchant/billing/gateways/heartland_portico'
class HeartlandPorticoTest < Test::Unit::TestCase
def setup
@gateway = HeartlandPorticoGateway.new(
:user_name => 'login',
:password => 'password',
:developer_i_d => '',
:device_id => '',
:license_id => '',
:site_id => '',
:version_nbr => ''
)
@credit_card = credit_card
@amount = 100
@options = {
:order_id => '1',
:billing_address => address,
:description => 'Store Purchase'
}
end
def savon_mock(response)
Savon::Operation.any_instance.expects(:call_with_logging).returns(HTTPI::Response.new(200,{},response))
end
def test_successful_purchase
savon_mock(successful_purchase_response)
assert response = @gateway.purchase(@amount, @credit_card, @options)
#assert_instance_of Response, response
assert_success response
# Replace with authorization number from the successful response
assert_equal '9414170', response.authorization
assert response.test?
end
def test_unsuccessful_request
savon_mock(failed_purchase_response)
assert response = @gateway.purchase(@amount, @credit_card, @options)
assert_failure response
assert response.test?
end
def test_cardholder_data
post = {}
options = {
:billing_address => {
:zip => 'K1C2N6',
:phone => "2505551234"
}
}
@gateway.send(:add_address, post, @credit_card, options)
assert_equal "K1C2N6", post[:card_holder_data][:card_holder_zip]
assert_equal "2505551234", post[:card_holder_data][:card_holder_phone]
assert_equal "", post[:card_holder_data][:card_holder_addr]
end
private
# Place raw successful response from gateway here
def successful_purchase_response
<<-XML
21198
21201
1525731
9414170
0
Success
2014-01-03T17:53:27.9004696
00
APPROVAL
27090A
0
400313728279
Visa
AVS Not Requested.
XML
end
# Place raw failed response from gateway here
def failed_purchase_response
<<-XML
21198
21201
1525731
9416864
0
Success
2014-01-03T17:53:29.1328775
05
DECLINE
0
400313728664
Visa
AVS Not Requested.
XML
end
end