xeroizer 2.18.1 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (133) hide show
  1. checksums.yaml +5 -5
  2. data/README.md +199 -223
  3. data/lib/xeroizer/connection.rb +49 -0
  4. data/lib/xeroizer/exceptions.rb +2 -0
  5. data/lib/xeroizer/generic_application.rb +12 -5
  6. data/lib/xeroizer/http.rb +5 -78
  7. data/lib/xeroizer/http_response.rb +157 -0
  8. data/lib/xeroizer/models/bank_account.rb +1 -0
  9. data/lib/xeroizer/models/bank_transaction.rb +1 -0
  10. data/lib/xeroizer/models/batch_payment.rb +27 -0
  11. data/lib/xeroizer/models/branding_theme.rb +49 -9
  12. data/lib/xeroizer/models/contact.rb +10 -4
  13. data/lib/xeroizer/models/contact_group.rb +45 -0
  14. data/lib/xeroizer/models/credit_note.rb +23 -22
  15. data/lib/xeroizer/models/from_bank_account.rb +1 -0
  16. data/lib/xeroizer/models/history_record.rb +72 -0
  17. data/lib/xeroizer/models/invoice.rb +14 -3
  18. data/lib/xeroizer/models/line_item.rb +17 -5
  19. data/lib/xeroizer/models/manual_journal.rb +2 -1
  20. data/lib/xeroizer/models/option.rb +1 -1
  21. data/lib/xeroizer/models/organisation.rb +2 -0
  22. data/lib/xeroizer/models/payment_service.rb +22 -0
  23. data/lib/xeroizer/models/payroll/address.rb +53 -0
  24. data/lib/xeroizer/models/payroll/bank_account.rb +18 -6
  25. data/lib/xeroizer/models/payroll/benefit_line.rb +26 -0
  26. data/lib/xeroizer/models/payroll/benefit_type.rb +45 -0
  27. data/lib/xeroizer/models/payroll/deduction_line.rb +32 -0
  28. data/lib/xeroizer/models/payroll/deduction_type.rb +49 -0
  29. data/lib/xeroizer/models/payroll/earnings_line.rb +39 -0
  30. data/lib/xeroizer/models/payroll/earnings_type.rb +53 -0
  31. data/lib/xeroizer/models/payroll/employee.rb +30 -8
  32. data/lib/xeroizer/models/payroll/leave_application.rb +27 -0
  33. data/lib/xeroizer/models/payroll/leave_line.rb +30 -0
  34. data/lib/xeroizer/models/payroll/leave_period.rb +15 -0
  35. data/lib/xeroizer/models/payroll/pay_items.rb +22 -0
  36. data/lib/xeroizer/models/payroll/pay_run.rb +33 -0
  37. data/lib/xeroizer/models/payroll/pay_schedule.rb +40 -0
  38. data/lib/xeroizer/models/payroll/pay_template.rb +24 -0
  39. data/lib/xeroizer/models/payroll/payment_method.rb +24 -0
  40. data/lib/xeroizer/models/payroll/paystub.rb +44 -0
  41. data/lib/xeroizer/models/payroll/reimbursement_line.rb +21 -0
  42. data/lib/xeroizer/models/payroll/reimbursement_type.rb +22 -0
  43. data/lib/xeroizer/models/payroll/salary_and_wage.rb +29 -0
  44. data/lib/xeroizer/models/payroll/super_line.rb +40 -0
  45. data/lib/xeroizer/models/payroll/tax_declaration.rb +50 -0
  46. data/lib/xeroizer/models/payroll/time_off_line.rb +20 -0
  47. data/lib/xeroizer/models/payroll/time_off_type.rb +32 -0
  48. data/lib/xeroizer/models/payroll/work_location.rb +25 -0
  49. data/lib/xeroizer/models/prepayment.rb +1 -0
  50. data/lib/xeroizer/models/purchase_order.rb +6 -6
  51. data/lib/xeroizer/models/quote.rb +76 -0
  52. data/lib/xeroizer/models/schedule.rb +1 -0
  53. data/lib/xeroizer/models/tax_component.rb +1 -0
  54. data/lib/xeroizer/models/to_bank_account.rb +1 -0
  55. data/lib/xeroizer/oauth.rb +12 -1
  56. data/lib/xeroizer/oauth2.rb +82 -0
  57. data/lib/xeroizer/oauth2_application.rb +49 -0
  58. data/lib/xeroizer/payroll_application.rb +8 -3
  59. data/lib/xeroizer/record/base.rb +1 -1
  60. data/lib/xeroizer/record/base_model.rb +1 -1
  61. data/lib/xeroizer/record/base_model_http_proxy.rb +4 -0
  62. data/lib/xeroizer/record/model_definition_helper.rb +1 -1
  63. data/lib/xeroizer/record/payroll_base.rb +4 -0
  64. data/lib/xeroizer/record/record_association_helper.rb +4 -4
  65. data/lib/xeroizer/record/validators/associated_validator.rb +1 -0
  66. data/lib/xeroizer/record/xml_helper.rb +18 -18
  67. data/lib/xeroizer/report/aged_receivables_by_contact.rb +1 -1
  68. data/lib/xeroizer/report/cell_xml_helper.rb +13 -13
  69. data/lib/xeroizer/response.rb +22 -17
  70. data/lib/xeroizer/version.rb +1 -1
  71. data/lib/xeroizer.rb +33 -4
  72. data/test/acceptance/about_creating_bank_transactions_test.rb +80 -82
  73. data/test/acceptance/about_creating_prepayment_test.rb +25 -30
  74. data/test/acceptance/about_fetching_bank_transactions_test.rb +12 -12
  75. data/test/acceptance/about_online_invoice_test.rb +6 -10
  76. data/test/acceptance/acceptance_test.rb +28 -26
  77. data/test/acceptance/bank_transfer_test.rb +12 -17
  78. data/test/acceptance/bulk_operations_test.rb +18 -16
  79. data/test/acceptance/connections_test.rb +11 -0
  80. data/test/stub_responses/bad_request.json +6 -0
  81. data/test/stub_responses/connections.json +16 -0
  82. data/test/stub_responses/expired_oauth2_token.json +6 -0
  83. data/test/stub_responses/generic_response_error.json +6 -0
  84. data/test/stub_responses/invalid_oauth2_request_token.json +6 -0
  85. data/test/stub_responses/invalid_tenant_header.json +6 -0
  86. data/test/stub_responses/object_not_found.json +6 -0
  87. data/test/stub_responses/organisations.xml +10 -0
  88. data/test/stub_responses/payment_service.xml +15 -0
  89. data/test/test_helper.rb +16 -11
  90. data/test/unit/generic_application_test.rb +21 -10
  91. data/test/unit/http_test.rb +284 -10
  92. data/test/unit/models/address_test.rb +2 -2
  93. data/test/unit/models/bank_transaction_model_parsing_test.rb +2 -2
  94. data/test/unit/models/bank_transaction_test.rb +1 -1
  95. data/test/unit/models/bank_transaction_validation_test.rb +1 -1
  96. data/test/unit/models/contact_test.rb +2 -2
  97. data/test/unit/models/credit_note_test.rb +8 -8
  98. data/test/unit/models/employee_test.rb +4 -4
  99. data/test/unit/models/invoice_test.rb +12 -12
  100. data/test/unit/models/journal_line_test.rb +6 -6
  101. data/test/unit/models/journal_test.rb +4 -4
  102. data/test/unit/models/line_item_sum_test.rb +1 -1
  103. data/test/unit/models/line_item_test.rb +26 -28
  104. data/test/unit/models/manual_journal_test.rb +3 -3
  105. data/test/unit/models/organisation_test.rb +16 -2
  106. data/test/unit/models/payment_service_test.rb +29 -0
  107. data/test/unit/models/phone_test.rb +7 -7
  108. data/test/unit/models/prepayment_test.rb +4 -4
  109. data/test/unit/models/repeating_invoice_test.rb +3 -3
  110. data/test/unit/models/tax_rate_test.rb +2 -2
  111. data/test/unit/oauth2_test.rb +171 -0
  112. data/test/unit/oauth_config_test.rb +1 -1
  113. data/test/unit/record/base_model_test.rb +13 -13
  114. data/test/unit/record/base_test.rb +15 -4
  115. data/test/unit/record/block_validator_test.rb +1 -1
  116. data/test/unit/record/connection_test.rb +60 -0
  117. data/test/unit/record/model_definition_test.rb +36 -36
  118. data/test/unit/record/parse_params_test.rb +2 -2
  119. data/test/unit/record/parse_where_hash_test.rb +13 -13
  120. data/test/unit/record/record_association_test.rb +14 -14
  121. data/test/unit/record/validators_test.rb +43 -43
  122. data/test/unit/record_definition_test.rb +7 -7
  123. data/test/unit/report_definition_test.rb +7 -7
  124. data/test/unit/report_test.rb +20 -20
  125. data/test/unit_test_helper.rb +16 -0
  126. metadata +100 -25
  127. data/lib/xeroizer/models/payroll/home_address.rb +0 -24
  128. data/lib/xeroizer/partner_application.rb +0 -51
  129. data/lib/xeroizer/private_application.rb +0 -25
  130. data/lib/xeroizer/public_application.rb +0 -21
  131. data/test/unit/http_tsl_12_upgrade_test.rb +0 -31
  132. data/test/unit/oauth_test.rb +0 -118
  133. data/test/unit/private_application_test.rb +0 -20
@@ -1,10 +1,10 @@
1
- require 'test_helper'
1
+ require 'unit_test_helper'
2
2
 
3
3
  class InvoiceTest < Test::Unit::TestCase
4
4
  include TestHelper
5
-
5
+
6
6
  def setup
7
- @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
7
+ @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
8
8
  mock_api('Invoices')
9
9
  @invoice = @client.Invoice.first
10
10
  end
@@ -26,7 +26,7 @@ class InvoiceTest < Test::Unit::TestCase
26
26
  end
27
27
 
28
28
  context "invoice types" do
29
-
29
+
30
30
  should "have helpers to determine invoice type" do
31
31
  @invoice.type = 'ACCREC'
32
32
  assert_equal(true, @invoice.accounts_receivable?)
@@ -36,11 +36,11 @@ class InvoiceTest < Test::Unit::TestCase
36
36
  assert_equal(false, @invoice.accounts_receivable?)
37
37
  assert_equal(true, @invoice.accounts_payable?)
38
38
  end
39
-
39
+
40
40
  end
41
-
41
+
42
42
  context "invoice totals" do
43
-
43
+
44
44
  should "large-scale testing from API XML" do
45
45
  invoices = @client.Invoice.all
46
46
  invoices.each do | invoice |
@@ -51,7 +51,7 @@ class InvoiceTest < Test::Unit::TestCase
51
51
  end
52
52
 
53
53
  end
54
-
54
+
55
55
  context "invoice validations" do
56
56
 
57
57
  should "build an invalid invoice if there are no attributes" do
@@ -59,7 +59,7 @@ class InvoiceTest < Test::Unit::TestCase
59
59
  end
60
60
 
61
61
  should "build a valid DRAFT invoice with minimal attributes" do
62
- invoice = @client.Invoice.build :type => "ACCREC", :contact => { :name => "ABC Limited" }
62
+ invoice = @client.Invoice.build :type => "ACCREC", :date => Date.today, :contact => { :name => "ABC Limited" }
63
63
  assert_equal(true, invoice.valid?)
64
64
  end
65
65
 
@@ -105,7 +105,7 @@ class InvoiceTest < Test::Unit::TestCase
105
105
  end
106
106
 
107
107
  context "contact shortcuts" do
108
-
108
+
109
109
  should "have valid #contact_name and #contact_id without downloading full invoice" do
110
110
  invoices = @client.Invoice.all
111
111
  invoices.each do |invoice|
@@ -114,13 +114,13 @@ class InvoiceTest < Test::Unit::TestCase
114
114
  assert_equal(false, invoice.complete_record_downloaded?)
115
115
  end
116
116
  end
117
-
117
+
118
118
  end
119
119
 
120
120
  context "updated date" do
121
121
  should "get the updated date as utc" do
122
122
  invoices = @client.Invoice.all
123
-
123
+
124
124
  assert_equal(Time.parse("2008-9-16T10:28:51.5Z"), invoices[0].updated_date_utc)
125
125
 
126
126
  invoices.each do |invoice|
@@ -1,20 +1,20 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_helper'))
1
+ require 'unit_test_helper'
2
2
 
3
3
  class JournalLineTest < Test::Unit::TestCase
4
4
  include TestHelper
5
5
  include Xeroizer::Record
6
-
6
+
7
7
  def setup
8
- @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
8
+ @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
9
9
  end
10
-
10
+
11
11
  it "journal_line tracking specified correctly" do
12
12
  journal = @client.Journal.build
13
13
  journal_line = journal.add_journal_line({})
14
-
14
+
15
15
  journal_line.add_tracking_category(:name => "Name 1", :option => "Option 1")
16
16
  journal_line.add_tracking_category(:name => "Name 2", :option => "Option 2")
17
-
17
+
18
18
  doc = Nokogiri::XML(journal_line.to_xml)
19
19
  assert_equal 2, doc.xpath("/JournalLine/TrackingCategories/TrackingCategory").size
20
20
  end
@@ -1,11 +1,11 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', '..', 'test_helper'))
1
+ require 'unit_test_helper'
2
2
 
3
3
  class JournalTest < Test::Unit::TestCase
4
4
  include TestHelper
5
5
  include Xeroizer::Record
6
-
6
+
7
7
  def setup
8
- @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
8
+ @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
9
9
 
10
10
  @journal = @client.Journal.build
11
11
  @journal.journal_id = "0d926df3-459f-4264-a3a3-49ac065eb0ed"
@@ -39,6 +39,6 @@ class JournalTest < Test::Unit::TestCase
39
39
  it "should render date" do
40
40
  assert_equal "2015-01-01", @doc.xpath("//JournalDate").text
41
41
  end
42
- end
42
+ end
43
43
 
44
44
  end
@@ -1,4 +1,4 @@
1
- require "test_helper"
1
+ require 'unit_test_helper'
2
2
 
3
3
  class LineItemSumTest < Test::Unit::TestCase
4
4
  include Xeroizer::Record
@@ -1,11 +1,11 @@
1
- require "test_helper"
1
+ require 'unit_test_helper'
2
2
 
3
3
  class LineItemTest < Test::Unit::TestCase
4
4
  include TestHelper
5
5
  include Xeroizer::Record
6
6
 
7
7
  def setup
8
- @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
8
+ @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
9
9
  end
10
10
 
11
11
  it "line_item tracking specified correctly" do
@@ -26,7 +26,7 @@ class LineItemTest < Test::Unit::TestCase
26
26
  line_item.unit_amount = BigDecimal("1337.00")
27
27
 
28
28
  assert_equal "1337.0", line_item.line_amount.to_s,
29
- "expected line_amount to equal unit_amount times quantity"
29
+ "expected line_amount to equal unit_amount times quantity"
30
30
  end
31
31
 
32
32
  it "line_amount equals unit_amount times quantity minus the discount if there is a discount_rate" do
@@ -36,43 +36,41 @@ class LineItemTest < Test::Unit::TestCase
36
36
  line_item.discount_rate = BigDecimal("12.34")
37
37
 
38
38
  assert_equal "1172.01", line_item.line_amount.to_s,
39
- "expected line_amount to equal unit_amount times quantity minus the discount"
39
+ "expected line_amount to equal unit_amount times quantity minus the discount"
40
40
  end
41
41
 
42
- it "line_amount is zero when quantity is nil or zero" do
42
+ it "line_amount equals unit_amount times quantity minus the discount if there is a discount_amount" do
43
43
  line_item = LineItem.new(nil)
44
+ line_item.quantity = 1
45
+ line_item.unit_amount = BigDecimal("1337.00")
46
+ line_item.discount_amount = BigDecimal("164.99")
44
47
 
45
- line_item.quantity = nil
46
- line_item.unit_amount = BigDecimal("1.00")
47
-
48
- assert_equal "0.0", line_item.line_amount.to_s,
49
- "expected line amount to be zero when quantity is nil"
50
-
51
- line_item.quantity = 0
52
- assert_equal "0.0", line_item.line_amount.to_s,
53
- "expected line amount to be zero when quantity is zero"
48
+ assert_equal "1172.01", line_item.line_amount.to_s,
49
+ "expected line_amount to equal unit_amount times quantity minus the discount amount"
54
50
  end
55
51
 
56
- it "is not possible to set unit_amount to zero" do
52
+ it "coerces decimals when calculating line amount" do
57
53
  line_item = LineItem.new(nil)
54
+ line_item.quantity = "1"
55
+ line_item.unit_amount = 50
56
+ assert_equal 50, line_item.line_amount,
57
+ "expected line amount to be calculated from coerced values"
58
+ end
58
59
 
59
- line_item.unit_amount = nil
60
+ context "line_item validations" do
60
61
 
61
- assert_equal 0.0, line_item.unit_amount,
62
- "Expected setting unit_amount to nil to be ignored, i.e., it should remain zero"
63
- end
62
+ it "is an invalid line_item if there is no description" do
63
+ line_item = LineItem.new(nil)
64
64
 
65
- it "line_amount is zero when unit_amount is nil or zero" do
66
- line_item = LineItem.new(nil)
65
+ assert_equal(false, line_item.valid?)
66
+ end
67
67
 
68
- line_item.quantity = 1
69
- line_item.unit_amount = nil
68
+ it "is a valid line_item with minimal attributes" do
69
+ line_item = LineItem.new(nil)
70
+ line_item.description = "Test Description"
70
71
 
71
- assert_equal "0.0", line_item.line_amount.to_s,
72
- "expected line amount to be zero when unit_amount is nil"
72
+ assert_equal(true, line_item.valid?)
73
+ end
73
74
 
74
- line_item.unit_amount = BigDecimal("0.00")
75
- assert_equal "0.0", line_item.line_amount.to_s,
76
- "expected line amount to be zero when unit_amount is zero"
77
75
  end
78
76
  end
@@ -1,10 +1,10 @@
1
- require 'test_helper'
1
+ require 'unit_test_helper'
2
2
 
3
3
  class ManualJournalTest < Test::Unit::TestCase
4
4
  include TestHelper
5
5
 
6
6
  def setup
7
- @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
7
+ @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
8
8
  mock_api('ManualJournals')
9
9
  end
10
10
 
@@ -22,4 +22,4 @@ class ManualJournalTest < Test::Unit::TestCase
22
22
  end
23
23
  end
24
24
  end
25
- end
25
+ end
@@ -1,10 +1,10 @@
1
- require 'test_helper'
1
+ require 'unit_test_helper'
2
2
 
3
3
  class OrganisationTest < Test::Unit::TestCase
4
4
  include TestHelper
5
5
 
6
6
  def setup
7
- @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
7
+ @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
8
8
  end
9
9
 
10
10
  context "sales_tax_basis_validations" do
@@ -35,4 +35,18 @@ class OrganisationTest < Test::Unit::TestCase
35
35
  end
36
36
  end
37
37
 
38
+ context "parse response" do
39
+ it "includes payment_terms" do
40
+ @instance = Xeroizer::Record::OrganisationModel.new(nil, "Organisation")
41
+ some_xml = get_record_xml("organisations")
42
+
43
+ result = @instance.parse_response(some_xml)
44
+ organisation = result.response_items.first
45
+
46
+ assert_equal(organisation.payment_terms.bills.day, "4")
47
+ assert_equal(organisation.payment_terms.bills.type, "OFFOLLOWINGMONTH")
48
+ assert_equal(organisation.payment_terms.sales.day, "2")
49
+ assert_equal(organisation.payment_terms.sales.type, "OFFOLLOWINGMONTH")
50
+ end
51
+ end
38
52
  end
@@ -0,0 +1,29 @@
1
+ require 'unit_test_helper'
2
+
3
+ class PaymentServiceTest < Test::Unit::TestCase
4
+ include TestHelper
5
+
6
+ def setup
7
+ @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
8
+ end
9
+
10
+ context "response parsing" do
11
+ it "parses default attributes" do
12
+ @instance = Xeroizer::Record::PaymentServiceModel.new(nil, "PaymentService")
13
+
14
+ some_xml = get_record_xml("payment_service")
15
+
16
+ result = @instance.parse_response(some_xml)
17
+ payment_service = result.response_items.first
18
+
19
+ keys = [:payment_service_id,
20
+ :payment_service_name,
21
+ :payment_service_type,
22
+ :payment_service_url,
23
+ :pay_now_text
24
+ ]
25
+
26
+ assert_equal(payment_service.attributes.keys, keys)
27
+ end
28
+ end
29
+ end
@@ -1,23 +1,23 @@
1
- require 'test_helper'
1
+ require 'unit_test_helper'
2
2
 
3
3
  class PhoneTest < Test::Unit::TestCase
4
4
  include TestHelper
5
-
5
+
6
6
  def setup
7
- @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
7
+ @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
8
8
  @contact = @client.Contact.build
9
9
 
10
10
  end
11
-
11
+
12
12
  context "validators" do
13
-
13
+
14
14
  should "not allow long phone numbers" do
15
15
  @phone = @contact.add_phone(phone_number: "1234567890123456789012345678901234567890123456789012345678901234567890")
16
16
  assert_equal(false, @phone.valid?)
17
17
  blank_error = @phone.errors_for(:phone_number).first
18
18
  assert_not_nil(blank_error)
19
19
  assert_equal("must be shorter than 50 characters", blank_error)
20
-
20
+
21
21
  end
22
22
 
23
23
  should "allow phone numbers" do
@@ -27,5 +27,5 @@ class PhoneTest < Test::Unit::TestCase
27
27
  assert_equal(0, @phone.errors.size)
28
28
  end
29
29
  end
30
-
30
+
31
31
  end
@@ -1,14 +1,14 @@
1
- require 'test_helper'
1
+ require 'unit_test_helper'
2
2
 
3
3
  class PrepaymentTest < Test::Unit::TestCase
4
4
  include TestHelper
5
-
5
+
6
6
  def setup
7
- @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
7
+ @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
8
8
  mock_api("Prepayments")
9
9
  @prepayment = @client.Prepayment.first
10
10
  end
11
-
11
+
12
12
  context "prepayment attributes" do
13
13
  should "large-scale testing from API XML" do
14
14
  prepayments = @client.Prepayment.all
@@ -1,10 +1,10 @@
1
- require 'test_helper'
1
+ require 'unit_test_helper'
2
2
 
3
3
  class RepeatingInvoiceTest < Test::Unit::TestCase
4
4
  include TestHelper
5
5
 
6
6
  def setup
7
- @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
7
+ @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
8
8
  mock_api('RepeatingInvoices')
9
9
  end
10
10
 
@@ -18,7 +18,7 @@ class RepeatingInvoiceTest < Test::Unit::TestCase
18
18
  repeating_invoice = repeating_invoices.first
19
19
 
20
20
  assert_equal "PowerDirect", repeating_invoice.contact_name
21
- assert_equal BigDecimal.new(90), repeating_invoice.total
21
+ assert_equal BigDecimal(90), repeating_invoice.total
22
22
  assert_equal true, repeating_invoice.accounts_payable?
23
23
 
24
24
  schedule = repeating_invoice.schedule
@@ -1,11 +1,11 @@
1
- require 'test_helper'
1
+ require 'unit_test_helper'
2
2
  require 'mocha/test_unit'
3
3
 
4
4
  class TaxRateTest < Test::Unit::TestCase
5
5
  include TestHelper
6
6
 
7
7
  def setup
8
- @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
8
+ @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
9
9
  end
10
10
 
11
11
  should "have a primary key value of :name" do
@@ -0,0 +1,171 @@
1
+ require 'unit_test_helper'
2
+
3
+ class OAuth2Test < UnitTestCase
4
+ include TestHelper
5
+
6
+ setup do
7
+ @client_id = 'client_id'
8
+ @client_secret = 'client_secret'
9
+ @access_token = 'access_token'
10
+ @site = 'https://example.com'
11
+ @content_type = 'application/xml'
12
+ @path = '/path'
13
+ @uri = "#{@site}#{@path}"
14
+ @response_body = '{"test": true}'
15
+ @status_code = 200
16
+ @additional_headers = {foo: 'bar'}
17
+ @request_body = "xml"
18
+ @request_headers = { 'Content-Type' => @content_type }
19
+ @tenant_id = "tenant"
20
+ end
21
+
22
+ def instance
23
+ Xeroizer::OAuth2.new(@client_id, @client_secret, {
24
+ site: @site
25
+ }).tap do |oauth2|
26
+ oauth2.authorize_from_access(@access_token)
27
+ end
28
+ end
29
+
30
+ context "get" do
31
+ setup do
32
+ stub_request(:get, @uri).
33
+ with(
34
+ headers: {
35
+ 'Authorization' => "Bearer #{@access_token}",
36
+ }
37
+ ).to_return(status: @status_code, body: @response_body, headers: {})
38
+ end
39
+
40
+ context "when tenant_id is not present" do
41
+ should "make a get request" do
42
+ result = instance.get(@path)
43
+ assert_equal(result.code, @status_code)
44
+ assert_equal(result.plain_body, @response_body)
45
+ assert_requested :get, @uri
46
+ assert_not_requested :get, @uri, headers: { "Xero-tenant-id" => @tenant_id }
47
+ end
48
+ end
49
+
50
+ context "when tenant_id is present" do
51
+ setup do
52
+ @client = instance
53
+ @client.tenant_id = @tenant_id
54
+ end
55
+
56
+ should "make a get request with the tenant_id" do
57
+ result = @client.get(@path)
58
+ assert_equal(result.code, @status_code)
59
+ assert_equal(result.plain_body, @response_body)
60
+ assert_requested :get, @uri, headers: { "Xero-tenant-id" => @tenant_id }
61
+ end
62
+ end
63
+ end
64
+
65
+ context "delete" do
66
+ setup do
67
+ stub_request(:delete, @uri).
68
+ with(
69
+ headers: {
70
+ 'Authorization' => "Bearer #{@access_token}",
71
+ }
72
+ ).to_return(status: @status_code, body: @response_body, headers: {})
73
+ end
74
+
75
+ context "when tenant_id is not present" do
76
+ should "make a delete request" do
77
+ result = instance.delete(@path)
78
+ assert_equal(result.code, @status_code)
79
+ assert_not_requested :delete, @uri, headers: { "Xero-tenant-id" => @tenant_id }
80
+ end
81
+ end
82
+
83
+
84
+ context "when tenant_id is present" do
85
+ setup do
86
+ @client = instance
87
+ @client.tenant_id = @tenant_id
88
+ end
89
+
90
+ should "make a delete request with the tenant_id" do
91
+ result = @client.delete(@path)
92
+ assert_equal(result.code, @status_code)
93
+ assert_equal(result.plain_body, @response_body)
94
+ assert_requested :delete, @uri, headers: { "Xero-tenant-id" => @tenant_id }
95
+ end
96
+ end
97
+ end
98
+
99
+ context "post" do
100
+ setup do
101
+ stub_request(:post, @uri).
102
+ with(
103
+ body: @request_body,
104
+ headers: {
105
+ 'Authorization' => "Bearer #{@access_token}",
106
+ 'Content-Type' => @content_type,
107
+ }).
108
+ to_return(status: @status_code, body: @response_body, headers: @request_headers)
109
+
110
+ end
111
+
112
+ context "when tenant_id is not present" do
113
+ should "make a post request" do
114
+ result = instance.post(@path, @request_body, @request_headers)
115
+ assert_equal(result.code, @status_code)
116
+ assert_equal(result.plain_body, @response_body)
117
+ assert_not_requested :post, @uri, headers: { "Xero-tenant-id" => @tenant_id }
118
+ end
119
+ end
120
+
121
+ context "when tenant_id is present" do
122
+ setup do
123
+ @client = instance
124
+ @client.tenant_id = @tenant_id
125
+ end
126
+
127
+ should "make a post request with the tenant_id" do
128
+ result = @client.post(@path, @request_body, @request_headers)
129
+ assert_equal(result.code, @status_code)
130
+ assert_equal(result.plain_body, @response_body)
131
+ assert_requested :post, @uri, headers: { "Xero-tenant-id" => @tenant_id }
132
+ end
133
+ end
134
+ end
135
+
136
+ context "put" do
137
+ setup do
138
+ stub_request(:put, @uri).
139
+ with(
140
+ body: @request_body,
141
+ headers: {
142
+ 'Authorization' => "Bearer #{@access_token}",
143
+ 'Content-Type' => @content_type,
144
+ }).
145
+ to_return(status: @status_code, body: @response_body, headers: @request_headers)
146
+ end
147
+
148
+ context "when tenant_id is not present" do
149
+ should "make a put request" do
150
+ result = instance.put(@path, @request_body, @request_headers)
151
+ assert_equal(result.code, @status_code)
152
+ assert_equal(result.plain_body, @response_body)
153
+ assert_not_requested :put, @uri, headers: { "Xero-tenant-id" => @tenant_id }
154
+ end
155
+ end
156
+
157
+ context "when tenant_id is present" do
158
+ setup do
159
+ @client = instance
160
+ @client.tenant_id = @tenant_id
161
+ end
162
+
163
+ should "make a put request" do
164
+ result = @client.put(@path, @request_body, @request_headers)
165
+ assert_equal(result.code, @status_code)
166
+ assert_equal(result.plain_body, @response_body)
167
+ assert_requested :put, @uri, headers: { "Xero-tenant-id" => @tenant_id }
168
+ end
169
+ end
170
+ end
171
+ end
@@ -1,4 +1,4 @@
1
- require "test_helper"
1
+ require 'unit_test_helper'
2
2
 
3
3
  class OAuthConfigTest < Test::Unit::TestCase
4
4
  include Xeroizer
@@ -1,50 +1,50 @@
1
- require 'test_helper'
1
+ require 'unit_test_helper'
2
2
 
3
3
  class RecordBaseModelTest < Test::Unit::TestCase
4
4
  include TestHelper
5
-
5
+
6
6
  class AppleModel < Xeroizer::Record::BaseModel
7
7
  set_api_controller_name 'AppleController'
8
8
  set_permissions :read, :write
9
9
  end
10
-
10
+
11
11
  class PearModel < Xeroizer::Record::BaseModel
12
12
  set_api_controller_name 'PearController'
13
13
  set_permissions :read
14
14
  end
15
-
15
+
16
16
  class OrangeModel < Xeroizer::Record::BaseModel
17
17
  set_permissions :read, :write, :update
18
18
  end
19
-
19
+
20
20
  def setup
21
- @client = Xeroizer::PublicApplication.new(CONSUMER_KEY, CONSUMER_SECRET)
21
+ @client = Xeroizer::OAuth2Application.new(CLIENT_ID, CLIENT_SECRET)
22
22
  @apple_model = AppleModel.new(@client, 'Apple')
23
23
  @pear_model = PearModel.new(@client, 'Pear')
24
24
  @orange_model = OrangeModel.new(@client, 'Orange')
25
25
  end
26
-
26
+
27
27
  context "RecordModel.api_controller_name" do
28
-
28
+
29
29
  should "api_controller_name should default to pluralized model name" do
30
30
  assert_equal('Oranges', @orange_model.api_controller_name)
31
31
  end
32
-
32
+
33
33
  should "set_api_controller_name should set the base controller name used by Xero" do
34
34
  assert_equal('AppleController', @apple_model.api_controller_name)
35
35
  assert_equal('PearController', @pear_model.api_controller_name)
36
36
  end
37
-
37
+
38
38
  end
39
-
39
+
40
40
  context "model permssions" do
41
-
41
+
42
42
  should "save permissions correctly" do
43
43
  assert_equal(%w(read write), @apple_model.class.permissions.keys.map(&:to_s).sort)
44
44
  assert_equal(%w(read), @pear_model.class.permissions.keys.map(&:to_s).sort)
45
45
  assert_equal(%w(read update write), @orange_model.class.permissions.keys.map(&:to_s).sort)
46
46
  end
47
-
47
+
48
48
  end
49
49
 
50
50
  context "InvalidPermissionError" do