Sha256: cd0fc00448ec72a8145c9682a3435e8c84e40a68f78a230fb329658ac05351f6

Contents?: true

Size: 1.79 KB

Versions: 31

Compression:

Stored size: 1.79 KB

Contents

require File.dirname(__FILE__) + '/../test_helper'

class CreateCreditNoteTest < Test::Unit::TestCase
  include TestHelper
  
  def setup
    @gateway = XeroGateway::Gateway.new(CONSUMER_KEY, CONSUMER_SECRET)
    
    if STUB_XERO_CALLS
      @gateway.xero_url = "DUMMY_URL"
      
      @gateway.stubs(:http_put).with {|client, url, body, params| url =~ /CreditNotes$/ }.returns(get_file_as_string("create_credit_note.xml"))          
      @gateway.stubs(:http_post).with {|client, url, body, params| url =~ /CreditNotes$/ }.returns(get_file_as_string("credit_note.xml"))          
    end
  end
  
  def test_create_credit_note
    example_credit_note = dummy_credit_note.dup
    
    result = @gateway.create_credit_note(example_credit_note)
    assert_valid_credit_note_save_response(result, example_credit_note)
  end
  
  def test_create_from_credit_note
    example_credit_note = dummy_credit_note.dup
    
    credit_note = @gateway.build_credit_note(example_credit_note)
    result = credit_note.create
    assert_valid_credit_note_save_response(result, example_credit_note)
  end
  
  def test_create_credit_note_valid
    example_credit_note = dummy_credit_note.dup
    assert_equal true, example_credit_note.valid?, "credit_note is invalid - errors:\n\t#{example_credit_note.errors.map { | error | "#{error[0]} #{error[1]}"}.join("\n\t")}"
  end
  
  private
  
    def assert_valid_credit_note_save_response(result, example_credit_note)
      assert_kind_of XeroGateway::Response, result
      assert result.success?
      assert !result.request_xml.nil?
      assert !result.response_xml.nil?
      assert !result.credit_note.credit_note_id.nil?
      assert result.credit_note.credit_note_number == example_credit_note.credit_note_number
      assert result.credit_note.credit_note_id =~ GUID_REGEX
    end
    
end

Version data entries

31 entries across 31 versions & 3 rubygems

Version Path
xero_gateway-2.7.0 test/integration/create_credit_note_test.rb
xero_gateway-2.6.0 test/integration/create_credit_note_test.rb
xero_gateway-2.5.0 test/integration/create_credit_note_test.rb
xero_gateway-2.4.0 test/integration/create_credit_note_test.rb
xero_gateway-2.3.0 test/integration/create_credit_note_test.rb
xero_gateway-float-2.1.7 test/integration/create_credit_note_test.rb
xero_gateway-float-2.1.6 test/integration/create_credit_note_test.rb
xero_gateway-float-2.1.4 test/integration/create_credit_note_test.rb
xero_gateway-float-2.1.3 test/integration/create_credit_note_test.rb
xero_gateway-float-2.1.1 test/integration/create_credit_note_test.rb
xero_gateway-float-2.0.18 test/integration/create_credit_note_test.rb
xero_gateway-float-2.0.17 test/integration/create_credit_note_test.rb
xero_gateway-float-2.0.16 test/integration/create_credit_note_test.rb
xero_gateway-float-2.0.15 test/integration/create_credit_note_test.rb
xero_gateway-2.1.0 test/integration/create_credit_note_test.rb
xero_gateway-n8vision-2.0.20 test/integration/create_credit_note_test.rb
xero_gateway-2.0.19 test/integration/create_credit_note_test.rb
xero_gateway-2.0.18 test/integration/create_credit_note_test.rb
xero_gateway-2.0.17 test/integration/create_credit_note_test.rb
xero_gateway-2.0.16 test/integration/create_credit_note_test.rb