business-central 1.0.3 → 1.0.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +58 -15
  3. data/lib/business_central/client.rb +71 -41
  4. data/lib/business_central/exceptions.rb +19 -9
  5. data/lib/business_central/object/account.rb +4 -2
  6. data/lib/business_central/object/aged_account_payable.rb +4 -2
  7. data/lib/business_central/object/aged_account_receivable.rb +4 -2
  8. data/lib/business_central/object/argument_helper.rb +22 -0
  9. data/lib/business_central/object/attachment.rb +30 -0
  10. data/lib/business_central/object/balance_sheet.rb +4 -2
  11. data/lib/business_central/object/base.rb +90 -56
  12. data/lib/business_central/object/cash_flow_statement.rb +4 -2
  13. data/lib/business_central/object/company.rb +5 -3
  14. data/lib/business_central/object/company_information.rb +7 -5
  15. data/lib/business_central/object/country_region.rb +8 -6
  16. data/lib/business_central/object/currency.rb +8 -6
  17. data/lib/business_central/object/customer.rb +16 -9
  18. data/lib/business_central/object/customer_financial_detail.rb +3 -1
  19. data/lib/business_central/object/customer_payment.rb +8 -6
  20. data/lib/business_central/object/customer_payment_journal.rb +8 -6
  21. data/lib/business_central/object/customer_sale.rb +3 -1
  22. data/lib/business_central/object/default_dimension.rb +18 -21
  23. data/lib/business_central/object/dimension.rb +20 -0
  24. data/lib/business_central/object/dimension_line.rb +37 -0
  25. data/lib/business_central/object/dimension_value.rb +28 -0
  26. data/lib/business_central/object/employee.rb +21 -0
  27. data/lib/business_central/object/filter_query.rb +18 -0
  28. data/lib/business_central/object/general_ledger_entry.rb +13 -0
  29. data/lib/business_central/object/income_statement.rb +13 -0
  30. data/lib/business_central/object/irs1099_code.rb +16 -0
  31. data/lib/business_central/object/item.rb +17 -10
  32. data/lib/business_central/object/item_category.rb +16 -0
  33. data/lib/business_central/object/journal.rb +29 -0
  34. data/lib/business_central/object/journal_line.rb +48 -0
  35. data/lib/business_central/object/{helper.rb → object_helper.rb} +18 -10
  36. data/lib/business_central/object/payment_method.rb +16 -0
  37. data/lib/business_central/object/payment_term.rb +16 -0
  38. data/lib/business_central/object/picture.rb +53 -0
  39. data/lib/business_central/object/purchase_invoice.rb +8 -6
  40. data/lib/business_central/object/purchase_invoice_line.rb +10 -8
  41. data/lib/business_central/object/purchase_order.rb +16 -0
  42. data/lib/business_central/object/request.rb +60 -49
  43. data/lib/business_central/object/response.rb +31 -23
  44. data/lib/business_central/object/retained_earning_statement.rb +13 -0
  45. data/lib/business_central/object/sales_credit_memo.rb +20 -0
  46. data/lib/business_central/object/sales_credit_memo_line.rb +30 -0
  47. data/lib/business_central/object/sales_invoice.rb +62 -0
  48. data/lib/business_central/object/sales_invoice_line.rb +30 -0
  49. data/lib/business_central/object/sales_order.rb +20 -0
  50. data/lib/business_central/object/sales_order_line.rb +30 -0
  51. data/lib/business_central/object/sales_quote.rb +20 -0
  52. data/lib/business_central/object/sales_quote_line.rb +30 -0
  53. data/lib/business_central/object/shipment_method.rb +16 -0
  54. data/lib/business_central/object/subscription.rb +16 -0
  55. data/lib/business_central/object/tax_area.rb +16 -0
  56. data/lib/business_central/object/tax_group.rb +16 -0
  57. data/lib/business_central/object/time_registration_entry.rb +16 -0
  58. data/lib/business_central/object/trial_balance.rb +13 -0
  59. data/lib/business_central/object/units_of_measure.rb +16 -0
  60. data/lib/business_central/object/url_builder.rb +59 -0
  61. data/lib/business_central/object/url_helper.rb +44 -0
  62. data/lib/business_central/object/validation.rb +10 -7
  63. data/lib/business_central/object/vendor.rb +10 -7
  64. data/lib/business_central/object/vendor_purchase.rb +13 -0
  65. data/lib/business_central/version.rb +4 -2
  66. data/lib/business_central/web_service.rb +78 -0
  67. data/lib/business_central.rb +40 -2
  68. data/lib/core_ext/string.rb +18 -12
  69. data/test/business_central/client_test.rb +18 -11
  70. data/test/business_central/object/account_test.rb +6 -5
  71. data/test/business_central/object/aged_account_payable_test.rb +6 -5
  72. data/test/business_central/object/aged_account_receivable_test.rb +6 -5
  73. data/test/business_central/object/attachment_test.rb +117 -0
  74. data/test/business_central/object/balance_sheet_test.rb +6 -5
  75. data/test/business_central/object/base_test.rb +4 -2
  76. data/test/business_central/object/cash_flow_statement_test.rb +6 -5
  77. data/test/business_central/object/company_information_test.rb +9 -10
  78. data/test/business_central/object/company_test.rb +6 -5
  79. data/test/business_central/object/country_region_test.rb +16 -17
  80. data/test/business_central/object/currency_test.rb +17 -18
  81. data/test/business_central/object/customer_financial_detail_test.rb +8 -6
  82. data/test/business_central/object/customer_payment_journal_test.rb +14 -15
  83. data/test/business_central/object/customer_payment_test.rb +15 -16
  84. data/test/business_central/object/customer_sale_test.rb +8 -6
  85. data/test/business_central/object/customer_test.rb +59 -16
  86. data/test/business_central/object/default_dimension_test.rb +15 -16
  87. data/test/business_central/object/dimension_line_test.rb +165 -0
  88. data/test/business_central/object/dimension_test.rb +65 -0
  89. data/test/business_central/object/dimension_value_test.rb +68 -0
  90. data/test/business_central/object/employee_test.rb +141 -0
  91. data/test/business_central/object/filter_query_test.rb +36 -0
  92. data/test/business_central/object/general_ledger_entry_test.rb +82 -0
  93. data/test/business_central/object/income_statement_test.rb +82 -0
  94. data/test/business_central/object/irs1099_code_test.rb +124 -0
  95. data/test/business_central/object/item_category_test.rb +122 -0
  96. data/test/business_central/object/item_test.rb +16 -17
  97. data/test/business_central/object/journal_line_test.rb +152 -0
  98. data/test/business_central/object/journal_test.rb +144 -0
  99. data/test/business_central/object/payment_method_test.rb +134 -0
  100. data/test/business_central/object/payment_term_test.rb +134 -0
  101. data/test/business_central/object/picture_test.rb +74 -0
  102. data/test/business_central/object/purchase_invoice_line_test.rb +15 -15
  103. data/test/business_central/object/purchase_invoice_test.rb +15 -15
  104. data/test/business_central/object/request_test.rb +17 -9
  105. data/test/business_central/object/response_test.rb +14 -7
  106. data/test/business_central/object/retained_earning_statement_test.rb +52 -0
  107. data/test/business_central/object/sales_credit_memo_line_test.rb +134 -0
  108. data/test/business_central/object/sales_credit_memo_test.rb +146 -0
  109. data/test/business_central/object/sales_invoice_line_test.rb +164 -0
  110. data/test/business_central/object/sales_invoice_test.rb +156 -0
  111. data/test/business_central/object/sales_order_line_test.rb +134 -0
  112. data/test/business_central/object/sales_order_test.rb +146 -0
  113. data/test/business_central/object/sales_quote_line_test.rb +134 -0
  114. data/test/business_central/object/sales_quote_test.rb +146 -0
  115. data/test/business_central/object/shipment_method_test.rb +133 -0
  116. data/test/business_central/object/subscription_test.rb +126 -0
  117. data/test/business_central/object/tax_area_test.rb +126 -0
  118. data/test/business_central/object/tax_group_test.rb +126 -0
  119. data/test/business_central/object/time_registration_entry_test.rb +126 -0
  120. data/test/business_central/object/trial_balance_test.rb +82 -0
  121. data/test/business_central/object/units_of_measure_test.rb +126 -0
  122. data/test/business_central/object/validation_test.rb +5 -4
  123. data/test/business_central/object/vendor_purchase_test.rb +82 -0
  124. data/test/business_central/object/vendor_test.rb +16 -16
  125. data/test/business_central/web_service_test.rb +100 -0
  126. data/test/business_central_test.rb +3 -1
  127. data/test/test_helper.rb +12 -6
  128. metadata +153 -41
@@ -1,4 +1,6 @@
1
- require "test_helper"
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
2
4
  # rake test TEST=test/business_central/object/validation_test.rb
3
5
 
4
6
  class BusinessCentral::Object::ValidationTest < Minitest::Test
@@ -33,7 +35,7 @@ class BusinessCentral::Object::ValidationTest < Minitest::Test
33
35
  def test_validation_inclusive_value
34
36
  validation_rules = {
35
37
  type: {
36
- inclusion_of: ['1', '2', '3']
38
+ inclusion_of: %w[1 2 3]
37
39
  }
38
40
  }
39
41
  object_params = {
@@ -57,5 +59,4 @@ class BusinessCentral::Object::ValidationTest < Minitest::Test
57
59
  BusinessCentral::Object::Validation.new(validation_rules, object_params).valid?
58
60
  end
59
61
  end
60
-
61
- end
62
+ end
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+ # rake test TEST=test/business_central/object/vendor_purchase_test.rb
5
+
6
+ class BusinessCentral::Object::VendorPurchaseTest < Minitest::Test
7
+ def setup
8
+ @company_id = '123456'
9
+ @client = BusinessCentral::Client.new
10
+ @vendor_purchase = @client.vendor_purchase(company_id: @company_id)
11
+ end
12
+
13
+ def test_find_all
14
+ stub_request(:get, /vendorPurchases/)
15
+ .to_return(
16
+ status: 200,
17
+ body: {
18
+ 'value': [
19
+ {
20
+ id: 1,
21
+ number: '1009'
22
+ }
23
+ ]
24
+ }.to_json
25
+ )
26
+
27
+ response = @vendor_purchase.find_all
28
+ assert_equal response.first[:number], '1009'
29
+ end
30
+
31
+ def test_find_by_id
32
+ test_id = '09876'
33
+ stub_request(:get, /vendorPurchases\(#{test_id}\)/)
34
+ .to_return(
35
+ status: 200,
36
+ body: {
37
+ id: test_id,
38
+ number: '1010'
39
+ }.to_json
40
+ )
41
+
42
+ response = @vendor_purchase.find_by_id(test_id)
43
+ assert_equal response[:number], '1010'
44
+ end
45
+
46
+ def test_where
47
+ test_filter = "number eq '1020'"
48
+ stub_request(:get, /vendorPurchases\?\$filter=#{test_filter}/)
49
+ .to_return(
50
+ status: 200,
51
+ body: {
52
+ 'value': [
53
+ {
54
+ id: '345',
55
+ number: '1011'
56
+ }
57
+ ]
58
+ }.to_json
59
+ )
60
+
61
+ response = @vendor_purchase.where(test_filter)
62
+ assert_equal response.first[:number], '1011'
63
+ end
64
+
65
+ def test_create
66
+ assert_raises BusinessCentral::NoSupportedMethod do
67
+ @vendor_purchase.create({})
68
+ end
69
+ end
70
+
71
+ def test_update
72
+ assert_raises BusinessCentral::NoSupportedMethod do
73
+ @vendor_purchase.update('123', {})
74
+ end
75
+ end
76
+
77
+ def test_delete
78
+ assert_raises BusinessCentral::NoSupportedMethod do
79
+ @vendor_purchase.destroy('123')
80
+ end
81
+ end
82
+ end
@@ -1,4 +1,6 @@
1
- require "test_helper"
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
2
4
  # rake test TEST=test/business_central/object/vendor_test.rb
3
5
 
4
6
  class BusinessCentral::Object::VendorTest < Minitest::Test
@@ -9,16 +11,16 @@ class BusinessCentral::Object::VendorTest < Minitest::Test
9
11
  end
10
12
 
11
13
  def test_find_all
12
- stub_request(:get, /\/vendors/)
14
+ stub_request(:get, %r{/vendors})
13
15
  .to_return(
14
- status: 200,
16
+ status: 200,
15
17
  body: {
16
18
  'value': [
17
19
  {
18
20
  displayName: 'vendor1'
19
21
  }
20
22
  ]
21
- }.to_json,
23
+ }.to_json
22
24
  )
23
25
 
24
26
  response = @vendor.find_all
@@ -29,7 +31,7 @@ class BusinessCentral::Object::VendorTest < Minitest::Test
29
31
  test_vendor_id = '09876'
30
32
  stub_request(:get, /vendors\(#{test_vendor_id}\)/)
31
33
  .to_return(
32
- status: 200,
34
+ status: 200,
33
35
  body: {
34
36
  displayName: 'vendor2'
35
37
  }.to_json
@@ -43,7 +45,7 @@ class BusinessCentral::Object::VendorTest < Minitest::Test
43
45
  test_filter = "displayName eq 'vendor3'"
44
46
  stub_request(:get, /vendors\?\$filter=#{test_filter}/)
45
47
  .to_return(
46
- status: 200,
48
+ status: 200,
47
49
  body: {
48
50
  'value': [
49
51
  {
@@ -60,15 +62,15 @@ class BusinessCentral::Object::VendorTest < Minitest::Test
60
62
  def test_create
61
63
  stub_request(:post, /vendors/)
62
64
  .to_return(
63
- status: 200,
65
+ status: 200,
64
66
  body: {
65
67
  displayName: 'vendor4'
66
68
  }.to_json
67
69
  )
68
70
 
69
- response = @vendor.create({
71
+ response = @vendor.create(
70
72
  display_name: 'vendor4'
71
- })
73
+ )
72
74
  assert_equal response[:display_name], 'vendor4'
73
75
  end
74
76
 
@@ -76,7 +78,7 @@ class BusinessCentral::Object::VendorTest < Minitest::Test
76
78
  test_vendor_id = '011123'
77
79
  stub_request(:get, /vendors\(#{test_vendor_id}\)/)
78
80
  .to_return(
79
- status: 200,
81
+ status: 200,
80
82
  body: {
81
83
  etag: '112',
82
84
  displayName: 'vendor5'
@@ -85,7 +87,7 @@ class BusinessCentral::Object::VendorTest < Minitest::Test
85
87
 
86
88
  stub_request(:patch, /vendors\(#{test_vendor_id}\)/)
87
89
  .to_return(
88
- status: 200,
90
+ status: 200,
89
91
  body: {
90
92
  displayName: 'vendor6'
91
93
  }.to_json
@@ -93,9 +95,7 @@ class BusinessCentral::Object::VendorTest < Minitest::Test
93
95
 
94
96
  response = @vendor.update(
95
97
  test_vendor_id,
96
- {
97
- display_name: 'vendor6'
98
- }
98
+ display_name: 'vendor6'
99
99
  )
100
100
  assert_equal response[:display_name], 'vendor6'
101
101
  end
@@ -104,7 +104,7 @@ class BusinessCentral::Object::VendorTest < Minitest::Test
104
104
  test_vendor_id = '0111245'
105
105
  stub_request(:get, /vendors\(#{test_vendor_id}\)/)
106
106
  .to_return(
107
- status: 200,
107
+ status: 200,
108
108
  body: {
109
109
  etag: '113',
110
110
  displayName: 'vendor7'
@@ -116,4 +116,4 @@ class BusinessCentral::Object::VendorTest < Minitest::Test
116
116
 
117
117
  assert @vendor.destroy(test_vendor_id)
118
118
  end
119
- end
119
+ end
@@ -0,0 +1,100 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+ # rake test TEST=test/business_central/web_service_test.rb
5
+
6
+ class BusinessCentral::WebServiceTest < Minitest::Test
7
+ def setup
8
+ @client = BusinessCentral::Client.new
9
+ @web_service = BusinessCentral::WebService.new(client: @client)
10
+ end
11
+
12
+ def test_build_object_url
13
+ @web_service.object('Company/Vendors')
14
+ assert_equal @web_service.object_url, 'Company/Vendors'
15
+ end
16
+
17
+ def test_build_object_url_with_array_template_values
18
+ @web_service.object("Company('?')", 'business1')
19
+ assert_equal @web_service.object_url, "Company('business1')"
20
+ end
21
+
22
+ def test_build_object_url_with_hash_template_values
23
+ @web_service.object("Company(':business_name')", business_name: 'business1')
24
+ assert_equal @web_service.object_url, "Company('business1')"
25
+ end
26
+
27
+ def test_object_get_request
28
+ stub_request(:get, /Company/)
29
+ .to_return(
30
+ status: 200,
31
+ body: {
32
+ 'value': [
33
+ {
34
+ displayName: 'business1'
35
+ }
36
+ ]
37
+ }.to_json
38
+ )
39
+
40
+ response = @web_service.object('Company').get
41
+ assert_equal response.first[:display_name], 'business1'
42
+ end
43
+
44
+ def test_object_post_request
45
+ stub_request(:post, /Company/)
46
+ .to_return(
47
+ status: 200,
48
+ body: {
49
+ displayName: 'business2'
50
+ }.to_json
51
+ )
52
+
53
+ response = @web_service.object('Company').post(
54
+ display_name: 'business2'
55
+ )
56
+ assert_equal response[:display_name], 'business2'
57
+ end
58
+
59
+ def test_object_patch_request
60
+ test_company_name = 'business3'
61
+ stub_request(:get, /Company\('#{test_company_name}'\)/)
62
+ .to_return(
63
+ status: 200,
64
+ body: {
65
+ etag: '112',
66
+ displayName: 'business3'
67
+ }.to_json
68
+ )
69
+
70
+ stub_request(:patch, /Company\('#{test_company_name}'\)/)
71
+ .to_return(
72
+ status: 200,
73
+ body: {
74
+ displayName: 'business4'
75
+ }.to_json
76
+ )
77
+
78
+ response = @web_service.object("Company('?')", test_company_name).patch(
79
+ display_name: 'business4'
80
+ )
81
+ assert_equal response[:display_name], 'business4'
82
+ end
83
+
84
+ def test_object_delete_request
85
+ test_company_name = 'business5'
86
+ stub_request(:get, /Company\('#{test_company_name}'\)/)
87
+ .to_return(
88
+ status: 200,
89
+ body: {
90
+ etag: '113',
91
+ displayName: 'business5'
92
+ }.to_json
93
+ )
94
+
95
+ stub_request(:delete, /Company\('#{test_company_name}'\)/)
96
+ .to_return(status: 204)
97
+
98
+ assert @web_service.object("Company('?')", test_company_name).delete
99
+ end
100
+ end
@@ -1,4 +1,6 @@
1
- require "test_helper"
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
2
4
 
3
5
  class BusinessCentralTest < Minitest::Test
4
6
  def test_version_number_exists
data/test/test_helper.rb CHANGED
@@ -1,15 +1,21 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'simplecov'
2
4
  SimpleCov.start do
3
5
  add_filter '/test/'
4
6
  end
5
7
 
6
- $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
7
- require "business_central"
8
+ $LOAD_PATH.unshift File.expand_path('../lib', __dir__)
9
+ require 'business_central'
8
10
 
9
- require "minitest/autorun"
10
- require "minitest/mock"
11
+ require 'minitest/autorun'
12
+ require 'minitest/focus'
13
+ require 'minitest/mock'
14
+ require 'minitest/reporters'
11
15
 
12
- require "byebug"
16
+ require 'byebug'
13
17
  require 'webmock/minitest'
14
18
 
15
- WebMock.disable_net_connect!(allow_localhost: true)
19
+ WebMock.disable_net_connect!(allow_localhost: true)
20
+
21
+ Minitest::Reporters.use!