xeroizer 2.17.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/README.md +246 -213
- data/lib/xeroizer/connection.rb +49 -0
- data/lib/xeroizer/exceptions.rb +4 -0
- data/lib/xeroizer/generic_application.rb +13 -5
- data/lib/xeroizer/http.rb +7 -80
- data/lib/xeroizer/http_response.rb +154 -0
- data/lib/xeroizer/models/bank_account.rb +1 -0
- data/lib/xeroizer/models/bank_transaction.rb +1 -0
- data/lib/xeroizer/models/batch_payment.rb +27 -0
- data/lib/xeroizer/models/branding_theme.rb +49 -9
- data/lib/xeroizer/models/contact.rb +12 -6
- data/lib/xeroizer/models/contact_group.rb +45 -0
- data/lib/xeroizer/models/credit_note.rb +24 -22
- data/lib/xeroizer/models/currency.rb +14 -2
- data/lib/xeroizer/models/from_bank_account.rb +1 -0
- data/lib/xeroizer/models/history_record.rb +72 -0
- data/lib/xeroizer/models/invoice.rb +17 -3
- data/lib/xeroizer/models/item.rb +2 -1
- data/lib/xeroizer/models/item_purchase_details.rb +1 -1
- data/lib/xeroizer/models/line_item.rb +17 -5
- data/lib/xeroizer/models/manual_journal.rb +2 -1
- data/lib/xeroizer/models/online_invoice.rb +37 -0
- data/lib/xeroizer/models/option.rb +1 -1
- data/lib/xeroizer/models/organisation.rb +2 -0
- data/lib/xeroizer/models/payment_service.rb +22 -0
- data/lib/xeroizer/models/payroll/address.rb +53 -0
- data/lib/xeroizer/models/payroll/bank_account.rb +18 -6
- data/lib/xeroizer/models/payroll/benefit_line.rb +26 -0
- data/lib/xeroizer/models/payroll/benefit_type.rb +45 -0
- data/lib/xeroizer/models/payroll/deduction_line.rb +32 -0
- data/lib/xeroizer/models/payroll/deduction_type.rb +49 -0
- data/lib/xeroizer/models/payroll/earnings_line.rb +39 -0
- data/lib/xeroizer/models/payroll/earnings_type.rb +53 -0
- data/lib/xeroizer/models/payroll/employee.rb +30 -8
- data/lib/xeroizer/models/payroll/leave_application.rb +27 -0
- data/lib/xeroizer/models/payroll/leave_line.rb +30 -0
- data/lib/xeroizer/models/payroll/leave_period.rb +15 -0
- data/lib/xeroizer/models/payroll/pay_items.rb +22 -0
- data/lib/xeroizer/models/payroll/pay_run.rb +33 -0
- data/lib/xeroizer/models/payroll/pay_schedule.rb +40 -0
- data/lib/xeroizer/models/payroll/pay_template.rb +24 -0
- data/lib/xeroizer/models/payroll/payment_method.rb +24 -0
- data/lib/xeroizer/models/payroll/paystub.rb +44 -0
- data/lib/xeroizer/models/payroll/reimbursement_line.rb +21 -0
- data/lib/xeroizer/models/payroll/reimbursement_type.rb +22 -0
- data/lib/xeroizer/models/payroll/salary_and_wage.rb +29 -0
- data/lib/xeroizer/models/payroll/super_line.rb +40 -0
- data/lib/xeroizer/models/payroll/tax_declaration.rb +50 -0
- data/lib/xeroizer/models/payroll/time_off_line.rb +20 -0
- data/lib/xeroizer/models/payroll/time_off_type.rb +32 -0
- data/lib/xeroizer/models/payroll/work_location.rb +25 -0
- data/lib/xeroizer/models/prepayment.rb +1 -0
- data/lib/xeroizer/models/purchase_order.rb +6 -6
- data/lib/xeroizer/models/quote.rb +76 -0
- data/lib/xeroizer/models/schedule.rb +1 -0
- data/lib/xeroizer/models/tax_component.rb +1 -0
- data/lib/xeroizer/models/to_bank_account.rb +1 -0
- data/lib/xeroizer/oauth.rb +12 -1
- data/lib/xeroizer/oauth2.rb +82 -0
- data/lib/xeroizer/oauth2_application.rb +49 -0
- data/lib/xeroizer/payroll_application.rb +8 -3
- data/lib/xeroizer/record/base.rb +11 -2
- data/lib/xeroizer/record/base_model.rb +1 -1
- data/lib/xeroizer/record/base_model_http_proxy.rb +37 -17
- data/lib/xeroizer/record/model_definition_helper.rb +1 -1
- data/lib/xeroizer/record/payroll_base.rb +4 -0
- data/lib/xeroizer/record/record_association_helper.rb +4 -4
- data/lib/xeroizer/record/validators/associated_validator.rb +1 -0
- data/lib/xeroizer/record/xml_helper.rb +18 -18
- data/lib/xeroizer/report/aged_receivables_by_contact.rb +1 -1
- data/lib/xeroizer/report/cell_xml_helper.rb +13 -13
- data/lib/xeroizer/response.rb +22 -17
- data/lib/xeroizer/version.rb +1 -1
- data/lib/xeroizer.rb +34 -4
- data/test/acceptance/about_creating_bank_transactions_test.rb +89 -81
- data/test/acceptance/about_creating_prepayment_test.rb +25 -30
- data/test/acceptance/about_fetching_bank_transactions_test.rb +12 -12
- data/test/acceptance/about_online_invoice_test.rb +25 -0
- data/test/acceptance/acceptance_test.rb +28 -26
- data/test/acceptance/bank_transfer_test.rb +12 -17
- data/test/acceptance/bulk_operations_test.rb +18 -16
- data/test/acceptance/connections_test.rb +11 -0
- data/test/stub_responses/bad_request.json +6 -0
- data/test/stub_responses/connections.json +16 -0
- data/test/stub_responses/expired_oauth2_token.json +6 -0
- data/test/stub_responses/generic_response_error.json +6 -0
- data/test/stub_responses/invalid_oauth2_request_token.json +6 -0
- data/test/stub_responses/invalid_tenant_header.json +6 -0
- data/test/stub_responses/object_not_found.json +6 -0
- data/test/stub_responses/organisations.xml +10 -0
- data/test/stub_responses/payment_service.xml +15 -0
- data/test/test_helper.rb +17 -12
- data/test/unit/generic_application_test.rb +21 -10
- data/test/unit/http_test.rb +282 -10
- data/test/unit/models/address_test.rb +2 -2
- data/test/unit/models/bank_transaction_model_parsing_test.rb +2 -2
- data/test/unit/models/bank_transaction_test.rb +1 -1
- data/test/unit/models/bank_transaction_validation_test.rb +1 -1
- data/test/unit/models/contact_test.rb +20 -11
- data/test/unit/models/credit_note_test.rb +8 -8
- data/test/unit/models/employee_test.rb +4 -4
- data/test/unit/models/invoice_test.rb +12 -12
- data/test/unit/models/journal_line_test.rb +6 -6
- data/test/unit/models/journal_test.rb +4 -4
- data/test/unit/models/line_item_sum_test.rb +1 -1
- data/test/unit/models/line_item_test.rb +29 -37
- data/test/unit/models/manual_journal_test.rb +3 -3
- data/test/unit/models/organisation_test.rb +16 -2
- data/test/unit/models/payment_service_test.rb +29 -0
- data/test/unit/models/phone_test.rb +7 -7
- data/test/unit/models/prepayment_test.rb +4 -4
- data/test/unit/models/repeating_invoice_test.rb +3 -3
- data/test/unit/models/tax_rate_test.rb +2 -2
- data/test/unit/oauth2_test.rb +171 -0
- data/test/unit/oauth_config_test.rb +1 -1
- data/test/unit/record/base_model_test.rb +13 -13
- data/test/unit/record/base_test.rb +73 -4
- data/test/unit/record/block_validator_test.rb +1 -1
- data/test/unit/record/connection_test.rb +60 -0
- data/test/unit/record/model_definition_test.rb +36 -36
- data/test/unit/record/parse_params_test.rb +59 -0
- data/test/unit/record/parse_where_hash_test.rb +13 -13
- data/test/unit/record/record_association_test.rb +14 -14
- data/test/unit/record/validators_test.rb +43 -43
- data/test/unit/record_definition_test.rb +7 -7
- data/test/unit/report_definition_test.rb +7 -7
- data/test/unit/report_test.rb +20 -20
- data/test/unit_test_helper.rb +16 -0
- metadata +117 -27
- data/lib/xeroizer/models/payroll/home_address.rb +0 -24
- data/lib/xeroizer/partner_application.rb +0 -51
- data/lib/xeroizer/private_application.rb +0 -25
- data/lib/xeroizer/public_application.rb +0 -21
- data/test/unit/oauth_test.rb +0 -118
- data/test/unit/private_application_test.rb +0 -20
@@ -4,43 +4,38 @@ require "acceptance_test"
|
|
4
4
|
class AboutCreatingPrepayment < Test::Unit::TestCase
|
5
5
|
include AcceptanceTest
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
def any_line_items(account)
|
8
|
+
[{
|
9
|
+
:description => "Clingfilm bike shorts",
|
10
|
+
:quantity => 1,
|
11
|
+
:unit_amount => "200.00",
|
12
|
+
:account_code => account.code,
|
13
|
+
:tax_type => account.tax_type
|
14
|
+
}]
|
15
|
+
end
|
16
|
+
|
17
|
+
def assert_exists(prepayment, client)
|
18
|
+
assert_not_nil prepayment.id,
|
19
|
+
"Cannot check for exitence unless the prepayment (bank transaction) has non-null identifier"
|
20
|
+
assert_not_nil client.BankTransaction.find prepayment.id
|
9
21
|
end
|
10
22
|
|
11
|
-
|
12
|
-
|
13
|
-
all_accounts = client.Account.all
|
23
|
+
setup do
|
24
|
+
@client = AcceptanceTestHelpers.oauth2_client
|
25
|
+
all_accounts = @client.Account.all
|
14
26
|
@account = all_accounts.select{|acct| acct.status == "ACTIVE" && acct.type == "REVENUE"}.first
|
15
|
-
@bank_account = all_accounts.select{|acct| acct.status == "ACTIVE" && acct.type == "BANK"}.first
|
27
|
+
@bank_account = all_accounts.select{|acct| acct.status == "ACTIVE" && acct.type == "BANK"}.first
|
16
28
|
end
|
17
29
|
|
18
30
|
can "create a new PrePayment bank transaction" do
|
19
|
-
new_transaction = client.BankTransaction.build(
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
31
|
+
new_transaction = @client.BankTransaction.build(
|
32
|
+
:type => "RECEIVE-PREPAYMENT",
|
33
|
+
:contact => { :name => "Jazz Kang" },
|
34
|
+
:line_items => any_line_items(@account),
|
35
|
+
:bank_account => { :account_id => @bank_account.account_id }
|
24
36
|
)
|
25
37
|
|
26
38
|
assert new_transaction.save, "Save failed with the following errors: #{new_transaction.errors.inspect}"
|
27
|
-
assert_exists new_transaction
|
39
|
+
assert_exists new_transaction, @client
|
28
40
|
end
|
29
|
-
|
30
|
-
def any_line_items(account)
|
31
|
-
[{
|
32
|
-
:description => "Clingfilm bike shorts",
|
33
|
-
:quantity => 1,
|
34
|
-
:unit_amount => "200.00",
|
35
|
-
:account_code => account.code,
|
36
|
-
:tax_type => account.tax_type
|
37
|
-
}]
|
38
|
-
end
|
39
|
-
|
40
|
-
def assert_exists(prepayment)
|
41
|
-
assert_not_nil prepayment.id,
|
42
|
-
"Cannot check for exitence unless the prepayment (bank transaction) has non-null identifier"
|
43
|
-
assert_not_nil client.BankTransaction.find prepayment.id
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
41
|
+
end
|
@@ -5,40 +5,40 @@ require "bank_transaction_reference_data"
|
|
5
5
|
class AboutFetchingBankTransactions < Test::Unit::TestCase
|
6
6
|
include AcceptanceTest
|
7
7
|
|
8
|
-
|
9
|
-
@client
|
8
|
+
setup do
|
9
|
+
@client = AcceptanceTestHelpers.oauth2_client
|
10
10
|
end
|
11
11
|
|
12
12
|
context "when requesting a single bank transaction with a reference" do
|
13
13
|
setup do
|
14
|
-
@a_new_bank_transaction = BankTransactionReferenceData.new(client).bank_transaction
|
14
|
+
@a_new_bank_transaction = BankTransactionReferenceData.new(@client).bank_transaction
|
15
15
|
end
|
16
16
|
|
17
17
|
it "has the extended set of attributes" do
|
18
18
|
keys = [:line_amount_types, :contact, :date, :status, :line_items,
|
19
19
|
:updated_date_utc, :currency_code, :bank_transaction_id,
|
20
20
|
:bank_account, :type, :reference, :is_reconciled, :currency_rate]
|
21
|
-
assert_equal(@a_new_bank_transaction.attributes.keys
|
21
|
+
assert_equal(keys, @a_new_bank_transaction.attributes.keys)
|
22
22
|
end
|
23
23
|
|
24
24
|
it "returns full line item details" do
|
25
|
-
single_bank_transaction = client.BankTransaction.find @a_new_bank_transaction.id
|
25
|
+
single_bank_transaction = @client.BankTransaction.find @a_new_bank_transaction.id
|
26
26
|
|
27
27
|
assert_not_empty single_bank_transaction.line_items,
|
28
|
-
|
28
|
+
"expected the bank transaction's line items to have been included"
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
32
32
|
context "when requesting all bank transactions (i.e., without filter)" do
|
33
33
|
setup do
|
34
|
-
@the_first_bank_transaction = client.BankTransaction.all.
|
34
|
+
@the_first_bank_transaction = @client.BankTransaction.all.detect { |trans| trans.attributes.keys.include?(:reference) }
|
35
35
|
end
|
36
36
|
|
37
37
|
it "has the limited set of attributes" do
|
38
|
-
keys = [:line_amount_types, :contact, :date, :status, :updated_date_utc,
|
39
|
-
:currency_code, :bank_transaction_id, :bank_account, :type, :reference,
|
40
|
-
:is_reconciled]
|
41
|
-
assert_equal(@the_first_bank_transaction.attributes.keys
|
38
|
+
keys = [:line_amount_types, :contact, :date, :status, :updated_date_utc,
|
39
|
+
:currency_code, :bank_transaction_id, :bank_account, :type, :reference,
|
40
|
+
:is_reconciled, :has_attachments]
|
41
|
+
assert_equal(keys, @the_first_bank_transaction.attributes.keys)
|
42
42
|
end
|
43
43
|
|
44
44
|
it "returns contact" do
|
@@ -49,5 +49,5 @@ class AboutFetchingBankTransactions < Test::Unit::TestCase
|
|
49
49
|
assert_not_nil @the_first_bank_transaction.bank_account
|
50
50
|
end
|
51
51
|
end
|
52
|
-
end
|
53
52
|
|
53
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "acceptance_test"
|
3
|
+
|
4
|
+
class AboutGetOnlineInvoiceUrl < Test::Unit::TestCase
|
5
|
+
include AcceptanceTest
|
6
|
+
|
7
|
+
setup do
|
8
|
+
@client = AcceptanceTestHelpers.oauth2_client
|
9
|
+
@invoice = @client.Invoice.all(:where => 'Type=="ACCREC"').first
|
10
|
+
@invoice_acc_pay = @client.Invoice.all(:where => 'Type=="ACCPAY"').first
|
11
|
+
end
|
12
|
+
|
13
|
+
can "Request OnlineInvoice of an AccRec invoice" do
|
14
|
+
@online_invoice = @invoice.online_invoice
|
15
|
+
|
16
|
+
assert @online_invoice.online_invoice_url, "online_invoice_url not found"
|
17
|
+
assert @online_invoice.online_invoice_url.start_with?('https://in.xero.com/'), "online_invoice_url returned in unexpected format"
|
18
|
+
end
|
19
|
+
|
20
|
+
can "Not request OnlineInvoice of an AccPay invoice" do
|
21
|
+
assert_raise do
|
22
|
+
@online_invoice_acc_pay = @invoice_acc_pay.online_invoice
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -1,7 +1,35 @@
|
|
1
|
+
module AcceptanceTestHelpers
|
2
|
+
def self.oauth2_client
|
3
|
+
config = self.load_oauth2_config_from_env
|
4
|
+
Xeroizer::OAuth2Application.new(
|
5
|
+
config.client_id,
|
6
|
+
config.client_secret,
|
7
|
+
access_token: config.access_token,
|
8
|
+
tenant_id: config.tenant_id
|
9
|
+
)
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.load_oauth2_config_from_env
|
13
|
+
raise "No XERO_CLIENT_ID environment variable specified." unless ENV["XERO_CLIENT_ID"]
|
14
|
+
raise "No XERO_CLIENT_SECRET environment variable specified." unless ENV["XERO_CLIENT_SECRET"]
|
15
|
+
raise "No XERO_ACCESS_TOKEN environment variable specified." unless ENV["XERO_ACCESS_TOKEN"]
|
16
|
+
raise "No XERO_TENANT_ID environment variable specified." unless ENV["XERO_TENANT_ID"]
|
17
|
+
|
18
|
+
OpenStruct.new(client_id: ENV["XERO_CLIENT_ID"],
|
19
|
+
client_secret: ENV["XERO_CLIENT_SECRET"],
|
20
|
+
access_token: ENV["XERO_ACCESS_TOKEN"],
|
21
|
+
tenant_id: ENV["XERO_TENANT_ID"])
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
1
25
|
module AcceptanceTest
|
2
26
|
class << self
|
3
27
|
def included(klass)
|
4
28
|
klass.class_eval do
|
29
|
+
def self.it_works_using_oauth2(&block)
|
30
|
+
instance_exec(AcceptanceTestHelpers.oauth2_client, 'oauth2', &block)
|
31
|
+
end
|
32
|
+
|
5
33
|
def self.log_to_console
|
6
34
|
Xeroizer::Logging.const_set :Log, Xeroizer::Logging::StdOutLog
|
7
35
|
end
|
@@ -24,30 +52,4 @@ module AcceptanceTest
|
|
24
52
|
end
|
25
53
|
end
|
26
54
|
end
|
27
|
-
|
28
|
-
def setup
|
29
|
-
config = load_config_from_file || load_config_from_env
|
30
|
-
|
31
|
-
@key_file = config.key_file
|
32
|
-
@consumer_key = config.consumer_key
|
33
|
-
@consumer_secret = config.consumer_secret
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
37
|
-
|
38
|
-
def load_config_from_file
|
39
|
-
the_file_name = File.join(File.dirname(__FILE__), '..', '..', '.oauth')
|
40
|
-
|
41
|
-
return nil unless File.exist? the_file_name
|
42
|
-
|
43
|
-
Xeroizer::OAuthConfig.load IO.read the_file_name
|
44
|
-
end
|
45
|
-
|
46
|
-
def load_config_from_env
|
47
|
-
assert_not_nil ENV["CONSUMER_KEY"], "No CONSUMER_KEY environment variable specified."
|
48
|
-
assert_not_nil ENV["CONSUMER_SECRET"], "No CONSUMER_SECRET environment variable specified."
|
49
|
-
assert_not_nil ENV["PRIVATE_KEY_PATH"], "No PRIVATE_KEY_PATH environment variable specified."
|
50
|
-
assert File.exist?(ENV["PRIVATE_KEY_PATH"]), "The file <#{ENV["PRIVATE_KEY_PATH"]}> does not exist."
|
51
|
-
Xeroizer::OAuthCredentials.new ENV["CONSUMER_KEY"], ENV["CONSUMER_SECRET"], ENV["PRIVATE_KEY_PATH"]
|
52
|
-
end
|
53
55
|
end
|
@@ -4,23 +4,18 @@ require "acceptance_test"
|
|
4
4
|
class BankTransfer < Test::Unit::TestCase
|
5
5
|
include AcceptanceTest
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
super
|
13
|
-
all_accounts = client.Account.all
|
14
|
-
@from_bank_account = all_accounts.select { |acct| acct.status == "ACTIVE" && acct.type == "BANK" }.first
|
15
|
-
@to_bank_account = all_accounts.select { |acct| acct.status == "ACTIVE" && acct.type == "BANK" }.last
|
16
|
-
end
|
7
|
+
it_works_using_oauth2 do |client, client_type|
|
8
|
+
can "create a bank for #{client_type}" do
|
9
|
+
all_accounts = client.Account.all
|
10
|
+
@from_bank_account = all_accounts.select { |acct| acct.status == "ACTIVE" && acct.type == "BANK" }.first
|
11
|
+
@to_bank_account = all_accounts.select { |acct| acct.status == "ACTIVE" && acct.type == "BANK" }.last
|
17
12
|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
13
|
+
new_transfer = client.BankTransfer.build(
|
14
|
+
:amount => 300,
|
15
|
+
:from_bank_account => { :account_id => @from_bank_account.account_id },
|
16
|
+
:to_bank_account => { :account_id => @to_bank_account.account_id }
|
17
|
+
)
|
18
|
+
assert new_transfer.save, "Save failed with the following errors: #{new_transfer.errors.inspect}"
|
19
|
+
end
|
25
20
|
end
|
26
21
|
end
|
@@ -1,5 +1,8 @@
|
|
1
1
|
require "test_helper"
|
2
2
|
require "acceptance_test"
|
3
|
+
require "shoulda/matchers"
|
4
|
+
|
5
|
+
include Shoulda::Matchers
|
3
6
|
|
4
7
|
class BulkOperationsTest < Test::Unit::TestCase
|
5
8
|
include AcceptanceTest
|
@@ -8,18 +11,17 @@ class BulkOperationsTest < Test::Unit::TestCase
|
|
8
11
|
"test-person-#{rand 1000000000}"
|
9
12
|
end
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
@client = Xeroizer::PrivateApplication.new(@consumer_key, @consumer_secret, @key_file)
|
14
|
+
setup do
|
15
|
+
@client = AcceptanceTestHelpers.oauth2_client
|
14
16
|
end
|
15
17
|
|
16
|
-
|
18
|
+
should "create multiple invoices at once" do
|
17
19
|
c1, c2 = nil, nil
|
18
20
|
assert_true(
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
@client.Contact.batch_save do
|
22
|
+
c1 = @client.Contact.build(name: random_name)
|
23
|
+
c2 = @client.Contact.build(name: random_name)
|
24
|
+
end
|
23
25
|
)
|
24
26
|
[c1, c2].each {|c| assert_false c.new_record? }
|
25
27
|
end
|
@@ -27,11 +29,11 @@ class BulkOperationsTest < Test::Unit::TestCase
|
|
27
29
|
can "create and update new records in bulk" do
|
28
30
|
c1, c2 = nil, nil
|
29
31
|
assert_true(
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
32
|
+
@client.Contact.batch_save do
|
33
|
+
c1 = @client.Contact.create(name: random_name)
|
34
|
+
c1.email_address = "foo@bar.com"
|
35
|
+
c2 = @client.Contact.build(name: random_name)
|
36
|
+
end
|
35
37
|
)
|
36
38
|
[c1, c2].each {|c| assert_false c.new_record? }
|
37
39
|
c1.download_complete_record!
|
@@ -40,9 +42,9 @@ class BulkOperationsTest < Test::Unit::TestCase
|
|
40
42
|
|
41
43
|
can "return false from #batch_save if validation fails" do
|
42
44
|
assert_false(
|
43
|
-
|
44
|
-
|
45
|
-
|
45
|
+
@client.Contact.batch_save do
|
46
|
+
@client.Contact.build(email_address: "guy-with-no-name@example.com")
|
47
|
+
end
|
46
48
|
)
|
47
49
|
end
|
48
50
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
require "acceptance_test"
|
3
|
+
|
4
|
+
class ConnectionsTest < Test::Unit::TestCase
|
5
|
+
include AcceptanceTest
|
6
|
+
|
7
|
+
should "be able to hit Xero to get current connections via OAuth2" do
|
8
|
+
connections = AcceptanceTestHelpers.oauth2_client.current_connections
|
9
|
+
assert_not_nil connections.first.tenant_id
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"id": "9332e669-0a35-4084-8f05-cd1ff31918c2",
|
4
|
+
"tenantId": "7f5fabdd-9565-416a-9b62-d53d852bb2a3",
|
5
|
+
"tenantType": "ORGANISATION",
|
6
|
+
"createdDateUtc": "2019-12-13T18:10:43.3063640",
|
7
|
+
"updatedDateUtc": "2019-12-13T18:10:43.3084790"
|
8
|
+
},
|
9
|
+
{
|
10
|
+
"id": "8774aba8-708f-48d1-865e-zedf93a0d5d5",
|
11
|
+
"tenantId": "b4aca7b2-6fab-4ee7-a969-477f9128f636",
|
12
|
+
"tenantType": "ORGANISATION",
|
13
|
+
"createdDateUtc": "2019-12-13T18:06:31.5600280",
|
14
|
+
"updatedDateUtc": "2019-12-13T18:16:38.2095570"
|
15
|
+
}
|
16
|
+
]
|
@@ -20,6 +20,16 @@
|
|
20
20
|
<FinancialYearEndMonth>6</FinancialYearEndMonth>
|
21
21
|
<PeriodLockDate>2008-06-30T00:00:00</PeriodLockDate>
|
22
22
|
<CreatedDateUTC>2011-05-19T05:26:03.95</CreatedDateUTC>
|
23
|
+
<PaymentTerms>
|
24
|
+
<Bills>
|
25
|
+
<Day>4</Day>
|
26
|
+
<Type>OFFOLLOWINGMONTH</Type>
|
27
|
+
</Bills>
|
28
|
+
<Sales>
|
29
|
+
<Day>2</Day>
|
30
|
+
<Type>OFFOLLOWINGMONTH</Type>
|
31
|
+
</Sales>
|
32
|
+
</PaymentTerms>
|
23
33
|
</Organisation>
|
24
34
|
</Organisations>
|
25
35
|
</Response>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<Response xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
2
|
+
<Id>42d8b00c-2fdd-4a8a-9b84-82cfe78ff34a</Id>
|
3
|
+
<Status>OK</Status>
|
4
|
+
<ProviderName>Test Provider Name</ProviderName>
|
5
|
+
<DateTimeUTC>2018-06-18T04:13:44.7828584Z</DateTimeUTC>
|
6
|
+
<PaymentServices>
|
7
|
+
<PaymentService>
|
8
|
+
<PaymentServiceID>4d7f4335-6f16-437a-86e3-a856ebc576b8</PaymentServiceID>
|
9
|
+
<PaymentServiceName>Custom Service</PaymentServiceName>
|
10
|
+
<PaymentServiceType>Custom</PaymentServiceType>
|
11
|
+
<PaymentServiceUrl>http://example.com</PaymentServiceUrl>
|
12
|
+
<PayNowText>Pay Me</PayNowText>
|
13
|
+
</PaymentService>
|
14
|
+
</PaymentServices>
|
15
|
+
</Response>
|
data/test/test_helper.rb
CHANGED
@@ -4,10 +4,11 @@ require 'test/unit'
|
|
4
4
|
require 'mocha'
|
5
5
|
require 'shoulda'
|
6
6
|
require 'pp'
|
7
|
+
require 'pry'
|
7
8
|
|
8
9
|
require File.dirname(__FILE__) + '/../lib/xeroizer.rb'
|
9
10
|
|
10
|
-
$: << File.join(File.dirname(__FILE__), "acceptance")
|
11
|
+
$: << File.join(File.dirname(__FILE__), "acceptance")
|
11
12
|
|
12
13
|
module TestHelper
|
13
14
|
|
@@ -15,26 +16,31 @@ module TestHelper
|
|
15
16
|
# environment, and you must have set up a customer key for that account.
|
16
17
|
#
|
17
18
|
# You can then run the tests against the test environment using the commands (linux or mac):
|
18
|
-
# export STUB_XERO_CALLS=false
|
19
|
+
# export STUB_XERO_CALLS=false
|
19
20
|
# rake test
|
20
21
|
# (this probably won't work under OAuth?)
|
21
22
|
#
|
22
23
|
|
23
24
|
$VERBOSE=nil
|
24
|
-
|
25
|
+
|
25
26
|
STUB_XERO_CALLS = ENV["STUB_XERO_CALLS"].nil? ? true : (ENV["STUB_XERO_CALLS"] == "true") unless defined? STUB_XERO_CALLS
|
26
|
-
|
27
|
+
|
27
28
|
CONSUMER_KEY = ENV["CONSUMER_KEY"] || "fake_key" unless defined?(CONSUMER_KEY)
|
28
29
|
CONSUMER_SECRET = ENV["CONSUMER_SECRET"] || "fake_secret" unless defined?(CONSUMER_SECRET)
|
29
|
-
|
30
|
-
|
30
|
+
PRIVATE_KEY_PATH = ENV["PRIVATE_KEY_PATH"] || "fake_key" unless defined?(PRIVATE_KEY_PATH)
|
31
|
+
|
32
|
+
CLIENT_ID = ENV["XERO_CLIENT_ID"] || "fake_client_id" unless defined?(CLIENT_ID)
|
33
|
+
CLIENT_SECRET = ENV["XERO_CLIENT_SECRET"] || "fake_client_secret" unless defined?(CLIENT_SECRET)
|
34
|
+
ACCESS_TOKEN = ENV["XERO_ACCESS_TOKEN"] || "fake_access_token" unless defined?(ACCESS_TOKEN)
|
35
|
+
TENANT_ID = ENV["XERO_TENANT_ID"] || "fake_tenant_id" unless defined?(TENANT_ID)
|
36
|
+
|
31
37
|
# Helper constant for checking regex
|
32
38
|
GUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/ unless defined?(GUID_REGEX)
|
33
39
|
|
34
40
|
def get_file_as_string(filename)
|
35
41
|
File.read(File.dirname(__FILE__) + "/stub_responses/" + filename)
|
36
42
|
end
|
37
|
-
|
43
|
+
|
38
44
|
def get_record_xml(type, id = nil)
|
39
45
|
if id.nil?
|
40
46
|
get_file_as_string("#{type}.xml")
|
@@ -42,28 +48,27 @@ module TestHelper
|
|
42
48
|
get_file_as_string("records/#{type}-#{id}.xml")
|
43
49
|
end
|
44
50
|
end
|
45
|
-
|
51
|
+
|
46
52
|
def get_report_xml(report_type)
|
47
53
|
get_file_as_string("reports/#{report_type.underscore}.xml")
|
48
54
|
end
|
49
|
-
|
55
|
+
|
50
56
|
def mock_api(model_name)
|
51
57
|
@client.stubs(:http_get).with {|client, url, params| url =~ /#{model_name}$/ }.returns(get_record_xml(model_name.underscore.pluralize.to_s.to_sym))
|
52
58
|
@client.send(model_name.singularize.to_s.to_sym).all.each do | record |
|
53
59
|
@client.stubs(:http_get).with {|client, url, params| url =~ /#{model_name}\/#{record.id}$/ }.returns(get_record_xml(model_name.underscore.singularize.to_s.to_sym, record.id))
|
54
60
|
end
|
55
61
|
end
|
56
|
-
|
62
|
+
|
57
63
|
def mock_report_api(report_type)
|
58
64
|
@client.stubs(:http_get).with { | client, url, params | url =~ /Reports\/#{report_type}$/ }.returns(get_report_xml(report_type))
|
59
65
|
end
|
60
|
-
|
61
66
|
end
|
62
67
|
|
63
68
|
Shoulda::Context::ClassMethods.class_eval do
|
64
69
|
%w{it must can}.each do |m|
|
65
70
|
alias_method m, :should
|
66
71
|
end
|
67
|
-
|
72
|
+
|
68
73
|
alias_method :must_eventually, :should_eventually
|
69
74
|
end
|
@@ -1,26 +1,37 @@
|
|
1
|
-
require '
|
1
|
+
require 'unit_test_helper'
|
2
2
|
|
3
3
|
class GenericApplicationTest < Test::Unit::TestCase
|
4
4
|
include TestHelper
|
5
5
|
|
6
|
-
|
6
|
+
setup do
|
7
7
|
@headers = {"User-Agent" => "Xeroizer/2.15.5"}
|
8
8
|
@unitdp = 4
|
9
|
-
@
|
9
|
+
@options = {
|
10
|
+
default_headers: @headers,
|
11
|
+
unitdp: @unitdp
|
12
|
+
}
|
10
13
|
end
|
11
14
|
|
12
|
-
|
15
|
+
it "fails when provided an invalid client" do
|
16
|
+
client = "an invalid client"
|
17
|
+
|
18
|
+
assert_raises Xeroizer::InvalidClientError do
|
19
|
+
Xeroizer::GenericApplication.new(client, {})
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "oauth 2" do
|
24
|
+
setup do
|
25
|
+
client = Xeroizer::OAuth2.new(CLIENT_ID, CLIENT_SECRET, @options)
|
26
|
+
@application = Xeroizer::GenericApplication.new(client, @options)
|
27
|
+
end
|
13
28
|
|
14
29
|
should "pass default headers" do
|
15
|
-
assert_equal(@headers, @
|
30
|
+
assert_equal(@headers, @application.default_headers)
|
16
31
|
end
|
17
32
|
|
18
33
|
should "pass unitdp value" do
|
19
|
-
assert_equal(@unitdp, @
|
34
|
+
assert_equal(@unitdp, @application.unitdp)
|
20
35
|
end
|
21
|
-
|
22
36
|
end
|
23
|
-
|
24
37
|
end
|
25
|
-
|
26
|
-
|