business-central 1.0.1 → 1.0.6

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.rb +47 -2
  4. data/lib/business_central/client.rb +82 -39
  5. data/lib/business_central/exceptions.rb +30 -10
  6. data/lib/business_central/object/account.rb +4 -12
  7. data/lib/business_central/object/aged_account_payable.rb +4 -12
  8. data/lib/business_central/object/aged_account_receivable.rb +4 -12
  9. data/lib/business_central/object/argument_helper.rb +22 -0
  10. data/lib/business_central/object/attachment.rb +30 -0
  11. data/lib/business_central/object/balance_sheet.rb +4 -12
  12. data/lib/business_central/object/base.rb +100 -49
  13. data/lib/business_central/object/cash_flow_statement.rb +4 -12
  14. data/lib/business_central/object/company.rb +9 -2
  15. data/lib/business_central/object/company_information.rb +7 -15
  16. data/lib/business_central/object/country_region.rb +26 -0
  17. data/lib/business_central/object/currency.rb +29 -0
  18. data/lib/business_central/object/customer.rb +34 -0
  19. data/lib/business_central/object/customer_financial_detail.rb +13 -0
  20. data/lib/business_central/object/customer_payment.rb +43 -0
  21. data/lib/business_central/object/customer_payment_journal.rb +25 -0
  22. data/lib/business_central/object/customer_sale.rb +13 -0
  23. data/lib/business_central/object/default_dimension.rb +51 -0
  24. data/lib/business_central/object/dimension.rb +20 -0
  25. data/lib/business_central/object/dimension_line.rb +37 -0
  26. data/lib/business_central/object/dimension_value.rb +28 -0
  27. data/lib/business_central/object/employee.rb +21 -0
  28. data/lib/business_central/object/filter_query.rb +18 -0
  29. data/lib/business_central/object/general_ledger_entry.rb +13 -0
  30. data/lib/business_central/object/income_statement.rb +13 -0
  31. data/lib/business_central/object/irs1099_code.rb +16 -0
  32. data/lib/business_central/object/item.rb +16 -19
  33. data/lib/business_central/object/item_category.rb +16 -0
  34. data/lib/business_central/object/journal.rb +29 -0
  35. data/lib/business_central/object/journal_line.rb +48 -0
  36. data/lib/business_central/object/object_helper.rb +49 -0
  37. data/lib/business_central/object/payment_method.rb +16 -0
  38. data/lib/business_central/object/payment_term.rb +16 -0
  39. data/lib/business_central/object/picture.rb +53 -0
  40. data/lib/business_central/object/purchase_invoice.rb +8 -16
  41. data/lib/business_central/object/purchase_invoice_line.rb +14 -18
  42. data/lib/business_central/object/request.rb +61 -50
  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 +12 -15
  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/core_ext/string.rb +18 -12
  68. data/test/business_central/client_test.rb +49 -7
  69. data/test/business_central/object/account_test.rb +6 -5
  70. data/test/business_central/object/aged_account_payable_test.rb +6 -5
  71. data/test/business_central/object/aged_account_receivable_test.rb +6 -5
  72. data/test/business_central/object/attachment_test.rb +117 -0
  73. data/test/business_central/object/balance_sheet_test.rb +6 -5
  74. data/test/business_central/object/base_test.rb +41 -0
  75. data/test/business_central/object/cash_flow_statement_test.rb +6 -5
  76. data/test/business_central/object/company_information_test.rb +9 -10
  77. data/test/business_central/object/company_test.rb +6 -5
  78. data/test/business_central/object/country_region_test.rb +129 -0
  79. data/test/business_central/object/currency_test.rb +150 -0
  80. data/test/business_central/object/customer_financial_detail_test.rb +68 -0
  81. data/test/business_central/object/customer_payment_journal_test.rb +134 -0
  82. data/test/business_central/object/customer_payment_test.rb +141 -0
  83. data/test/business_central/object/customer_sale_test.rb +72 -0
  84. data/test/business_central/object/customer_test.rb +168 -0
  85. data/test/business_central/object/default_dimension_test.rb +170 -0
  86. data/test/business_central/object/dimension_line_test.rb +165 -0
  87. data/test/business_central/object/dimension_test.rb +65 -0
  88. data/test/business_central/object/dimension_value_test.rb +68 -0
  89. data/test/business_central/object/employee_test.rb +141 -0
  90. data/test/business_central/object/filter_query_test.rb +36 -0
  91. data/test/business_central/object/general_ledger_entry_test.rb +82 -0
  92. data/test/business_central/object/income_statement_test.rb +82 -0
  93. data/test/business_central/object/irs1099_code_test.rb +124 -0
  94. data/test/business_central/object/item_category_test.rb +122 -0
  95. data/test/business_central/object/item_test.rb +16 -17
  96. data/test/business_central/object/journal_line_test.rb +152 -0
  97. data/test/business_central/object/journal_test.rb +144 -0
  98. data/test/business_central/object/payment_method_test.rb +134 -0
  99. data/test/business_central/object/payment_term_test.rb +134 -0
  100. data/test/business_central/object/picture_test.rb +74 -0
  101. data/test/business_central/object/purchase_invoice_line_test.rb +15 -15
  102. data/test/business_central/object/purchase_invoice_test.rb +15 -15
  103. data/test/business_central/object/request_test.rb +75 -12
  104. data/test/business_central/object/response_test.rb +34 -9
  105. data/test/business_central/object/retained_earning_statement_test.rb +52 -0
  106. data/test/business_central/object/sales_credit_memo_line_test.rb +134 -0
  107. data/test/business_central/object/sales_credit_memo_test.rb +146 -0
  108. data/test/business_central/object/sales_invoice_line_test.rb +164 -0
  109. data/test/business_central/object/sales_invoice_test.rb +156 -0
  110. data/test/business_central/object/sales_order_line_test.rb +134 -0
  111. data/test/business_central/object/sales_order_test.rb +146 -0
  112. data/test/business_central/object/sales_quote_line_test.rb +134 -0
  113. data/test/business_central/object/sales_quote_test.rb +146 -0
  114. data/test/business_central/object/shipment_method_test.rb +133 -0
  115. data/test/business_central/object/subscription_test.rb +126 -0
  116. data/test/business_central/object/tax_area_test.rb +126 -0
  117. data/test/business_central/object/tax_group_test.rb +126 -0
  118. data/test/business_central/object/time_registration_entry_test.rb +126 -0
  119. data/test/business_central/object/trial_balance_test.rb +82 -0
  120. data/test/business_central/object/units_of_measure_test.rb +126 -0
  121. data/test/business_central/object/validation_test.rb +5 -4
  122. data/test/business_central/object/vendor_purchase_test.rb +82 -0
  123. data/test/business_central/object/vendor_test.rb +16 -16
  124. data/test/business_central/web_service_test.rb +100 -0
  125. data/test/business_central_test.rb +3 -1
  126. data/test/test_helper.rb +16 -6
  127. metadata +188 -37
  128. data/lib/business_central/object/helper.rb +0 -15
@@ -0,0 +1,165 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+ # rake test TEST=test/business_central/object/dimension_line_test.rb
5
+
6
+ class BusinessCentral::Object::DimensionLineTest < Minitest::Test
7
+ def setup
8
+ @company_id = '123456'
9
+ @client = BusinessCentral::Client.new
10
+ @dimension_line = @client.dimension_line(
11
+ company_id: @company_id
12
+ )
13
+ end
14
+
15
+ def test_find_all
16
+ stub_request(:get, /dimensionLines/)
17
+ .to_return(
18
+ status: 200,
19
+ body: {
20
+ 'value': [
21
+ {
22
+ parent_id: 1,
23
+ id: '123',
24
+ code: '456',
25
+ displayName: 'dimension line 1',
26
+ valueId: 1,
27
+ valueCode: 'ABC',
28
+ valueDisplayName: 'DEF'
29
+ }
30
+ ]
31
+ }.to_json
32
+ )
33
+
34
+ response = @dimension_line.find_all
35
+ assert_equal response.first[:display_name], 'dimension line 1'
36
+ end
37
+
38
+ def test_find_by_id
39
+ test_id = '2'
40
+ stub_request(:get, /dimensionLines\(#{test_id}\)/)
41
+ .to_return(
42
+ status: 200,
43
+ body: {
44
+ parent_id: 2,
45
+ id: test_id,
46
+ code: '789',
47
+ displayName: 'dimension line 2',
48
+ valueId: 2,
49
+ valueCode: 'DEF',
50
+ valueDisplayName: 'GHI'
51
+ }.to_json
52
+ )
53
+
54
+ response = @dimension_line.find_by_id(test_id)
55
+ assert_equal response[:display_name], 'dimension line 2'
56
+ end
57
+
58
+ def test_where
59
+ test_filter = "displayName eq 'dimension line 3'"
60
+ stub_request(:get, /dimensionLines\?\$filter=#{test_filter}/)
61
+ .to_return(
62
+ status: 200,
63
+ body: {
64
+ 'value': [
65
+ {
66
+ parent_id: 3,
67
+ id: '456',
68
+ code: '789',
69
+ displayName: 'dimension line 3',
70
+ valueId: 3,
71
+ valueCode: 'GHI',
72
+ valueDisplayName: 'JKL'
73
+ }
74
+ ]
75
+ }.to_json
76
+ )
77
+
78
+ response = @dimension_line.where(test_filter)
79
+ assert_equal response.first[:display_name], 'dimension line 3'
80
+ end
81
+
82
+ def test_create
83
+ stub_request(:post, /dimensionLines/)
84
+ .to_return(
85
+ status: 200,
86
+ body: {
87
+ parent_id: 4,
88
+ code: '1011',
89
+ displayName: 'dimension line 4',
90
+ valueId: 4,
91
+ valueCode: 'MNO',
92
+ valueDisplayName: 'PQR'
93
+ }.to_json
94
+ )
95
+
96
+ response = @dimension_line.create(
97
+ parent_id: 4,
98
+ value_id: 4
99
+ )
100
+ assert_equal response[:parent_id], 4
101
+ end
102
+
103
+ def test_update
104
+ test_id = '2'
105
+ stub_request(:get, /dimensionLines\(#{test_id}\)/)
106
+ .to_return(
107
+ status: 200,
108
+ body: {
109
+ etag: '1111',
110
+ parent_id: 5,
111
+ id: 5,
112
+ code: '1011',
113
+ displayName: 'dimension line 4',
114
+ valueId: 4,
115
+ valueCode: 'MNO',
116
+ valueDisplayName: 'PQR'
117
+ }.to_json
118
+ )
119
+
120
+ stub_request(:patch, /dimensionLines\(#{test_id}\)/)
121
+ .to_return(
122
+ status: 200,
123
+ body: {
124
+ etag: '2222',
125
+ parent_id: 5,
126
+ id: 5,
127
+ code: '1011',
128
+ displayName: 'dimension line 5',
129
+ valueId: 5,
130
+ valueCode: 'MNO',
131
+ valueDisplayName: 'PQR'
132
+ }.to_json
133
+ )
134
+
135
+ response = @dimension_line.update(
136
+ test_id,
137
+ display_name: 'dimension line 5',
138
+ value_id: 5
139
+ )
140
+ assert_equal response[:display_name], 'dimension line 5'
141
+ end
142
+
143
+ def test_delete
144
+ test_id = '33333'
145
+ stub_request(:get, /dimensionLines\(#{test_id}\)/)
146
+ .to_return(
147
+ status: 200,
148
+ body: {
149
+ etag: '5555',
150
+ parent_id: 6,
151
+ id: '33333',
152
+ code: '1011',
153
+ displayName: 'dimension line 6',
154
+ valueId: 6,
155
+ valueCode: 'MNO',
156
+ valueDisplayName: 'PQR'
157
+ }.to_json
158
+ )
159
+
160
+ stub_request(:delete, /dimensionLines\(#{test_id}\)/)
161
+ .to_return(status: 204)
162
+
163
+ assert @dimension_line.destroy(test_id)
164
+ end
165
+ end
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+ # rake test TEST=test/business_central/object/dimension_test.rb
5
+
6
+ class BusinessCentral::Object::DimensionTest < Minitest::Test
7
+ def setup
8
+ @company_id = '123456'
9
+ @client = BusinessCentral::Client.new
10
+ @dimension = @client.dimension(company_id: @company_id)
11
+ end
12
+
13
+ def test_find_all
14
+ stub_request(:get, /dimensions/)
15
+ .to_return(
16
+ status: 200,
17
+ body: {
18
+ 'value': [
19
+ {
20
+ id: '123',
21
+ code: '456',
22
+ displayName: 'Dimension1'
23
+ }
24
+ ]
25
+ }.to_json
26
+ )
27
+
28
+ response = @dimension.find_all
29
+ assert_equal response.first[:display_name], 'Dimension1'
30
+ end
31
+
32
+ def test_find_by_id
33
+ test_id = '123'
34
+ stub_request(:get, /dimensions\(#{test_id}\)/)
35
+ .to_return(
36
+ status: 200,
37
+ body: {
38
+ id: '123',
39
+ code: '456',
40
+ displayName: 'Dimension2'
41
+ }.to_json
42
+ )
43
+
44
+ response = @dimension.find_by_id(test_id)
45
+ assert_equal response[:display_name], 'Dimension2'
46
+ end
47
+
48
+ def test_create
49
+ assert_raises BusinessCentral::NoSupportedMethod do
50
+ @dimension.create({})
51
+ end
52
+ end
53
+
54
+ def test_update
55
+ assert_raises BusinessCentral::NoSupportedMethod do
56
+ @dimension.update('123', {})
57
+ end
58
+ end
59
+
60
+ def test_delete
61
+ assert_raises BusinessCentral::NoSupportedMethod do
62
+ @dimension.destroy('123')
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+ # rake test TEST=test/business_central/object/dimension_value_test.rb
5
+
6
+ class BusinessCentral::Object::DimensionValueTest < Minitest::Test
7
+ def setup
8
+ @company_id = '123456'
9
+ @client = BusinessCentral::Client.new
10
+ @dimension_value = @client.dimension_value(
11
+ company_id: @company_id,
12
+ dimension_id: '123456'
13
+ )
14
+ end
15
+
16
+ def test_find_all
17
+ stub_request(:get, /dimensionValues/)
18
+ .to_return(
19
+ status: 200,
20
+ body: {
21
+ 'value': [
22
+ {
23
+ id: '123',
24
+ code: '456',
25
+ displayName: 'dimension value 1'
26
+ }
27
+ ]
28
+ }.to_json
29
+ )
30
+
31
+ response = @dimension_value.find_all
32
+ assert_equal response.first[:display_name], 'dimension value 1'
33
+ end
34
+
35
+ def test_find_by_id
36
+ test_id = '123'
37
+ stub_request(:get, /dimensionValues\(#{test_id}\)/)
38
+ .to_return(
39
+ status: 200,
40
+ body: {
41
+ id: '123',
42
+ code: '456',
43
+ displayName: 'dimension value 2'
44
+ }.to_json
45
+ )
46
+
47
+ response = @dimension_value.find_by_id(test_id)
48
+ assert_equal response[:display_name], 'dimension value 2'
49
+ end
50
+
51
+ def test_create
52
+ assert_raises BusinessCentral::NoSupportedMethod do
53
+ @dimension_value.create({})
54
+ end
55
+ end
56
+
57
+ def test_update
58
+ assert_raises BusinessCentral::NoSupportedMethod do
59
+ @dimension_value.update('123', {})
60
+ end
61
+ end
62
+
63
+ def test_delete
64
+ assert_raises BusinessCentral::NoSupportedMethod do
65
+ @dimension_value.destroy('123')
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,141 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+ # rake test TEST=test/business_central/object/employee_test.rb
5
+
6
+ class BusinessCentral::Object::EmployeeTest < Minitest::Test
7
+ def setup
8
+ @company_id = '123456'
9
+ @client = BusinessCentral::Client.new
10
+ @employee = @client.employee(company_id: @company_id)
11
+ end
12
+
13
+ def test_find_all
14
+ stub_request(:get, %r{/employees})
15
+ .to_return(
16
+ status: 200,
17
+ body: {
18
+ 'value': [
19
+ {
20
+ displayName: 'employee1'
21
+ }
22
+ ]
23
+ }.to_json
24
+ )
25
+
26
+ response = @employee.find_all
27
+ assert_equal response.first[:display_name], 'employee1'
28
+ end
29
+
30
+ def test_find_by_id
31
+ test_id = '09876'
32
+ stub_request(:get, /employees\(#{test_id}\)/)
33
+ .to_return(
34
+ status: 200,
35
+ body: {
36
+ id: test_id,
37
+ displayName: 'employee2'
38
+ }.to_json
39
+ )
40
+
41
+ response = @employee.find_by_id(test_id)
42
+ assert_equal response[:display_name], 'employee2'
43
+ end
44
+
45
+ def test_where
46
+ test_filter = "displayName eq 'employee3'"
47
+ stub_request(:get, /employees\?\$filter=#{test_filter}/)
48
+ .to_return(
49
+ status: 200,
50
+ body: {
51
+ 'value': [
52
+ {
53
+ displayName: 'employee3'
54
+ }
55
+ ]
56
+ }.to_json
57
+ )
58
+
59
+ response = @employee.where(test_filter)
60
+ assert_equal response.first[:display_name], 'employee3'
61
+ end
62
+
63
+ def test_create
64
+ stub_request(:post, /employees/)
65
+ .to_return(
66
+ status: 200,
67
+ body: {
68
+ displayName: 'employee4'
69
+ }.to_json
70
+ )
71
+
72
+ response = @employee.create(
73
+ display_name: 'employee4'
74
+ )
75
+ assert_equal response[:display_name], 'employee4'
76
+ end
77
+
78
+ def test_update
79
+ test_id = '011123'
80
+ stub_request(:get, /employees\(#{test_id}\)/)
81
+ .to_return(
82
+ status: 200,
83
+ body: {
84
+ etag: '112',
85
+ id: test_id,
86
+ displayName: 'employee5'
87
+ }.to_json
88
+ )
89
+
90
+ stub_request(:patch, /employees\(#{test_id}\)/)
91
+ .to_return(
92
+ status: 200,
93
+ body: {
94
+ etag: '112',
95
+ id: test_id,
96
+ displayName: 'employee6'
97
+ }.to_json
98
+ )
99
+
100
+ response = @employee.update(
101
+ test_id,
102
+ display_name: 'employee6'
103
+ )
104
+ assert_equal response[:display_name], 'employee6'
105
+ end
106
+
107
+ def test_delete
108
+ test_id = '0111245'
109
+ stub_request(:get, /employees\(#{test_id}\)/)
110
+ .to_return(
111
+ status: 200,
112
+ body: {
113
+ etag: '113',
114
+ displayName: 'employee7'
115
+ }.to_json
116
+ )
117
+
118
+ stub_request(:delete, /employees\(#{test_id}\)/)
119
+ .to_return(status: 204)
120
+
121
+ assert @employee.destroy(test_id)
122
+ end
123
+
124
+ def test_default_dimension_navigation
125
+ stub_request(:get, /defaultDimensions/)
126
+ .to_return(
127
+ status: 200,
128
+ body: {
129
+ 'value': [
130
+ {
131
+ id: 1,
132
+ parentId: '123',
133
+ }
134
+ ]
135
+ }.to_json
136
+ )
137
+
138
+ response = @client.employee(company_id: @company_id, id: '123').default_dimension.find_all
139
+ assert_equal response.first[:parent_id], '123'
140
+ end
141
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+ # rake test TEST=test/business_central/object/filter_query_test.rb
5
+
6
+ class BusinessCentral::Object::FilterQueryTest < Minitest::Test
7
+ def setup
8
+ @filter_query = BusinessCentral::Object::FilterQuery
9
+ end
10
+
11
+ def test_no_template_values
12
+ test_filter = "displayName eq 'name'"
13
+ filter = @filter_query.sanitize(test_filter)
14
+ assert_equal filter, CGI.escape(test_filter)
15
+ end
16
+
17
+ def test_template_filter_value
18
+ filter = @filter_query.sanitize("displayName eq '?'", ['name'])
19
+ assert_equal filter, CGI.escape("displayName eq 'name'")
20
+ end
21
+
22
+ def test_multiple_template_filter_value
23
+ filter = @filter_query.sanitize("displayName eq '?' and '?'", %w[name hello])
24
+ assert_equal filter, CGI.escape("displayName eq 'name' and 'hello'")
25
+ end
26
+
27
+ def test_template_filter_with_single_quote
28
+ filter = @filter_query.sanitize("displayName eq '?'", ["It's a hard knock life"])
29
+ assert_equal filter, CGI.escape("displayName eq 'It''s a hard knock life'")
30
+ end
31
+
32
+ def test_invalid_values_provided_for_templates_defined
33
+ filter = @filter_query.sanitize("displayName eq '?' and ?", ['test1'])
34
+ assert_equal filter, CGI.escape("displayName eq 'test1' and ")
35
+ end
36
+ end