test/unit/gateways/moneris_test.rb in activemerchant-1.2.1 vs test/unit/gateways/moneris_test.rb in activemerchant-1.3.0
- old
+ new
@@ -1,48 +1,36 @@
require File.dirname(__FILE__) + '/../../test_helper'
-class MonerisResponseTest < Test::Unit::TestCase
+class MonerisTest < Test::Unit::TestCase
def setup
+ Base.mode = :test
+
@gateway = MonerisGateway.new(
:login => 'store1',
:password => 'yesguy'
)
- @creditcard = credit_card('4242424242424242')
+ @amount = 100
+ @credit_card = credit_card('4242424242424242')
+ @options = { :order_id => '1', :billing_address => address }
end
- def teardown
- Base.mode = :test
- end
+ def test_successful_purchase
+ @gateway.expects(:ssl_post).returns(successful_purchase_response)
- def test_purchase_success
- @creditcard.number = 1
-
- assert response = @gateway.purchase(100, @creditcard, :order_id => 1)
- assert_equal Response, response.class
- assert_equal '#0001', response.params['receiptid']
- assert_equal true, response.success?
+ assert response = @gateway.authorize(100, @credit_card, @options)
+ assert_success response
+ assert_equal '58-0_3;1026.1', response.authorization
end
- def test_purchase_error
- @creditcard.number = 2
-
- assert response = @gateway.purchase(100, @creditcard, :order_id => 1)
- assert_equal Response, response.class
- assert_equal '#0001', response.params['receiptid']
- assert_equal false, response.success?
-
- end
+ def test_failed_purchase
+ @gateway.expects(:ssl_post).returns(failed_purchase_response)
- def test_purchase_exceptions
- @creditcard.number = 3
-
- assert_raise(Error) do
- assert response = @gateway.purchase(100, @creditcard, :order_id => 1)
- end
+ assert response = @gateway.authorize(100, @credit_card, @options)
+ assert_failure response
end
-
+
def test_amount_style
assert_equal '10.34', @gateway.send(:amount, 1034)
assert_raise(ArgumentError) do
@gateway.send(:amount, '10.34')
@@ -62,32 +50,10 @@
assert data = @gateway.send(:post_data, 'preauth', params)
assert REXML::Document.new(data)
assert_equal xml_capture_fixture.size, data.size
end
- private
-
- def xml_purchase_fixture
- %q{<request><store_id>store1</store_id><api_token>yesguy</api_token><purchase><amount>1.01</amount><pan>4242424242424242</pan><expdate>0303</expdate><crypt_type>7</crypt_type><order_id>order1</order_id></purchase></request>}
- end
-
- def xml_capture_fixture
- %q{<request><store_id>store1</store_id><api_token>yesguy</api_token><preauth><amount>1.01</amount><pan>4242424242424242</pan><expdate>0303</expdate><crypt_type>7</crypt_type><order_id>order1</order_id></preauth></request>}
- end
-
-end
-
-
-class MonerisRequestTest < Test::Unit::TestCase
- def setup
- @gateway = MonerisGateway.new(
- :login => 'store1',
- :password => 'yesguy'
- )
- end
-
-
def test_purchase_is_valid_xml
params = {
:order_id => "order1",
:amount => "1.01",
@@ -113,31 +79,11 @@
assert data = @gateway.send(:post_data, 'preauth', params)
assert REXML::Document.new(data)
assert_equal xml_capture_fixture.size, data.size
end
-
- def test_access_url_for_test_environment
- Base.mode = :test
- gateway = MonerisGateway.new(
- :login => 'store1',
- :password => 'yesguy'
- )
-
- assert_equal 'https://esqa.moneris.com/gateway2/servlet/MpgRequest', gateway.url
- end
- def test_access_url_for_production_environment
- Base.mode = :production
- gateway = MonerisGateway.new(
- :login => 'store1',
- :password => 'yesguy'
- )
-
- assert_equal 'https://www3.moneris.com/gateway2/servlet/MpgRequest', gateway.url
- end
-
def test_supported_countries
assert_equal ['CA'], MonerisGateway.supported_countries
end
def test_supported_card_types
@@ -148,20 +94,65 @@
[nil, '', '1234'].each do |invalid_transaction_param|
assert_raise(ArgumentError) { @gateway.void(invalid_transaction_param) }
end
end
- def test_should_not_raise_error_if_transaction_param_is_not_empty_on_credit_request
- assert_nothing_raised(ArgumentError) { @gateway.void('1234;456') }
+ private
+ def successful_purchase_response
+ <<-RESPONSE
+<?xml version="1.0"?>
+<response>
+ <receipt>
+ <ReceiptId>1026.1</ReceiptId>
+ <ReferenceNum>661221050010170010</ReferenceNum>
+ <ResponseCode>027</ResponseCode>
+ <ISO>01</ISO>
+ <AuthCode>013511</AuthCode>
+ <TransTime>18:41:13</TransTime>
+ <TransDate>2008-01-05</TransDate>
+ <TransType>00</TransType>
+ <Complete>true</Complete>
+ <Message>APPROVED * =</Message>
+ <TransAmount>1.00</TransAmount>
+ <CardType>V</CardType>
+ <TransID>58-0_3</TransID>
+ <TimedOut>false</TimedOut>
+ </receipt>
+</response>
+
+ RESPONSE
end
+
+ def failed_purchase_response
+ <<-RESPONSE
+<?xml version="1.0"?>
+<response>
+ <receipt>
+ <ReceiptId>1026.1</ReceiptId>
+ <ReferenceNum>661221050010170010</ReferenceNum>
+ <ResponseCode>481</ResponseCode>
+ <ISO>01</ISO>
+ <AuthCode>013511</AuthCode>
+ <TransTime>18:41:13</TransTime>
+ <TransDate>2008-01-05</TransDate>
+ <TransType>00</TransType>
+ <Complete>true</Complete>
+ <Message>DECLINED * =</Message>
+ <TransAmount>1.00</TransAmount>
+ <CardType>V</CardType>
+ <TransID>97-2-0</TransID>
+ <TimedOut>false</TimedOut>
+ </receipt>
+</response>
+
+ RESPONSE
+ end
- private
-
def xml_purchase_fixture
- %q{<request><store_id>store1</store_id><api_token>yesguy</api_token><purchase><amount>1.01</amount><pan>4242424242424242</pan><expdate>0303</expdate><crypt_type>7</crypt_type><order_id>order1</order_id></purchase></request>}
+ '<request><store_id>store1</store_id><api_token>yesguy</api_token><purchase><amount>1.01</amount><pan>4242424242424242</pan><expdate>0303</expdate><crypt_type>7</crypt_type><order_id>order1</order_id></purchase></request>'
end
def xml_capture_fixture
- %q{<request><store_id>store1</store_id><api_token>yesguy</api_token><preauth><amount>1.01</amount><pan>4242424242424242</pan><expdate>0303</expdate><crypt_type>7</crypt_type><order_id>order1</order_id></preauth></request>}
+ '<request><store_id>store1</store_id><api_token>yesguy</api_token><preauth><amount>1.01</amount><pan>4242424242424242</pan><expdate>0303</expdate><crypt_type>7</crypt_type><order_id>order1</order_id></preauth></request>'
end
end