xeroizer 2.20.0 → 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 +126 -185
- data/lib/xeroizer/connection.rb +49 -0
- data/lib/xeroizer/exceptions.rb +2 -0
- data/lib/xeroizer/generic_application.rb +8 -3
- data/lib/xeroizer/http.rb +5 -80
- data/lib/xeroizer/http_response.rb +154 -0
- data/lib/xeroizer/models/bank_transaction.rb +1 -0
- data/lib/xeroizer/models/batch_payment.rb +4 -1
- data/lib/xeroizer/models/contact.rb +10 -4
- data/lib/xeroizer/models/credit_note.rb +20 -20
- data/lib/xeroizer/models/history_record.rb +72 -0
- data/lib/xeroizer/models/invoice.rb +5 -1
- data/lib/xeroizer/models/line_item.rb +4 -2
- data/lib/xeroizer/models/manual_journal.rb +2 -1
- data/lib/xeroizer/models/option.rb +1 -1
- 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/quote.rb +76 -0
- data/lib/xeroizer/models/tax_component.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_model.rb +1 -1
- data/lib/xeroizer/record/base_model_http_proxy.rb +1 -0
- 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 +16 -16
- data/lib/xeroizer/response.rb +22 -17
- data/lib/xeroizer/version.rb +1 -1
- data/lib/xeroizer.rb +31 -4
- data/test/acceptance/about_creating_bank_transactions_test.rb +80 -82
- data/test/acceptance/about_creating_prepayment_test.rb +25 -30
- data/test/acceptance/about_fetching_bank_transactions_test.rb +10 -10
- data/test/acceptance/about_online_invoice_test.rb +6 -10
- 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/test_helper.rb +16 -11
- data/test/unit/generic_application_test.rb +21 -10
- data/test/unit/http_test.rb +281 -9
- 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 +2 -2
- 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 +19 -2
- data/test/unit/models/manual_journal_test.rb +3 -3
- data/test/unit/models/organisation_test.rb +2 -2
- data/test/unit/models/payment_service_test.rb +2 -2
- 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 +2 -2
- 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 +5 -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 +2 -2
- 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 +106 -23
- 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/http_tsl_12_upgrade_test.rb +0 -31
- data/test/unit/oauth_test.rb +0 -118
- data/test/unit/private_application_test.rb +0 -20
data/lib/xeroizer/response.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# Copyright (c) 2008 Tim Connor <tlconnor@gmail.com>
|
2
|
-
#
|
2
|
+
#
|
3
3
|
# Permission to use, copy, modify, and/or distribute this software for any
|
4
4
|
# purpose with or without fee is hereby granted, provided that the above
|
5
5
|
# copyright notice and this permission notice appear in all copies.
|
6
|
-
#
|
6
|
+
#
|
7
7
|
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
8
8
|
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
9
9
|
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
@@ -14,23 +14,23 @@
|
|
14
14
|
|
15
15
|
module Xeroizer
|
16
16
|
class Response
|
17
|
-
|
17
|
+
|
18
18
|
attr_accessor :id, :status, :errors, :provider, :date_time, :response_items, :request_params, :request_xml, :response_xml
|
19
|
-
|
19
|
+
|
20
20
|
class << self
|
21
|
-
|
21
|
+
|
22
22
|
# Parse the response retreived during any request.
|
23
23
|
def parse(raw_response, request = {}, options = {}, &block)
|
24
24
|
response = Xeroizer::Response.new
|
25
25
|
response.response_xml = raw_response
|
26
|
-
|
26
|
+
|
27
27
|
doc = Nokogiri::XML(raw_response) { | cfg | cfg.noblanks }
|
28
|
-
|
28
|
+
|
29
29
|
# check for responses we don't understand
|
30
30
|
raise Xeroizer::UnparseableResponse.new(doc.root.name) unless doc.root.name == 'Response'
|
31
|
-
|
31
|
+
|
32
32
|
doc.root.elements.each do | element |
|
33
|
-
|
33
|
+
|
34
34
|
# Text element
|
35
35
|
if element.children && element.children.size == 1 && element.children.first.text?
|
36
36
|
case element.name
|
@@ -39,31 +39,36 @@ module Xeroizer
|
|
39
39
|
when 'ProviderName' then response.provider = element.text
|
40
40
|
when 'DateTimeUTC' then response.date_time = Time.parse(element.text)
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
|
+
# Special case for Paystubs and PayItems because they are not wrapped in plural element or
|
44
|
+
# don't have singular children
|
45
|
+
elsif element.children && element.children.size > 0 && (element.name == 'Paystub' || element.name == 'PayItems')
|
46
|
+
yield(response, [element], element.name)
|
47
|
+
|
43
48
|
# Records in response
|
44
49
|
elsif element.children && element.children.size > 0
|
45
50
|
yield(response, element.children, element.children.first.name)
|
46
51
|
end
|
47
52
|
end
|
48
|
-
|
53
|
+
|
49
54
|
response
|
50
55
|
end
|
51
|
-
|
56
|
+
|
52
57
|
end
|
53
|
-
|
58
|
+
|
54
59
|
public
|
55
|
-
|
60
|
+
|
56
61
|
def initialize
|
57
62
|
@response_items = []
|
58
63
|
end
|
59
|
-
|
64
|
+
|
60
65
|
def success?
|
61
66
|
status == 'OK'
|
62
67
|
end
|
63
|
-
|
68
|
+
|
64
69
|
def error
|
65
70
|
errors.blank? ? nil : errors[0]
|
66
71
|
end
|
67
|
-
|
72
|
+
|
68
73
|
end
|
69
74
|
end
|
data/lib/xeroizer/version.rb
CHANGED
data/lib/xeroizer.rb
CHANGED
@@ -5,6 +5,7 @@ require 'active_support/inflector'
|
|
5
5
|
require "active_support/core_ext/array"
|
6
6
|
require "active_support/core_ext/big_decimal/conversions"
|
7
7
|
require 'oauth'
|
8
|
+
require 'oauth2'
|
8
9
|
require 'oauth/signature/rsa/sha1'
|
9
10
|
require 'nokogiri'
|
10
11
|
require 'builder'
|
@@ -17,14 +18,17 @@ $: << File.expand_path(File.dirname(__FILE__))
|
|
17
18
|
require 'class_level_inheritable_attributes'
|
18
19
|
require 'xeroizer/exceptions'
|
19
20
|
require 'xeroizer/oauth'
|
21
|
+
require 'xeroizer/oauth2'
|
20
22
|
require 'xeroizer/http_encoding_helper'
|
21
23
|
require 'xeroizer/http'
|
24
|
+
require 'xeroizer/connection'
|
22
25
|
|
23
26
|
require 'xeroizer/record/base_model'
|
24
27
|
require 'xeroizer/record/payroll_base_model'
|
25
28
|
require 'xeroizer/record/base'
|
26
29
|
require 'xeroizer/record/payroll_base'
|
27
30
|
require 'xeroizer/configuration'
|
31
|
+
require 'xeroizer/http_response'
|
28
32
|
|
29
33
|
# Include models
|
30
34
|
require 'xeroizer/models/account'
|
@@ -43,6 +47,7 @@ require 'xeroizer/models/credit_note'
|
|
43
47
|
require 'xeroizer/models/currency'
|
44
48
|
require 'xeroizer/models/employee'
|
45
49
|
require 'xeroizer/models/expense_claim'
|
50
|
+
require 'xeroizer/models/history_record'
|
46
51
|
require 'xeroizer/models/invoice'
|
47
52
|
require 'xeroizer/models/invoice_reminder'
|
48
53
|
require 'xeroizer/models/online_invoice'
|
@@ -62,6 +67,7 @@ require 'xeroizer/models/prepayment'
|
|
62
67
|
require 'xeroizer/models/overpayment'
|
63
68
|
require 'xeroizer/models/phone'
|
64
69
|
require 'xeroizer/models/purchase_order'
|
70
|
+
require 'xeroizer/models/quote'
|
65
71
|
require 'xeroizer/models/receipt'
|
66
72
|
require 'xeroizer/models/repeating_invoice'
|
67
73
|
require 'xeroizer/models/schedule'
|
@@ -74,16 +80,37 @@ require 'xeroizer/models/journal_line_tracking_category'
|
|
74
80
|
require 'xeroizer/models/contact_sales_tracking_category'
|
75
81
|
require 'xeroizer/models/contact_purchases_tracking_category'
|
76
82
|
|
77
|
-
require 'xeroizer/models/payroll/home_address'
|
78
83
|
require 'xeroizer/models/payroll/bank_account'
|
84
|
+
require 'xeroizer/models/payroll/benefit_line'
|
85
|
+
require 'xeroizer/models/payroll/benefit_type'
|
86
|
+
require 'xeroizer/models/payroll/deduction_line'
|
87
|
+
require 'xeroizer/models/payroll/deduction_type'
|
88
|
+
require 'xeroizer/models/payroll/earnings_line'
|
89
|
+
require 'xeroizer/models/payroll/earnings_type'
|
79
90
|
require 'xeroizer/models/payroll/employee'
|
91
|
+
require 'xeroizer/models/payroll/address'
|
92
|
+
require 'xeroizer/models/payroll/leave_line'
|
93
|
+
require 'xeroizer/models/payroll/pay_items'
|
94
|
+
require 'xeroizer/models/payroll/pay_run'
|
95
|
+
require 'xeroizer/models/payroll/pay_template'
|
96
|
+
require 'xeroizer/models/payroll/payment_method'
|
97
|
+
require 'xeroizer/models/payroll/pay_schedule'
|
98
|
+
require 'xeroizer/models/payroll/paystub'
|
99
|
+
require 'xeroizer/models/payroll/reimbursement_line'
|
100
|
+
require 'xeroizer/models/payroll/reimbursement_type'
|
101
|
+
require 'xeroizer/models/payroll/salary_and_wage'
|
102
|
+
require 'xeroizer/models/payroll/super_line'
|
103
|
+
require 'xeroizer/models/payroll/tax_declaration'
|
104
|
+
require 'xeroizer/models/payroll/time_off_line'
|
105
|
+
require 'xeroizer/models/payroll/time_off_type'
|
106
|
+
require 'xeroizer/models/payroll/work_location'
|
107
|
+
require 'xeroizer/models/payroll/leave_application'
|
108
|
+
require 'xeroizer/models/payroll/leave_period'
|
80
109
|
|
81
110
|
require 'xeroizer/report/factory'
|
82
111
|
|
83
112
|
require 'xeroizer/response'
|
84
113
|
|
85
114
|
require 'xeroizer/generic_application'
|
86
|
-
require 'xeroizer/
|
87
|
-
require 'xeroizer/private_application'
|
88
|
-
require 'xeroizer/partner_application'
|
115
|
+
require 'xeroizer/oauth2_application'
|
89
116
|
require 'xeroizer/payroll_application'
|
@@ -4,40 +4,67 @@ require "acceptance_test"
|
|
4
4
|
class AboutCreatingBankTransactions < Test::Unit::TestCase
|
5
5
|
include AcceptanceTest
|
6
6
|
|
7
|
-
|
8
|
-
|
7
|
+
def assert_exists(bank_transaction, client)
|
8
|
+
assert_not_nil bank_transaction.id,
|
9
|
+
"Cannot check for exitence unless the bank transaction has non-null identifier"
|
10
|
+
assert_not_nil client.BankTransaction.find bank_transaction.id
|
11
|
+
end
|
12
|
+
|
13
|
+
def any_line_items(account)
|
14
|
+
[{
|
15
|
+
:description => "Clingfilm bike shorts",
|
16
|
+
:quantity => 1,
|
17
|
+
:unit_amount => "17.00",
|
18
|
+
:account_code => account.code,
|
19
|
+
:tax_type => account.tax_type
|
20
|
+
}]
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_inclusive_tax(amount, tax_rate)
|
24
|
+
inclusive_tax = amount * (1 - (100/(100 + tax_rate)))
|
25
|
+
BigDecimal(inclusive_tax.to_s).round(2)
|
26
|
+
end
|
27
|
+
|
28
|
+
def get_exclusive_tax(amount, tax_rate)
|
29
|
+
exclusive_tax = amount * (tax_rate/100)
|
30
|
+
BigDecimal(exclusive_tax.to_s).round(2)
|
31
|
+
end
|
32
|
+
|
33
|
+
def get_tax_rate(tax_type, client)
|
34
|
+
@all_tax_types ||= client.TaxRate.all
|
35
|
+
@all_tax_types.select{|tax_rate| tax_rate.tax_type == tax_type}.first
|
9
36
|
end
|
10
37
|
|
11
|
-
|
12
|
-
|
13
|
-
all_accounts = client.Account.all
|
38
|
+
setup do
|
39
|
+
@client = AcceptanceTestHelpers.oauth2_client
|
40
|
+
all_accounts = @client.Account.all
|
14
41
|
@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
|
42
|
+
@bank_account = all_accounts.select{|acct| acct.status == "ACTIVE" && acct.type == "BANK"}.first
|
16
43
|
end
|
17
44
|
|
18
45
|
can "create a new SPEND bank transaction" do
|
19
|
-
new_transaction = client.BankTransaction.build(
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
46
|
+
new_transaction = @client.BankTransaction.build(
|
47
|
+
:type => "SPEND",
|
48
|
+
:contact => { :name => "Jazz Kang" },
|
49
|
+
:line_items => any_line_items(@account),
|
50
|
+
:bank_account => { :account_id => @bank_account.account_id }
|
24
51
|
)
|
25
52
|
|
26
53
|
assert new_transaction.save, "Save failed with the following errors: #{new_transaction.errors.inspect}"
|
27
|
-
assert_exists
|
54
|
+
assert_exists(new_transaction, @client)
|
28
55
|
end
|
29
56
|
|
30
57
|
can "update a SPEND bank transaction, for example by setting its status" do
|
31
|
-
new_transaction = client.BankTransaction.build(
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
58
|
+
new_transaction = @client.BankTransaction.build(
|
59
|
+
:type => "SPEND",
|
60
|
+
:contact => { :name => "Jazz Kang" },
|
61
|
+
:line_items => any_line_items(@account),
|
62
|
+
:bank_account => { :account_id => @bank_account.account_id }
|
36
63
|
)
|
37
64
|
|
38
65
|
assert new_transaction.save, "Save failed with the following errors: #{new_transaction.errors.inspect}"
|
39
66
|
|
40
|
-
assert_exists new_transaction
|
67
|
+
assert_exists new_transaction, @client
|
41
68
|
|
42
69
|
the_new_type = "RECEIVE"
|
43
70
|
|
@@ -49,110 +76,81 @@ class AboutCreatingBankTransactions < Test::Unit::TestCase
|
|
49
76
|
|
50
77
|
assert_equal expected_id, new_transaction.id, "Expected the id to be the same because it has been updated"
|
51
78
|
|
52
|
-
refreshed_bank_transaction = client.BankTransaction.find expected_id
|
79
|
+
refreshed_bank_transaction = @client.BankTransaction.find expected_id
|
53
80
|
|
54
81
|
assert_equal the_new_type, refreshed_bank_transaction.type,
|
55
|
-
|
82
|
+
"Expected the bank transaction to've had its type updated"
|
56
83
|
end
|
57
84
|
|
58
85
|
can "update a bank transaction by adding line items provided you calculate the tax_amount correctly" do
|
59
|
-
new_transaction = client.BankTransaction.build(
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
86
|
+
new_transaction = @client.BankTransaction.build(
|
87
|
+
:type => "SPEND",
|
88
|
+
:contact => { :name => "Jazz Kang" },
|
89
|
+
:line_items => any_line_items(@account),
|
90
|
+
:bank_account => { :account_id => @bank_account.account_id },
|
91
|
+
:line_amount_types => "Exclusive"
|
65
92
|
)
|
66
93
|
|
67
94
|
assert new_transaction.save, "Save failed with the following errors: #{new_transaction.errors.inspect}"
|
68
|
-
assert_exists new_transaction
|
95
|
+
assert_exists new_transaction, @client
|
69
96
|
|
70
97
|
expected_id = new_transaction.id
|
71
98
|
|
72
|
-
tax_rate = get_tax_rate(@account.tax_type).effective_rate
|
99
|
+
tax_rate = get_tax_rate(@account.tax_type, @client).effective_rate
|
73
100
|
|
74
101
|
unit_price = BigDecimal("1337.00")
|
75
102
|
|
76
103
|
the_new_line_items = [
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
104
|
+
{
|
105
|
+
:description => "Burrito skin",
|
106
|
+
:quantity => 1,
|
107
|
+
:unit_amount => unit_price,
|
108
|
+
:account_code => @account.code,
|
109
|
+
:tax_type => @account.tax_type,
|
110
|
+
:tax_amount => get_exclusive_tax(unit_price, tax_rate)
|
111
|
+
}
|
85
112
|
]
|
86
113
|
|
87
114
|
new_transaction.line_items = the_new_line_items
|
88
115
|
|
89
116
|
assert new_transaction.save, "Update failed with the following errors: #{new_transaction.errors.inspect}"
|
90
117
|
|
91
|
-
refreshed_bank_transaction = client.BankTransaction.find expected_id
|
118
|
+
refreshed_bank_transaction = @client.BankTransaction.find expected_id
|
92
119
|
|
93
120
|
assert_equal expected_id, new_transaction.id,
|
94
|
-
|
121
|
+
"Expected the id to be the same because it has been updated"
|
95
122
|
|
96
123
|
assert_equal 1, refreshed_bank_transaction.line_items.size,
|
97
|
-
|
124
|
+
"Expected the bank transaction to've had its line items updated to just one"
|
98
125
|
|
99
126
|
the_first_line_item = refreshed_bank_transaction.line_items.first
|
100
127
|
|
101
128
|
assert_equal "Burrito skin", the_first_line_item.description,
|
102
|
-
|
103
|
-
|
104
|
-
end
|
105
|
-
|
106
|
-
def get_inclusive_tax(amount, tax_rate)
|
107
|
-
inclusive_tax = amount * (1 - (100/(100 + tax_rate)))
|
108
|
-
BigDecimal(inclusive_tax.to_s).round(2)
|
109
|
-
end
|
110
|
-
|
111
|
-
def get_exclusive_tax(amount, tax_rate)
|
112
|
-
exclusive_tax = amount * (tax_rate/100)
|
113
|
-
BigDecimal(exclusive_tax.to_s).round(2)
|
114
|
-
end
|
115
|
-
|
116
|
-
def get_tax_rate tax_type
|
117
|
-
@all_tax_types ||= client.TaxRate.all
|
118
|
-
@all_tax_types.select{|tax_rate| tax_rate.tax_type == tax_type}.first
|
129
|
+
"Expected the bank transaction to've had its line items updated, " +
|
130
|
+
"but the first one's description does not match: #{the_first_line_item.inspect}"
|
119
131
|
end
|
120
132
|
|
121
133
|
can "create a new RECEIVE bank transaction" do
|
122
|
-
new_transaction = client.BankTransaction.build(
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
134
|
+
new_transaction = @client.BankTransaction.build(
|
135
|
+
:type => "RECEIVE",
|
136
|
+
:contact => { :name => "Jazz Kang" },
|
137
|
+
:line_items => any_line_items(@account),
|
138
|
+
:bank_account => { :account_id => @bank_account.account_id }
|
127
139
|
)
|
128
140
|
|
129
141
|
assert new_transaction.save, "Save failed with the following errors: #{new_transaction.errors.inspect}"
|
130
|
-
assert_exists new_transaction
|
142
|
+
assert_exists new_transaction, @client
|
131
143
|
end
|
132
144
|
|
133
145
|
it "treats line item unit_amounts as tax EXCLUSIVE"
|
134
146
|
must "not set the tax_amount manually on line items"
|
135
147
|
|
136
|
-
def assert_exists(bank_transaction)
|
137
|
-
assert_not_nil bank_transaction.id,
|
138
|
-
"Cannot check for exitence unless the bank transaction has non-null identifier"
|
139
|
-
assert_not_nil client.BankTransaction.find bank_transaction.id
|
140
|
-
end
|
141
148
|
|
142
|
-
def any_line_items(account)
|
143
|
-
[{
|
144
|
-
:description => "Clingfilm bike shorts",
|
145
|
-
:quantity => 1,
|
146
|
-
:unit_amount => "17.00",
|
147
|
-
:account_code => account.code,
|
148
|
-
:tax_type => account.tax_type
|
149
|
-
}]
|
150
|
-
end
|
151
149
|
|
152
150
|
it "fails with ApiException when you try and create a new bank account with missing account type with save! method" do
|
153
|
-
new_account = client.Account.build(
|
154
|
-
|
155
|
-
|
151
|
+
new_account = @client.Account.build(
|
152
|
+
:name => "Example bank account",
|
153
|
+
:code => "ACC-001"
|
156
154
|
)
|
157
155
|
|
158
156
|
assert_raise Xeroizer::ApiException do
|
@@ -161,9 +159,9 @@ class AboutCreatingBankTransactions < Test::Unit::TestCase
|
|
161
159
|
end
|
162
160
|
|
163
161
|
it "returns false when you try and create a new bank account with a missing account type with save method" do
|
164
|
-
new_account = client.Account.build(
|
165
|
-
|
166
|
-
|
162
|
+
new_account = @client.Account.build(
|
163
|
+
:name => "Example bank account",
|
164
|
+
:code => "ACC-001"
|
167
165
|
)
|
168
166
|
|
169
167
|
assert new_account.save == false, "Account save method expected to return false"
|
@@ -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,13 +5,13 @@ 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
|
@@ -22,22 +22,22 @@ class AboutFetchingBankTransactions < Test::Unit::TestCase
|
|
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]
|
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
41
|
assert_equal(keys, @the_first_bank_transaction.attributes.keys)
|
42
42
|
end
|
43
43
|
|
@@ -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
|
@@ -4,17 +4,13 @@ require "acceptance_test"
|
|
4
4
|
class AboutGetOnlineInvoiceUrl < Test::Unit::TestCase
|
5
5
|
include AcceptanceTest
|
6
6
|
|
7
|
-
|
8
|
-
|
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
|
9
11
|
end
|
10
12
|
|
11
|
-
|
12
|
-
super
|
13
|
-
@invoice = client.Invoice.all(:where => 'Type=="ACCREC"').first
|
14
|
-
@invoice_acc_pay = client.Invoice.all(:where => 'Type=="ACCPAY"').first
|
15
|
-
end
|
16
|
-
|
17
|
-
can "Request OnlineInvoice of an AccRec invoice" do
|
13
|
+
can "Request OnlineInvoice of an AccRec invoice" do
|
18
14
|
@online_invoice = @invoice.online_invoice
|
19
15
|
|
20
16
|
assert @online_invoice.online_invoice_url, "online_invoice_url not found"
|
@@ -26,4 +22,4 @@ class AboutGetOnlineInvoiceUrl < Test::Unit::TestCase
|
|
26
22
|
@online_invoice_acc_pay = @invoice_acc_pay.online_invoice
|
27
23
|
end
|
28
24
|
end
|
29
|
-
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
|