require 'test_helper'
class EfsnetTest < Test::Unit::TestCase
def setup
@gateway = EfsnetGateway.new(
:login => 'LOGIN',
:password => 'PASSWORD'
)
@credit_card = credit_card('4242424242424242')
@amount = 100
@options = { :order_id => 1, :billing_address => address }
end
def test_successful_purchase
@gateway.expects(:ssl_post).returns(successful_purchase_response)
assert response = @gateway.purchase(@amount, @credit_card, @options)
assert_instance_of Response, response
assert_success response
assert response.test?
assert_equal '100018347764;1.00', response.authorization
assert_equal 'Approved', response.message
end
def test_unsuccessful_purchase
@gateway.expects(:ssl_post).returns(unsuccessful_purchase_response)
assert response = @gateway.purchase(@amount, @credit_card, @options)
assert_instance_of Response, response
assert_failure response
assert response.test?
assert_equal 'Declined', response.message
end
def test_authorize_is_valid_xml
params = {
:order_id => "order1",
:transaction_amount => "1.01",
:account_number => "4242424242424242",
:expiration_month => "12",
:expiration_year => "2029",
}
assert data = @gateway.send(:post_data, :credit_card_authorize, params)
assert REXML::Document.new(data)
end
def test_settle_is_valid_xml
params = {
:order_id => "order1",
:transaction_amount => "1.01",
:original_transaction_amount => "1.01",
:original_transaction_id => "1",
}
assert data = @gateway.send(:post_data, :credit_card_settle, params)
assert REXML::Document.new(data)
end
def test_avs_result
@gateway.expects(:ssl_post).returns(successful_purchase_response)
response = @gateway.purchase(@amount, @credit_card, @options)
assert_equal 'N', response.avs_result['code']
end
def test_cvv_result
@gateway.expects(:ssl_post).returns(successful_purchase_response)
response = @gateway.purchase(@amount, @credit_card, @options)
assert_equal 'M', response.cvv_result['code']
end
private
def successful_purchase_response
<<-XML
0
00
APPROVED
100018347764
N
M
123456
123456
080117
163222
1
XXXXXXXXXXXX2224
1.00
XML
end
def unsuccessful_purchase_response
<<-XML
256
04
DECLINED
100018347784
N
080117
163946
1
XXXXXXXXXXXX2224
1.56
XML
end
end