require 'test_helper' class DataCashTest < Test::Unit::TestCase # 100 Cents AMOUNT = 100 def setup @gateway = DataCashGateway.new( :login => 'LOGIN', :password => 'PASSWORD' ) @credit_card = credit_card('4242424242424242') @address = { :name => 'Mark McBride', :address1 => 'Flat 12/3', :address2 => '45 Main Road', :city => 'London', :state => 'None', :country => 'GBR', :zip => 'A987AA', :phone => '(555)555-5555' } @options = { :order_id => generate_unique_id, :billing_address => @address } end def test_successful_purchase @gateway.expects(:ssl_post).returns(successful_purchase_response) response = @gateway.purchase(@amount, @credit_card, @options) assert_instance_of Response, response assert_success response assert response.test? assert_equal 'The transaction was successful', response.message assert_equal '4400200050664928;123456789;', response.authorization end def test_unsuccessful_purchase @gateway.expects(:ssl_post).returns(failed_purchase_response) response = @gateway.purchase(@amount, @credit_card, @options) assert_instance_of Response, response assert_failure response assert response.test? assert_equal 'Invalid reference number', response.message end def test_error_response @gateway.expects(:ssl_post).returns(failed_purchase_response) response = @gateway.purchase(@amount, @credit_card, @options) assert_instance_of Response, response assert_failure response assert response.test? assert_equal 'Invalid reference number', response.message end def test_supported_countries assert_equal ['GB'], DataCashGateway.supported_countries end def test_supported_card_types assert_equal [ :visa, :master, :american_express, :discover, :diners_club, :jcb, :maestro, :switch, :solo, :laser ], DataCashGateway.supported_cardtypes end def test_purchase_with_missing_order_id_option assert_raise(ArgumentError){ @gateway.purchase(100, @credit_card, {}) } end def test_authorize_with_missing_order_id_option assert_raise(ArgumentError){ @gateway.authorize(100, @credit_card, {}) } end def test_purchase_does_not_raise_exception_with_missing_billing_address @gateway.expects(:ssl_post).returns(successful_purchase_response) assert @gateway.authorize(100, @credit_card, {:order_id => generate_unique_id }).is_a?(AbtainBilling::Billing::Response) end def test_continuous_authority_purchase_with_missing_continuous_authority_reference assert_raise(ArgumentError) do @gateway.authorize(100, "a;b;", @options) end end def test_successful_continuous_authority_purchase @gateway.expects(:ssl_post).returns(successful_purchase_response) response = @gateway.purchase(@amount, '4400200050664928;123456789;10000000', @options) assert_instance_of Response, response assert_success response assert response.test? assert_equal 'The transaction was successful', response.message end private def failed_purchase_response <<-XML 22 TEST United Kingdom 2d24cc91284c1ed5c65d8821f1e752c7 Clydesdale Bank PLC Invalid reference number Solo 4400200050664928 XML end def successful_purchase_response <<-XML 1 TEST United Kingdom 2d24cc91284c1ed5c65d8821f1e752c7 Clydesdale Bank PLC The transaction was successful Visa 4400200050664928 123456789 XML end end