xero_gateway-n8vision 2.0.20
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +12 -0
- data/LICENSE +14 -0
- data/README.textile +357 -0
- data/Rakefile +14 -0
- data/examples/oauth.rb +25 -0
- data/examples/partner_app.rb +36 -0
- data/init.rb +1 -0
- data/lib/oauth/oauth_consumer.rb +14 -0
- data/lib/xero_gateway.rb +41 -0
- data/lib/xero_gateway/account.rb +86 -0
- data/lib/xero_gateway/accounts_list.rb +73 -0
- data/lib/xero_gateway/address.rb +96 -0
- data/lib/xero_gateway/bank_transaction.rb +175 -0
- data/lib/xero_gateway/ca-certificates.crt +2560 -0
- data/lib/xero_gateway/contact.rb +203 -0
- data/lib/xero_gateway/credit_note.rb +220 -0
- data/lib/xero_gateway/currency.rb +56 -0
- data/lib/xero_gateway/dates.rb +25 -0
- data/lib/xero_gateway/error.rb +18 -0
- data/lib/xero_gateway/exceptions.rb +51 -0
- data/lib/xero_gateway/gateway.rb +698 -0
- data/lib/xero_gateway/http.rb +135 -0
- data/lib/xero_gateway/http_encoding_helper.rb +49 -0
- data/lib/xero_gateway/invoice.rb +238 -0
- data/lib/xero_gateway/journal_line.rb +102 -0
- data/lib/xero_gateway/line_item.rb +125 -0
- data/lib/xero_gateway/line_item_calculations.rb +51 -0
- data/lib/xero_gateway/manual_journal.rb +163 -0
- data/lib/xero_gateway/money.rb +16 -0
- data/lib/xero_gateway/oauth.rb +92 -0
- data/lib/xero_gateway/organisation.rb +75 -0
- data/lib/xero_gateway/partner_app.rb +30 -0
- data/lib/xero_gateway/payment.rb +43 -0
- data/lib/xero_gateway/phone.rb +77 -0
- data/lib/xero_gateway/private_app.rb +17 -0
- data/lib/xero_gateway/response.rb +43 -0
- data/lib/xero_gateway/tax_rate.rb +63 -0
- data/lib/xero_gateway/tracking_category.rb +87 -0
- data/test/integration/accounts_list_test.rb +109 -0
- data/test/integration/create_bank_transaction_test.rb +38 -0
- data/test/integration/create_contact_test.rb +66 -0
- data/test/integration/create_credit_note_test.rb +49 -0
- data/test/integration/create_invoice_test.rb +49 -0
- data/test/integration/create_manual_journal_test.rb +35 -0
- data/test/integration/get_accounts_test.rb +23 -0
- data/test/integration/get_bank_transaction_test.rb +51 -0
- data/test/integration/get_bank_transactions_test.rb +88 -0
- data/test/integration/get_contact_test.rb +28 -0
- data/test/integration/get_contacts_test.rb +40 -0
- data/test/integration/get_credit_note_test.rb +48 -0
- data/test/integration/get_credit_notes_test.rb +90 -0
- data/test/integration/get_currencies_test.rb +25 -0
- data/test/integration/get_invoice_test.rb +48 -0
- data/test/integration/get_invoices_test.rb +92 -0
- data/test/integration/get_manual_journal_test.rb +50 -0
- data/test/integration/get_manual_journals_test.rb +88 -0
- data/test/integration/get_organisation_test.rb +24 -0
- data/test/integration/get_tax_rates_test.rb +25 -0
- data/test/integration/get_tracking_categories_test.rb +27 -0
- data/test/integration/update_bank_transaction_test.rb +31 -0
- data/test/integration/update_contact_test.rb +31 -0
- data/test/integration/update_invoice_test.rb +31 -0
- data/test/integration/update_manual_journal_test.rb +31 -0
- data/test/test_helper.rb +217 -0
- data/test/unit/account_test.rb +47 -0
- data/test/unit/bank_transaction_test.rb +126 -0
- data/test/unit/contact_test.rb +97 -0
- data/test/unit/credit_note_test.rb +284 -0
- data/test/unit/currency_test.rb +31 -0
- data/test/unit/gateway_test.rb +119 -0
- data/test/unit/invoice_test.rb +326 -0
- data/test/unit/manual_journal_test.rb +93 -0
- data/test/unit/oauth_test.rb +116 -0
- data/test/unit/organisation_test.rb +38 -0
- data/test/unit/tax_rate_test.rb +38 -0
- data/test/unit/tracking_category_test.rb +52 -0
- data/xero_gateway-n8vision.gemspec +15 -0
- metadata +178 -0
@@ -0,0 +1,38 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class CreateBankTransactionTest < Test::Unit::TestCase
|
4
|
+
include TestHelper
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@gateway = XeroGateway::Gateway.new(CONSUMER_KEY, CONSUMER_SECRET)
|
8
|
+
|
9
|
+
if STUB_XERO_CALLS
|
10
|
+
@gateway.xero_url = "DUMMY_URL"
|
11
|
+
|
12
|
+
@gateway.stubs(:http_put).with {|client, url, body, params| url =~ /BankTransactions$/ }.returns(get_file_as_string("create_bank_transaction.xml"))
|
13
|
+
@gateway.stubs(:http_post).with {|client, url, body, params| url =~ /BankTransactions$/ }.returns(get_file_as_string("bank_transaction.xml"))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_create_bank_transaction
|
18
|
+
example_bank_transaction = create_test_bank_transaction.dup
|
19
|
+
|
20
|
+
result = @gateway.create_bank_transaction(example_bank_transaction)
|
21
|
+
assert_kind_of XeroGateway::Response, result
|
22
|
+
assert result.success?
|
23
|
+
assert !result.request_xml.nil?
|
24
|
+
assert !result.response_xml.nil?
|
25
|
+
assert !result.bank_transaction.bank_transaction_id.nil?
|
26
|
+
assert example_bank_transaction.bank_transaction_id =~ GUID_REGEX
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_create_bank_transaction_valid
|
30
|
+
example_bank_transaction = create_test_bank_transaction.dup
|
31
|
+
assert_equal true, example_bank_transaction.valid?,
|
32
|
+
"bank_transaction is invalid - errors:\n\t#{example_bank_transaction.errors.map { | error | "#{error[0]} #{error[1]}"}.join("\n\t")}"
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class CreateContactTest < Test::Unit::TestCase
|
4
|
+
include TestHelper
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@gateway = XeroGateway::Gateway.new(CONSUMER_KEY, CONSUMER_SECRET)
|
8
|
+
|
9
|
+
if STUB_XERO_CALLS
|
10
|
+
@gateway.xero_url = "DUMMY_URL"
|
11
|
+
|
12
|
+
@gateway.stubs(:http_put).with {|client, url, body, params| url =~ /Contacts$/ }.returns(get_file_as_string("contact.xml"))
|
13
|
+
@gateway.stubs(:http_post).with {|client, url, body, params| url =~ /Contacts$/ }.returns(get_file_as_string("contact.xml"))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_create_contact
|
18
|
+
example_contact = dummy_contact.dup
|
19
|
+
|
20
|
+
result = @gateway.create_contact(example_contact)
|
21
|
+
assert_valid_contact_save_response(result, example_contact)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_create_from_contact
|
25
|
+
example_contact = dummy_contact.dup
|
26
|
+
|
27
|
+
contact = @gateway.build_contact(example_contact)
|
28
|
+
result = contact.create
|
29
|
+
assert_valid_contact_save_response(result, example_contact)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_update_from_contact
|
33
|
+
example_contact = dummy_contact.dup
|
34
|
+
|
35
|
+
contact = @gateway.build_contact(example_contact)
|
36
|
+
contact.create # need to create first so we have a ContactID
|
37
|
+
|
38
|
+
result = contact.update
|
39
|
+
assert_valid_contact_save_response(result, example_contact)
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_save_from_contact
|
43
|
+
example_contact = dummy_contact.dup
|
44
|
+
|
45
|
+
contact = @gateway.build_contact(example_contact)
|
46
|
+
result = contact.save
|
47
|
+
assert_valid_contact_save_response(result, example_contact)
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_create_contact_valid
|
51
|
+
example_contact = dummy_contact.dup
|
52
|
+
assert_equal true, example_contact.valid?, "contact is invalid - errors:\n\t#{example_contact.errors.map { | error | "#{error[0]} #{error[1]}"}.join("\n\t")}"
|
53
|
+
end
|
54
|
+
|
55
|
+
private
|
56
|
+
|
57
|
+
def assert_valid_contact_save_response(result, example_contact)
|
58
|
+
assert_kind_of XeroGateway::Response, result
|
59
|
+
assert result.success?
|
60
|
+
assert !result.contact.contact_id.nil?
|
61
|
+
assert !result.request_xml.nil?
|
62
|
+
assert !result.response_xml.nil?
|
63
|
+
assert_equal result.contact.name, example_contact.name
|
64
|
+
assert example_contact.contact_id =~ GUID_REGEX
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class CreateCreditNoteTest < Test::Unit::TestCase
|
4
|
+
include TestHelper
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@gateway = XeroGateway::Gateway.new(CONSUMER_KEY, CONSUMER_SECRET)
|
8
|
+
|
9
|
+
if STUB_XERO_CALLS
|
10
|
+
@gateway.xero_url = "DUMMY_URL"
|
11
|
+
|
12
|
+
@gateway.stubs(:http_put).with {|client, url, body, params| url =~ /CreditNotes$/ }.returns(get_file_as_string("create_credit_note.xml"))
|
13
|
+
@gateway.stubs(:http_post).with {|client, url, body, params| url =~ /CreditNotes$/ }.returns(get_file_as_string("credit_note.xml"))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_create_credit_note
|
18
|
+
example_credit_note = dummy_credit_note.dup
|
19
|
+
|
20
|
+
result = @gateway.create_credit_note(example_credit_note)
|
21
|
+
assert_valid_credit_note_save_response(result, example_credit_note)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_create_from_credit_note
|
25
|
+
example_credit_note = dummy_credit_note.dup
|
26
|
+
|
27
|
+
credit_note = @gateway.build_credit_note(example_credit_note)
|
28
|
+
result = credit_note.create
|
29
|
+
assert_valid_credit_note_save_response(result, example_credit_note)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_create_credit_note_valid
|
33
|
+
example_credit_note = dummy_credit_note.dup
|
34
|
+
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")}"
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def assert_valid_credit_note_save_response(result, example_credit_note)
|
40
|
+
assert_kind_of XeroGateway::Response, result
|
41
|
+
assert result.success?
|
42
|
+
assert !result.request_xml.nil?
|
43
|
+
assert !result.response_xml.nil?
|
44
|
+
assert !result.credit_note.credit_note_id.nil?
|
45
|
+
assert result.credit_note.credit_note_number == example_credit_note.credit_note_number
|
46
|
+
assert result.credit_note.credit_note_id =~ GUID_REGEX
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class CreateInvoiceTest < Test::Unit::TestCase
|
4
|
+
include TestHelper
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@gateway = XeroGateway::Gateway.new(CONSUMER_KEY, CONSUMER_SECRET)
|
8
|
+
|
9
|
+
if STUB_XERO_CALLS
|
10
|
+
@gateway.xero_url = "DUMMY_URL"
|
11
|
+
|
12
|
+
@gateway.stubs(:http_put).with {|client, url, body, params| url =~ /Invoices$/ }.returns(get_file_as_string("create_invoice.xml"))
|
13
|
+
@gateway.stubs(:http_post).with {|client, url, body, params| url =~ /Invoices$/ }.returns(get_file_as_string("invoice.xml"))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_create_invoice
|
18
|
+
example_invoice = dummy_invoice.dup
|
19
|
+
|
20
|
+
result = @gateway.create_invoice(example_invoice)
|
21
|
+
assert_valid_invoice_save_response(result, example_invoice)
|
22
|
+
end
|
23
|
+
|
24
|
+
def test_create_from_invoice
|
25
|
+
example_invoice = dummy_invoice.dup
|
26
|
+
|
27
|
+
invoice = @gateway.build_invoice(example_invoice)
|
28
|
+
result = invoice.create
|
29
|
+
assert_valid_invoice_save_response(result, example_invoice)
|
30
|
+
end
|
31
|
+
|
32
|
+
def test_create_invoice_valid
|
33
|
+
example_invoice = dummy_invoice.dup
|
34
|
+
assert_equal true, example_invoice.valid?, "invoice is invalid - errors:\n\t#{example_invoice.errors.map { | error | "#{error[0]} #{error[1]}"}.join("\n\t")}"
|
35
|
+
end
|
36
|
+
|
37
|
+
private
|
38
|
+
|
39
|
+
def assert_valid_invoice_save_response(result, example_invoice)
|
40
|
+
assert_kind_of XeroGateway::Response, result
|
41
|
+
assert result.success?
|
42
|
+
assert !result.request_xml.nil?
|
43
|
+
assert !result.response_xml.nil?
|
44
|
+
assert !result.invoice.invoice_id.nil?
|
45
|
+
assert result.invoice.invoice_number == example_invoice.invoice_number
|
46
|
+
assert example_invoice.invoice_id =~ GUID_REGEX
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class CreateManualJournalTest < Test::Unit::TestCase
|
4
|
+
include TestHelper
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@gateway = XeroGateway::Gateway.new(CONSUMER_KEY, CONSUMER_SECRET)
|
8
|
+
|
9
|
+
if STUB_XERO_CALLS
|
10
|
+
@gateway.xero_url = "DUMMY_URL"
|
11
|
+
|
12
|
+
@gateway.stubs(:http_put).with {|client, url, body, params| url =~ /ManualJournals$/ }.returns(get_file_as_string("create_manual_journal.xml"))
|
13
|
+
@gateway.stubs(:http_post).with {|client, url, body, params| url =~ /ManualJournals$/ }.returns(get_file_as_string("manual_journal.xml"))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_create_manual_journal
|
18
|
+
example_manual_journal = create_test_manual_journal.dup
|
19
|
+
|
20
|
+
result = @gateway.create_manual_journal(example_manual_journal)
|
21
|
+
assert_kind_of XeroGateway::Response, result
|
22
|
+
assert result.success?
|
23
|
+
assert !result.request_xml.nil?
|
24
|
+
assert !result.response_xml.nil?
|
25
|
+
assert !result.manual_journal.manual_journal_id.nil?
|
26
|
+
assert example_manual_journal.manual_journal_id =~ GUID_REGEX
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_create_manual_journal_valid
|
30
|
+
example_manual_journal = create_test_manual_journal.dup
|
31
|
+
assert_equal true, example_manual_journal.valid?,
|
32
|
+
"manual_journal is invalid - errors:\n\t#{example_manual_journal.errors.map { | error | "#{error[0]} #{error[1]}"}.join("\n\t")}"
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class GetAccountsTest < Test::Unit::TestCase
|
4
|
+
include TestHelper
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@gateway = XeroGateway::Gateway.new(CONSUMER_KEY, CONSUMER_SECRET)
|
8
|
+
|
9
|
+
if STUB_XERO_CALLS
|
10
|
+
@gateway.xero_url = "DUMMY_URL"
|
11
|
+
|
12
|
+
@gateway.stubs(:http_get).with {|client, url, params| url =~ /Accounts$/ }.returns(get_file_as_string("accounts.xml"))
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def test_get_accounts
|
17
|
+
result = @gateway.get_accounts
|
18
|
+
assert result.success?
|
19
|
+
assert !result.response_xml.nil?
|
20
|
+
assert result.accounts.size > 0
|
21
|
+
assert_equal XeroGateway::Account, result.accounts.first.class
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class GetBankTransactionTest < Test::Unit::TestCase
|
4
|
+
include TestHelper
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@gateway = XeroGateway::Gateway.new(CONSUMER_KEY, CONSUMER_SECRET)
|
8
|
+
|
9
|
+
if STUB_XERO_CALLS
|
10
|
+
@gateway.xero_url = "DUMMY_URL"
|
11
|
+
|
12
|
+
@gateway.stubs(:http_get).with {|client, url, params| url =~ /BankTransactions(\/[0-9a-z\-]+)?$/i }.returns(get_file_as_string("bank_transaction.xml"))
|
13
|
+
@gateway.stubs(:http_put).with {|client, url, body, params| url =~ /BankTransactions$/ }.returns(get_file_as_string("create_bank_transaction.xml"))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_get_bank_transaction
|
18
|
+
# Make sure there is a bank transaction in Xero to retrieve
|
19
|
+
response = @gateway.create_bank_transaction(create_test_bank_transaction)
|
20
|
+
bank_transaction = response.bank_transaction
|
21
|
+
|
22
|
+
result = @gateway.get_bank_transaction(bank_transaction.bank_transaction_id)
|
23
|
+
assert result.success?
|
24
|
+
assert !result.request_params.nil?
|
25
|
+
assert !result.response_xml.nil?
|
26
|
+
assert_equal result.bank_transaction.bank_transaction_id, bank_transaction.bank_transaction_id
|
27
|
+
assert_equal result.bank_transaction.reference, bank_transaction.reference
|
28
|
+
assert result.bank_transaction.is_reconciled
|
29
|
+
|
30
|
+
result = @gateway.get_bank_transaction(bank_transaction.bank_transaction_id)
|
31
|
+
assert result.success?
|
32
|
+
assert !result.request_params.nil?
|
33
|
+
assert !result.response_xml.nil?
|
34
|
+
assert_equal result.bank_transaction.bank_transaction_id, bank_transaction.bank_transaction_id
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_line_items_downloaded_set_correctly
|
38
|
+
# Make sure there is a bank transaction in Xero to retrieve.
|
39
|
+
example_bank_transaction = @gateway.create_bank_transaction(create_test_bank_transaction).bank_transaction
|
40
|
+
|
41
|
+
# No line items.
|
42
|
+
response = @gateway.get_bank_transaction(example_bank_transaction.bank_transaction_id)
|
43
|
+
assert_equal(true, response.success?)
|
44
|
+
|
45
|
+
bank_transaction = response.bank_transaction
|
46
|
+
assert_kind_of(XeroGateway::LineItem, bank_transaction.line_items.first)
|
47
|
+
assert_kind_of(XeroGateway::BankTransaction, bank_transaction)
|
48
|
+
assert_equal(true, bank_transaction.line_items_downloaded?)
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class GetBankTransactionsTest < Test::Unit::TestCase
|
4
|
+
include TestHelper
|
5
|
+
|
6
|
+
INVALID_BANK_TRANSACTION_ID = "99999999-9999-9999-9999-999999999999" unless defined?(INVALID_BANK_TRANSACTION_ID)
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@gateway = XeroGateway::Gateway.new(CONSUMER_KEY, CONSUMER_SECRET)
|
10
|
+
|
11
|
+
if STUB_XERO_CALLS
|
12
|
+
@gateway.xero_url = "DUMMY_URL"
|
13
|
+
|
14
|
+
@gateway.stubs(:http_get).with {|client, url, params| url =~ /BankTransactions(\/[0-9a-z\-]+)?$/i }.returns(get_file_as_string("bank_transactions.xml"))
|
15
|
+
@gateway.stubs(:http_put).with {|client, url, body, params| url =~ /BankTransactions$/ }.returns(get_file_as_string("create_bank_transaction.xml"))
|
16
|
+
|
17
|
+
# Get a bank transaction with an invalid ID.
|
18
|
+
@gateway.stubs(:http_get).with {|client, url, params| url =~ Regexp.new("BankTransactions/#{INVALID_BANK_TRANSACTION_ID}") }.returns(get_file_as_string("bank_transaction_not_found_error.xml"))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_get_bank_transactions
|
23
|
+
# Make sure there is a bank transaction in Xero to retrieve
|
24
|
+
bank_transaction = @gateway.create_bank_transaction(create_test_bank_transaction).bank_transaction
|
25
|
+
|
26
|
+
result = @gateway.get_bank_transactions
|
27
|
+
assert result.success?
|
28
|
+
assert !result.request_params.nil?
|
29
|
+
assert !result.response_xml.nil?
|
30
|
+
assert result.bank_transactions.collect {|i| i.reference}.include?(bank_transaction.reference)
|
31
|
+
assert result.bank_transactions.collect {|i| i.bank_transaction_id}.include?(bank_transaction.bank_transaction_id)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_get_bank_transactions_with_modified_since_date
|
35
|
+
# Create a test bank transaction
|
36
|
+
@gateway.create_bank_transaction(create_test_bank_transaction)
|
37
|
+
|
38
|
+
# Check that it is returned
|
39
|
+
result = @gateway.get_bank_transactions(:modified_since => Date.today - 1)
|
40
|
+
assert result.success?
|
41
|
+
assert !result.request_params.nil?
|
42
|
+
assert !result.response_xml.nil?
|
43
|
+
assert result.request_params.keys.include?(:ModifiedAfter) # make sure the flag was sent
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_line_items_downloaded_set_correctly
|
47
|
+
# No line items.
|
48
|
+
response = @gateway.get_bank_transactions
|
49
|
+
assert_equal(true, response.success?)
|
50
|
+
|
51
|
+
bank_transaction = response.bank_transactions.first
|
52
|
+
assert_kind_of(XeroGateway::BankTransaction, bank_transaction)
|
53
|
+
assert_equal(false, bank_transaction.line_items_downloaded?)
|
54
|
+
end
|
55
|
+
|
56
|
+
# Make sure that a reference to gateway is passed when the get_bank_transactions response is parsed.
|
57
|
+
def test_get_bank_transactions_gateway_reference
|
58
|
+
result = @gateway.get_bank_transactions
|
59
|
+
assert(result.success?)
|
60
|
+
assert_not_equal(0, result.bank_transactions.size)
|
61
|
+
|
62
|
+
result.bank_transactions.each do |bank_transaction|
|
63
|
+
assert(bank_transaction.gateway === @gateway)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
# Test to make sure that we correctly error when a bank transaction doesn't have an ID.
|
68
|
+
# This should usually never be ecountered.
|
69
|
+
def test_to_ensure_that_a_bank_transaction_with_invalid_id_errors
|
70
|
+
# Make sure there is a bank transaction to retrieve, even though we will mangle it later.
|
71
|
+
bank_transaction = @gateway.create_bank_transaction(create_test_bank_transaction).bank_transaction
|
72
|
+
|
73
|
+
result = @gateway.get_bank_transactions
|
74
|
+
assert_equal(true, result.success?)
|
75
|
+
|
76
|
+
bank_transaction = result.bank_transactions.first
|
77
|
+
assert_equal(false, bank_transaction.line_items_downloaded?)
|
78
|
+
|
79
|
+
# Mangle invoice_id to invalid one.
|
80
|
+
bank_transaction.bank_transaction_id = INVALID_BANK_TRANSACTION_ID
|
81
|
+
|
82
|
+
# Make sure we fail here.
|
83
|
+
line_items = nil
|
84
|
+
assert_raise(XeroGateway::BankTransactionNotFoundError) { line_items = bank_transaction.line_items }
|
85
|
+
assert_nil(line_items)
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class GetContactTest < Test::Unit::TestCase
|
4
|
+
include TestHelper
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@gateway = XeroGateway::Gateway.new(CONSUMER_KEY, CONSUMER_SECRET)
|
8
|
+
|
9
|
+
if STUB_XERO_CALLS
|
10
|
+
@gateway.xero_url = "DUMMY_URL"
|
11
|
+
|
12
|
+
@gateway.stubs(:http_get).with {|client, url, params| url =~ /Contacts\/[^\/]+$/ }.returns(get_file_as_string("contact.xml"))
|
13
|
+
@gateway.stubs(:http_put).with {|client, url, body, params| url =~ /Contacts$/ }.returns(get_file_as_string("contact.xml"))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_get_contact
|
18
|
+
# Make sure there is an contact in Xero to retrieve
|
19
|
+
contact = @gateway.create_contact(dummy_contact).contact
|
20
|
+
flunk "get_contact could not be tested because create_contact failed" if contact.nil?
|
21
|
+
|
22
|
+
result = @gateway.get_contact_by_id(contact.contact_id)
|
23
|
+
assert result.success?
|
24
|
+
assert !result.request_params.nil?
|
25
|
+
assert !result.response_xml.nil?
|
26
|
+
assert_equal result.contact.name, contact.name
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../test_helper'
|
2
|
+
|
3
|
+
class GetContactsTest < Test::Unit::TestCase
|
4
|
+
include TestHelper
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@gateway = XeroGateway::Gateway.new(CONSUMER_KEY, CONSUMER_SECRET)
|
8
|
+
|
9
|
+
if STUB_XERO_CALLS
|
10
|
+
@gateway.xero_url = "DUMMY_URL"
|
11
|
+
|
12
|
+
@gateway.stubs(:http_get).with {|client, url, params| url =~ /Contacts$/ }.returns(get_file_as_string("contacts.xml"))
|
13
|
+
@gateway.stubs(:http_put).with {|client, url, body, params| url =~ /Contacts$/ }.returns(get_file_as_string("contact.xml"))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_get_contacts
|
18
|
+
# Make sure there is an contact in Xero to retrieve
|
19
|
+
contact = @gateway.create_contact(dummy_contact).contact
|
20
|
+
flunk "get_contacts could not be tested because create_contact failed" if contact.nil?
|
21
|
+
|
22
|
+
result = @gateway.get_contacts
|
23
|
+
assert result.success?
|
24
|
+
assert !result.request_params.nil?
|
25
|
+
assert !result.response_xml.nil?
|
26
|
+
assert result.contacts.collect {|c| c.contact_id}.include?(contact.contact_id)
|
27
|
+
end
|
28
|
+
|
29
|
+
# Make sure that a reference to gateway is passed when the get_contacts response is parsed.
|
30
|
+
def test_get_contacts_gateway_reference
|
31
|
+
result = @gateway.get_contacts
|
32
|
+
assert(result.success?)
|
33
|
+
assert_not_equal(0, result.contacts.size)
|
34
|
+
|
35
|
+
result.contacts.each do | contact |
|
36
|
+
assert(contact.gateway === @gateway)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|