business-central 1.0.7 → 2.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.
Files changed (125) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +45 -32
  3. data/lib/business_central/client.rb +7 -53
  4. data/lib/business_central/exceptions.rb +11 -29
  5. data/lib/business_central/object/{attachment.rb → attachments.rb} +9 -11
  6. data/lib/business_central/object/base.rb +42 -114
  7. data/lib/business_central/object/companies.rb +19 -0
  8. data/lib/business_central/object/filter_query.rb +2 -0
  9. data/lib/business_central/object/object_helper.rb +9 -36
  10. data/lib/business_central/object/picture.rb +4 -40
  11. data/lib/business_central/object/request.rb +14 -15
  12. data/lib/business_central/object/response.rb +2 -0
  13. data/lib/business_central/object/url_builder.rb +16 -12
  14. data/lib/business_central/object/url_helper.rb +2 -0
  15. data/lib/business_central/version.rb +1 -1
  16. data/lib/business_central/web_service.rb +2 -0
  17. data/lib/business_central.rb +4 -56
  18. data/lib/refinements/strings.rb +42 -0
  19. data/test/business_central/client_test.rb +24 -0
  20. data/test/business_central/exceptions_test.rb +40 -0
  21. data/test/business_central/object/{attachment_test.rb → attachments_test.rb} +5 -6
  22. data/test/business_central/object/base_test.rb +59 -22
  23. data/test/business_central/object/{company_test.rb → companies_test.rb} +3 -21
  24. data/test/business_central/object/picture_test.rb +7 -16
  25. metadata +25 -155
  26. data/lib/business_central/object/account.rb +0 -13
  27. data/lib/business_central/object/aged_account_payable.rb +0 -13
  28. data/lib/business_central/object/aged_account_receivable.rb +0 -13
  29. data/lib/business_central/object/argument_helper.rb +0 -22
  30. data/lib/business_central/object/balance_sheet.rb +0 -13
  31. data/lib/business_central/object/cash_flow_statement.rb +0 -13
  32. data/lib/business_central/object/company.rb +0 -18
  33. data/lib/business_central/object/company_information.rb +0 -14
  34. data/lib/business_central/object/country_region.rb +0 -26
  35. data/lib/business_central/object/currency.rb +0 -29
  36. data/lib/business_central/object/customer.rb +0 -34
  37. data/lib/business_central/object/customer_financial_detail.rb +0 -13
  38. data/lib/business_central/object/customer_payment.rb +0 -43
  39. data/lib/business_central/object/customer_payment_journal.rb +0 -25
  40. data/lib/business_central/object/customer_sale.rb +0 -13
  41. data/lib/business_central/object/default_dimension.rb +0 -51
  42. data/lib/business_central/object/dimension.rb +0 -20
  43. data/lib/business_central/object/dimension_line.rb +0 -37
  44. data/lib/business_central/object/dimension_value.rb +0 -28
  45. data/lib/business_central/object/employee.rb +0 -21
  46. data/lib/business_central/object/general_ledger_entry.rb +0 -13
  47. data/lib/business_central/object/income_statement.rb +0 -13
  48. data/lib/business_central/object/irs1099_code.rb +0 -16
  49. data/lib/business_central/object/item.rb +0 -47
  50. data/lib/business_central/object/item_category.rb +0 -16
  51. data/lib/business_central/object/journal.rb +0 -29
  52. data/lib/business_central/object/journal_line.rb +0 -48
  53. data/lib/business_central/object/payment_method.rb +0 -16
  54. data/lib/business_central/object/payment_term.rb +0 -16
  55. data/lib/business_central/object/purchase_invoice.rb +0 -69
  56. data/lib/business_central/object/purchase_invoice_line.rb +0 -37
  57. data/lib/business_central/object/purchase_order.rb +0 -16
  58. data/lib/business_central/object/retained_earning_statement.rb +0 -13
  59. data/lib/business_central/object/sales_credit_memo.rb +0 -20
  60. data/lib/business_central/object/sales_credit_memo_line.rb +0 -30
  61. data/lib/business_central/object/sales_invoice.rb +0 -62
  62. data/lib/business_central/object/sales_invoice_line.rb +0 -30
  63. data/lib/business_central/object/sales_order.rb +0 -20
  64. data/lib/business_central/object/sales_order_line.rb +0 -30
  65. data/lib/business_central/object/sales_quote.rb +0 -20
  66. data/lib/business_central/object/sales_quote_line.rb +0 -30
  67. data/lib/business_central/object/shipment_method.rb +0 -16
  68. data/lib/business_central/object/subscription.rb +0 -16
  69. data/lib/business_central/object/tax_area.rb +0 -16
  70. data/lib/business_central/object/tax_group.rb +0 -16
  71. data/lib/business_central/object/time_registration_entry.rb +0 -16
  72. data/lib/business_central/object/trial_balance.rb +0 -13
  73. data/lib/business_central/object/units_of_measure.rb +0 -16
  74. data/lib/business_central/object/validation.rb +0 -57
  75. data/lib/business_central/object/vendor.rb +0 -42
  76. data/lib/business_central/object/vendor_purchase.rb +0 -13
  77. data/lib/core_ext/string.rb +0 -31
  78. data/test/business_central/object/account_test.rb +0 -67
  79. data/test/business_central/object/aged_account_payable_test.rb +0 -61
  80. data/test/business_central/object/aged_account_receivable_test.rb +0 -61
  81. data/test/business_central/object/balance_sheet_test.rb +0 -61
  82. data/test/business_central/object/cash_flow_statement_test.rb +0 -61
  83. data/test/business_central/object/company_information_test.rb +0 -81
  84. data/test/business_central/object/country_region_test.rb +0 -129
  85. data/test/business_central/object/currency_test.rb +0 -150
  86. data/test/business_central/object/customer_financial_detail_test.rb +0 -68
  87. data/test/business_central/object/customer_payment_journal_test.rb +0 -134
  88. data/test/business_central/object/customer_payment_test.rb +0 -141
  89. data/test/business_central/object/customer_sale_test.rb +0 -72
  90. data/test/business_central/object/customer_test.rb +0 -168
  91. data/test/business_central/object/default_dimension_test.rb +0 -170
  92. data/test/business_central/object/dimension_line_test.rb +0 -165
  93. data/test/business_central/object/dimension_test.rb +0 -65
  94. data/test/business_central/object/dimension_value_test.rb +0 -68
  95. data/test/business_central/object/employee_test.rb +0 -141
  96. data/test/business_central/object/general_ledger_entry_test.rb +0 -82
  97. data/test/business_central/object/income_statement_test.rb +0 -82
  98. data/test/business_central/object/irs1099_code_test.rb +0 -124
  99. data/test/business_central/object/item_category_test.rb +0 -122
  100. data/test/business_central/object/item_test.rb +0 -121
  101. data/test/business_central/object/journal_line_test.rb +0 -152
  102. data/test/business_central/object/journal_test.rb +0 -144
  103. data/test/business_central/object/payment_method_test.rb +0 -134
  104. data/test/business_central/object/payment_term_test.rb +0 -134
  105. data/test/business_central/object/purchase_invoice_line_test.rb +0 -123
  106. data/test/business_central/object/purchase_invoice_test.rb +0 -119
  107. data/test/business_central/object/retained_earning_statement_test.rb +0 -52
  108. data/test/business_central/object/sales_credit_memo_line_test.rb +0 -134
  109. data/test/business_central/object/sales_credit_memo_test.rb +0 -146
  110. data/test/business_central/object/sales_invoice_line_test.rb +0 -164
  111. data/test/business_central/object/sales_invoice_test.rb +0 -156
  112. data/test/business_central/object/sales_order_line_test.rb +0 -134
  113. data/test/business_central/object/sales_order_test.rb +0 -146
  114. data/test/business_central/object/sales_quote_line_test.rb +0 -134
  115. data/test/business_central/object/sales_quote_test.rb +0 -146
  116. data/test/business_central/object/shipment_method_test.rb +0 -133
  117. data/test/business_central/object/subscription_test.rb +0 -126
  118. data/test/business_central/object/tax_area_test.rb +0 -126
  119. data/test/business_central/object/tax_group_test.rb +0 -126
  120. data/test/business_central/object/time_registration_entry_test.rb +0 -126
  121. data/test/business_central/object/trial_balance_test.rb +0 -82
  122. data/test/business_central/object/units_of_measure_test.rb +0 -126
  123. data/test/business_central/object/validation_test.rb +0 -62
  124. data/test/business_central/object/vendor_purchase_test.rb +0 -82
  125. data/test/business_central/object/vendor_test.rb +0 -119
@@ -3,6 +3,8 @@
3
3
  module BusinessCentral
4
4
  module Object
5
5
  class Request
6
+ using Refinements::Strings
7
+
6
8
  class << self
7
9
  def get(client, url)
8
10
  request(:get, client, url)
@@ -66,23 +68,20 @@ module BusinessCentral
66
68
  response
67
69
  elsif Response.success_no_content?(request.code.to_i)
68
70
  true
69
- else
70
- if Response.unauthorized?(request.code.to_i)
71
- raise UnauthorizedException
72
- elsif Response.not_found?(request.code.to_i)
73
- raise NotFoundException
71
+ elsif Response.unauthorized?(request.code.to_i)
72
+ raise UnauthorizedException
73
+ elsif Response.not_found?(request.code.to_i)
74
+ raise NotFoundException
75
+ elsif !response.fetch(:error, nil).nil?
76
+ case response[:error][:code]
77
+ when 'Internal_CompanyNotFound'
78
+ raise CompanyNotFoundException
74
79
  else
75
- if !response.fetch(:error, nil).nil?
76
- case response[:error][:code]
77
- when 'Internal_CompanyNotFound'
78
- raise CompanyNotFoundException
79
- else
80
- raise ApiException, "#{request.code} - #{response[:error][:code]} #{response[:error][:message]}"
81
- end
82
- else
83
- raise ApiException, "#{request.code} - API call failed"
84
- end
80
+ raise ApiException,
81
+ "#{request.code} - #{response[:error][:code]} #{response[:error][:message]}"
85
82
  end
83
+ else
84
+ raise ApiException, "#{request.code} - API call failed"
86
85
  end
87
86
  end
88
87
  end
@@ -3,6 +3,8 @@
3
3
  module BusinessCentral
4
4
  module Object
5
5
  class Response
6
+ using Refinements::Strings
7
+
6
8
  class << self
7
9
  def success?(status)
8
10
  [200, 201].include?(status)
@@ -3,6 +3,8 @@
3
3
  module BusinessCentral
4
4
  module Object
5
5
  class URLBuilder
6
+ using Refinements::Strings
7
+
6
8
  extend URLHelper
7
9
 
8
10
  class << self
@@ -14,12 +16,11 @@ module BusinessCentral
14
16
  end
15
17
  end
16
18
 
17
- def initialize(base_url:, parent_path: [], child_path: '', child_id: '', child_code: '', filter: '')
19
+ def initialize(base_url:, object_path: [], object_id: '', object_code: '', filter: '')
18
20
  @base_url = base_url.to_s
19
- @parent_path = parent_path || []
20
- @child_path = child_path.to_s
21
- @child_id = child_id.to_s
22
- @child_code = child_code.to_s
21
+ @object_path = object_path || []
22
+ @object_id = object_id.to_s
23
+ @object_code = object_code.to_s
23
24
  @filter = filter.to_s
24
25
  end
25
26
 
@@ -34,18 +35,21 @@ module BusinessCentral
34
35
  private
35
36
 
36
37
  def build_parent_path
37
- return '' if @parent_path.empty?
38
-
39
- @parent_path.map do |parent|
40
- "/#{parent[:path]}(#{parent[:id]})" if !parent[:id].nil?
38
+ return '' if @object_path.empty?
39
+
40
+ @object_path.map do |parent|
41
+ if !parent[:id].nil?
42
+ "/#{parent[:path]}(#{parent[:id]})"
43
+ else
44
+ "/#{parent[:path]}"
45
+ end
41
46
  end.join('')
42
47
  end
43
48
 
44
49
  def build_child_path
45
50
  url = ''
46
- url += "/#{@child_path}" if @child_path.present?
47
- url += "(#{@child_id})" if @child_id.present?
48
- url += "('#{odata_encode(@child_code)}')" if @child_code.present?
51
+ url += "(#{@object_id})" if @object_id.present?
52
+ url += "('#{odata_encode(@object_code)}')" if @object_code.present?
49
53
  url
50
54
  end
51
55
 
@@ -3,6 +3,8 @@
3
3
  module BusinessCentral
4
4
  module Object
5
5
  module URLHelper
6
+ using Refinements::Strings
7
+
6
8
  def encode_url_object(object)
7
9
  URI::RFC2396_Parser.new.escape(object)
8
10
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BusinessCentral
4
- VERSION = '1.0.7'
4
+ VERSION = '2.0.0'
5
5
  end
@@ -2,6 +2,8 @@
2
2
 
3
3
  module BusinessCentral
4
4
  class WebService
5
+ using Refinements::Strings
6
+
5
7
  DEFAULT_URL = 'https://api.businesscentral.dynamics.com/v2.0/production/ODataV4'
6
8
 
7
9
  attr_reader :url, :object_url
@@ -3,70 +3,18 @@ require 'oauth2/error'
3
3
  require 'net/http'
4
4
  require 'json'
5
5
 
6
- require 'core_ext/string'
6
+ require 'refinements/strings'
7
7
 
8
- require 'business_central/object/argument_helper'
9
8
  require 'business_central/object/url_helper'
10
9
  require 'business_central/object/object_helper'
11
-
12
- require 'business_central/object/base'
13
- require 'business_central/object/validation'
14
10
  require 'business_central/object/response'
15
11
  require 'business_central/object/request'
16
12
  require 'business_central/object/filter_query'
17
13
  require 'business_central/object/url_builder'
18
-
19
- require 'business_central/object/account'
20
- require 'business_central/object/aged_account_payable'
21
- require 'business_central/object/aged_account_receivable'
22
- require 'business_central/object/attachment'
23
- require 'business_central/object/cash_flow_statement'
24
- require 'business_central/object/balance_sheet'
25
- require 'business_central/object/company'
26
- require 'business_central/object/company_information'
27
- require 'business_central/object/country_region'
28
- require 'business_central/object/currency'
29
- require 'business_central/object/customer'
30
- require 'business_central/object/customer_financial_detail'
31
- require 'business_central/object/customer_payment'
32
- require 'business_central/object/customer_payment_journal'
33
- require 'business_central/object/customer_sale'
34
- require 'business_central/object/default_dimension'
35
- require 'business_central/object/dimension'
36
- require 'business_central/object/dimension_line'
37
- require 'business_central/object/dimension_value'
38
- require 'business_central/object/employee'
39
- require 'business_central/object/general_ledger_entry'
40
- require 'business_central/object/income_statement'
41
- require 'business_central/object/irs1099_code'
42
- require 'business_central/object/item'
43
- require 'business_central/object/item_category'
44
- require 'business_central/object/journal'
45
- require 'business_central/object/journal_line'
46
- require 'business_central/object/payment_method'
47
- require 'business_central/object/payment_term'
14
+ require 'business_central/object/base'
15
+ require 'business_central/object/companies'
48
16
  require 'business_central/object/picture'
49
- require 'business_central/object/purchase_invoice'
50
- require 'business_central/object/purchase_invoice_line'
51
- require 'business_central/object/retained_earning_statement'
52
- require 'business_central/object/sales_invoice'
53
- require 'business_central/object/sales_invoice_line'
54
- require 'business_central/object/sales_credit_memo'
55
- require 'business_central/object/sales_credit_memo_line'
56
- require 'business_central/object/sales_order'
57
- require 'business_central/object/sales_order_line'
58
- require 'business_central/object/sales_quote'
59
- require 'business_central/object/sales_quote_line'
60
- require 'business_central/object/shipment_method'
61
- require 'business_central/object/subscription'
62
- require 'business_central/object/tax_area'
63
- require 'business_central/object/tax_group'
64
- require 'business_central/object/time_registration_entry'
65
- require 'business_central/object/trial_balance'
66
- require 'business_central/object/units_of_measure'
67
- require 'business_central/object/vendor'
68
- require 'business_central/object/vendor_purchase'
69
- require 'business_central/object/purchase_order'
17
+ require 'business_central/object/attachments'
70
18
 
71
19
  require 'business_central/exceptions'
72
20
  require 'business_central/client'
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Refinements
4
+ module Strings
5
+ refine String do
6
+ def blank?
7
+ empty? || /\A[[:space:]]*\z/.match?(self)
8
+ end
9
+
10
+ def present?
11
+ !blank?
12
+ end
13
+
14
+ # Convert string to CamelCase
15
+ def to_camel_case(uppercase_first_letter = false)
16
+ string = self
17
+ string = if uppercase_first_letter
18
+ string.sub(/^[a-z\d]*/, &:capitalize)
19
+ else
20
+ string.sub(/^(?:(?=\b|[A-Z_])|\w)/, &:downcase)
21
+ end
22
+ string.gsub(%r{(?:_|(/))([a-z\d]*)}) do
23
+ "#{Regexp.last_match(1)}#{Regexp.last_match(2).capitalize}"
24
+ end.gsub('/', '::')
25
+ end
26
+
27
+ # Convert string to snake_case
28
+ def to_snake_case
29
+ gsub(/::/, '/')
30
+ .gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2')
31
+ .gsub(/([a-z\d])([A-Z])/, '\1_\2')
32
+ .tr('-', '_')
33
+ .downcase
34
+ end
35
+
36
+ # Convert to class symbol
37
+ def to_class_sym
38
+ to_camel_case(true).to_s.to_sym
39
+ end
40
+ end
41
+ end
42
+ end
@@ -112,6 +112,30 @@ class BusinessCentral::ClientTest < Minitest::Test
112
112
  end
113
113
  end
114
114
 
115
+ def test_refresh_token_throws_invalid_grant_exception
116
+ @client.authorize_from_token(
117
+ token: '123',
118
+ refresh_token: '456',
119
+ expires_at: Time.now + 3600,
120
+ expires_in: 3600
121
+ )
122
+ stub_request(:post, /#{BusinessCentral::Client::DEFAULT_LOGIN_URL}/)
123
+ .to_return(
124
+ status: 200,
125
+ headers: {
126
+ 'Content-Type': 'application/json'
127
+ },
128
+ body: {
129
+ error: 'invalid_grant',
130
+ error_description: 'Invalid grant was because it was invalid'
131
+ }.to_json
132
+ )
133
+
134
+ assert_raises(BusinessCentral::InvalidGrantException) do
135
+ @client.refresh_token
136
+ end
137
+ end
138
+
115
139
  def test_build_web_service_object
116
140
  @client.web_service.object('Company/Vendors')
117
141
  assert_equal @client.web_service.object_url, 'Company/Vendors'
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+ # rake test TEST=test/business_central/exceptions_test.rb
5
+
6
+ class BusinessCentral::ExceptionsTest < Minitest::Test
7
+ def test_invalid_client_exception
8
+ exception = BusinessCentral::InvalidClientException.new
9
+ assert_equal('Invalid client setup', exception.message)
10
+ end
11
+
12
+ def test_company_not_found_exception
13
+ exception = BusinessCentral::CompanyNotFoundException.new
14
+ assert_equal('Company not found', exception.message)
15
+ end
16
+
17
+ def test_unathorized_exception
18
+ exception = BusinessCentral::UnauthorizedException.new
19
+ assert_equal('Unauthorized - The credentials provided are incorrect', exception.message)
20
+ end
21
+
22
+ def test_not_found_exception
23
+ exception = BusinessCentral::NotFoundException.new
24
+ assert_equal('Not Found - The URL provided cannot be found', exception.message)
25
+ end
26
+
27
+ def test_invalid_object_url_exception
28
+ exception = BusinessCentral::InvalidObjectURLException.new
29
+ assert_equal('Object URL missing for request', exception.message)
30
+ end
31
+
32
+ def test_invalid_grant_exception
33
+ exception = BusinessCentral::InvalidGrantException.new('Extra error details')
34
+ assert_equal(
35
+ 'The provided grant has expired due to it being revoked, a fresh auth token is needed',
36
+ exception.message
37
+ )
38
+ assert_equal('Extra error details', exception.error_message)
39
+ end
40
+ end
@@ -1,13 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
- # rake test TEST=test/business_central/object/attachment_test.rb
4
+ # rake test TEST=test/business_central/object/attachments_test.rb
5
5
 
6
- class BusinessCentral::Object::AttachmentTest < Minitest::Test
6
+ class BusinessCentral::Object::AttachmentsTest < Minitest::Test
7
7
  def setup
8
8
  @company_id = '123456'
9
9
  @client = BusinessCentral::Client.new
10
- @attachment = @client.attachment(company_id: @company_id)
10
+ @attachment = @client.attachments(company_id: @company_id)
11
11
  end
12
12
 
13
13
  def test_find_all
@@ -106,12 +106,11 @@ class BusinessCentral::Object::AttachmentTest < Minitest::Test
106
106
  end
107
107
 
108
108
  def test_delete
109
- test_parent_id = '011124'
110
109
  test_attachment_id = '11124'
111
110
 
112
- stub_request(:delete, /attachments\(#{test_parent_id},#{test_attachment_id}\)/)
111
+ stub_request(:delete, /attachments\(#{test_attachment_id}\)/)
113
112
  .to_return(status: 204)
114
113
 
115
- assert @attachment.destroy(parent_id: test_parent_id, attachment_id: test_attachment_id)
114
+ assert @attachment.destroy(test_attachment_id)
116
115
  end
117
116
  end
@@ -6,36 +6,73 @@ require 'test_helper'
6
6
  class BusinessCentral::Object::BaseTest < Minitest::Test
7
7
  def setup
8
8
  @company_id = '123456'
9
- @client = BusinessCentral::Client.new
9
+ @client = BusinessCentral::Client.new(
10
+ default_company_id: @company_id
11
+ )
10
12
  end
11
13
 
12
- def test_no_method_supported_for_find_all
13
- base = BusinessCentral::Object::Base.new(@client, {})
14
- set_object_method(base, [])
15
- assert_raises(BusinessCentral::NoSupportedMethod) do
16
- base.find_all
17
- end
14
+ def test_client_responds_to_any_method_object
15
+ assert(@client.respond_to?(:random_object_that_does_not_exist))
18
16
  end
19
17
 
20
- def test_no_method_supported_for_find_by_id
21
- base = BusinessCentral::Object::Base.new(@client, {})
22
- set_object_method(base, [])
23
- assert_raises(BusinessCentral::NoSupportedMethod) do
24
- base.find_by_id('123')
25
- end
18
+ def test_respond_to_chaining_objects
19
+ assert(@client.vendors.respond_to?(:random_object_that_does_not_exist))
26
20
  end
27
21
 
28
- def test_no_method_supported_for_where_query
29
- base = BusinessCentral::Object::Base.new(@client, {})
30
- set_object_method(base, [])
31
- assert_raises(BusinessCentral::NoSupportedMethod) do
32
- base.where("displayName eq '123'")
33
- end
22
+ def test_find_all_for_vendor_object
23
+ stub_request(:get, %r{companies\(#{@company_id}\)/vendors})
24
+ .to_return(
25
+ status: 200,
26
+ body: {
27
+ 'value': [
28
+ {
29
+ displayName: 'vendor1'
30
+ }
31
+ ]
32
+ }.to_json
33
+ )
34
+
35
+ response = @client.vendors.find_all
36
+ assert_equal response.first[:display_name], 'vendor1'
34
37
  end
35
38
 
36
- private
39
+ def test_find_all_for_vendors_default_dimensions
40
+ stub_request(:get, %r{companies\(#{@company_id}\)/vendors\(1\)/defaultDimensions})
41
+ .to_return(
42
+ status: 200,
43
+ body: {
44
+ 'value': [
45
+ {
46
+ dimensionValueCode: 'SALES'
47
+ }
48
+ ]
49
+ }.to_json
50
+ )
51
+
52
+ response = @client.vendors(id: 1).default_dimensions.find_all
53
+ assert_equal response.first[:dimension_value_code], 'SALES'
54
+ end
55
+
56
+ def test_update_vendor_object
57
+ test_id = 1
58
+ stub_request(:get, %r{companies\(#{@company_id}\)/vendors\(#{test_id}\)})
59
+ .to_return(
60
+ status: 200,
61
+ body: {
62
+ etag: '111',
63
+ displayName: 'vendor1'
64
+ }.to_json
65
+ )
66
+
67
+ stub_request(:patch, %r{companies\(#{@company_id}\)/vendors\(#{test_id}\)})
68
+ .to_return(
69
+ status: 200,
70
+ body: {
71
+ displayName: 'vendor2'
72
+ }.to_json
73
+ )
37
74
 
38
- def set_object_method(base, value)
39
- base.class.const_set('OBJECT_METHODS', value) if !base.class.const_defined?('OBJECT_METHODS')
75
+ response = @client.vendors.update(test_id, { display_name: 'vendor2' })
76
+ assert_equal response[:display_name], 'vendor2'
40
77
  end
41
78
  end
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'test_helper'
4
- # rake test TEST=test/business_central/object/company_test.rb
4
+ # rake test TEST=test/business_central/object/companies_test.rb
5
5
 
6
- class BusinessCentral::Object::CompanyTest < Minitest::Test
6
+ class BusinessCentral::Object::CompaniesTest < Minitest::Test
7
7
  def setup
8
8
  @client = BusinessCentral::Client.new
9
- @company = @client.company
9
+ @company = @client.companies
10
10
  end
11
11
 
12
12
  def test_find_all
@@ -39,22 +39,4 @@ class BusinessCentral::Object::CompanyTest < Minitest::Test
39
39
  response = @company.find_by_id(test_company_id)
40
40
  assert_equal response[:display_name], 'business2'
41
41
  end
42
-
43
- def test_create
44
- assert_raises BusinessCentral::NoSupportedMethod do
45
- @company.create({})
46
- end
47
- end
48
-
49
- def test_update
50
- assert_raises BusinessCentral::NoSupportedMethod do
51
- @company.update('123', {})
52
- end
53
- end
54
-
55
- def test_delete
56
- assert_raises BusinessCentral::NoSupportedMethod do
57
- @company.destroy('123')
58
- end
59
- end
60
42
  end
@@ -7,11 +7,11 @@ class BusinessCentral::Object::PictureTest < Minitest::Test
7
7
  def setup
8
8
  @company_id = '123456'
9
9
  @client = BusinessCentral::Client.new
10
- @picture = @client.picture(parent: 'vendors', parent_id: '123', company_id: @company_id)
10
+ @picture = @client.items(id: 123, company_id: @company_id).picture
11
11
  end
12
12
 
13
13
  def test_find_all
14
- stub_request(:get, /picture/)
14
+ stub_request(:get, %r{companies\(#{@company_id}\)/items\(123\)/picture})
15
15
  .to_return(
16
16
  status: 200,
17
17
  body: {
@@ -25,21 +25,12 @@ class BusinessCentral::Object::PictureTest < Minitest::Test
25
25
  ]
26
26
  }.to_json
27
27
  )
28
-
29
28
  response = @picture.find_all
30
29
  assert_equal response.first[:content_type], 'image\jpeg'
31
30
  end
32
31
 
33
- def test_create
34
- stub_request(:patch, /picture/)
35
- .to_return(status: 204)
36
-
37
- response = @picture.create('ImageData')
38
- assert response
39
- end
40
-
41
32
  def test_update
42
- stub_request(:get, /picture/)
33
+ stub_request(:get, %r{companies\(#{@company_id}\)/items\(123\)/picture})
43
34
  .to_return(
44
35
  status: 200,
45
36
  body: {
@@ -48,16 +39,16 @@ class BusinessCentral::Object::PictureTest < Minitest::Test
48
39
  }.to_json
49
40
  )
50
41
 
51
- stub_request(:patch, /picture/)
42
+ stub_request(:patch, %r{companies\(#{@company_id}\)/items\(123\)/picture\(1\)/content})
52
43
  .to_return(status: 204)
53
44
 
54
- response = @picture.update('ImageData')
45
+ response = @picture.update(1, 'ImageData')
55
46
  assert response
56
47
  end
57
48
 
58
49
  def test_delete
59
50
  test_id = 2
60
- stub_request(:get, /picture/)
51
+ stub_request(:get, %r{companies\(#{@company_id}\)/items\(123\)/picture\(#{test_id}\)})
61
52
  .to_return(
62
53
  status: 200,
63
54
  body: {
@@ -66,7 +57,7 @@ class BusinessCentral::Object::PictureTest < Minitest::Test
66
57
  }.to_json
67
58
  )
68
59
 
69
- stub_request(:delete, /picture/)
60
+ stub_request(:delete, %r{companies\(#{@company_id}\)/items\(123\)/picture\(#{test_id}\)})
70
61
  .to_return(status: 204)
71
62
 
72
63
  assert @picture.destroy(test_id)