business-central 1.0.5 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +45 -32
  3. data/lib/business_central/client.rb +7 -52
  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 +10 -37
  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 +5 -1
  13. data/lib/business_central/object/url_builder.rb +16 -12
  14. data/lib/business_central/object/url_helper.rb +16 -2
  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 -55
  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. data/test/business_central/object/response_test.rb +5 -0
  26. data/test/business_central/web_service_test.rb +7 -2
  27. metadata +38 -167
  28. data/lib/business_central/object/account.rb +0 -13
  29. data/lib/business_central/object/aged_account_payable.rb +0 -13
  30. data/lib/business_central/object/aged_account_receivable.rb +0 -13
  31. data/lib/business_central/object/argument_helper.rb +0 -22
  32. data/lib/business_central/object/balance_sheet.rb +0 -13
  33. data/lib/business_central/object/cash_flow_statement.rb +0 -13
  34. data/lib/business_central/object/company.rb +0 -18
  35. data/lib/business_central/object/company_information.rb +0 -14
  36. data/lib/business_central/object/country_region.rb +0 -26
  37. data/lib/business_central/object/currency.rb +0 -29
  38. data/lib/business_central/object/customer.rb +0 -34
  39. data/lib/business_central/object/customer_financial_detail.rb +0 -13
  40. data/lib/business_central/object/customer_payment.rb +0 -43
  41. data/lib/business_central/object/customer_payment_journal.rb +0 -25
  42. data/lib/business_central/object/customer_sale.rb +0 -13
  43. data/lib/business_central/object/default_dimension.rb +0 -51
  44. data/lib/business_central/object/dimension.rb +0 -20
  45. data/lib/business_central/object/dimension_line.rb +0 -37
  46. data/lib/business_central/object/dimension_value.rb +0 -28
  47. data/lib/business_central/object/employee.rb +0 -21
  48. data/lib/business_central/object/general_ledger_entry.rb +0 -13
  49. data/lib/business_central/object/income_statement.rb +0 -13
  50. data/lib/business_central/object/irs1099_code.rb +0 -16
  51. data/lib/business_central/object/item.rb +0 -47
  52. data/lib/business_central/object/item_category.rb +0 -16
  53. data/lib/business_central/object/journal.rb +0 -29
  54. data/lib/business_central/object/journal_line.rb +0 -48
  55. data/lib/business_central/object/payment_method.rb +0 -16
  56. data/lib/business_central/object/payment_term.rb +0 -16
  57. data/lib/business_central/object/purchase_invoice.rb +0 -69
  58. data/lib/business_central/object/purchase_invoice_line.rb +0 -37
  59. data/lib/business_central/object/retained_earning_statement.rb +0 -13
  60. data/lib/business_central/object/sales_credit_memo.rb +0 -20
  61. data/lib/business_central/object/sales_credit_memo_line.rb +0 -30
  62. data/lib/business_central/object/sales_invoice.rb +0 -62
  63. data/lib/business_central/object/sales_invoice_line.rb +0 -30
  64. data/lib/business_central/object/sales_order.rb +0 -20
  65. data/lib/business_central/object/sales_order_line.rb +0 -30
  66. data/lib/business_central/object/sales_quote.rb +0 -20
  67. data/lib/business_central/object/sales_quote_line.rb +0 -30
  68. data/lib/business_central/object/shipment_method.rb +0 -16
  69. data/lib/business_central/object/subscription.rb +0 -16
  70. data/lib/business_central/object/tax_area.rb +0 -16
  71. data/lib/business_central/object/tax_group.rb +0 -16
  72. data/lib/business_central/object/time_registration_entry.rb +0 -16
  73. data/lib/business_central/object/trial_balance.rb +0 -13
  74. data/lib/business_central/object/units_of_measure.rb +0 -16
  75. data/lib/business_central/object/validation.rb +0 -57
  76. data/lib/business_central/object/vendor.rb +0 -42
  77. data/lib/business_central/object/vendor_purchase.rb +0 -13
  78. data/lib/core_ext/string.rb +0 -31
  79. data/test/business_central/object/account_test.rb +0 -67
  80. data/test/business_central/object/aged_account_payable_test.rb +0 -61
  81. data/test/business_central/object/aged_account_receivable_test.rb +0 -61
  82. data/test/business_central/object/balance_sheet_test.rb +0 -61
  83. data/test/business_central/object/cash_flow_statement_test.rb +0 -61
  84. data/test/business_central/object/company_information_test.rb +0 -81
  85. data/test/business_central/object/country_region_test.rb +0 -129
  86. data/test/business_central/object/currency_test.rb +0 -150
  87. data/test/business_central/object/customer_financial_detail_test.rb +0 -68
  88. data/test/business_central/object/customer_payment_journal_test.rb +0 -134
  89. data/test/business_central/object/customer_payment_test.rb +0 -141
  90. data/test/business_central/object/customer_sale_test.rb +0 -72
  91. data/test/business_central/object/customer_test.rb +0 -168
  92. data/test/business_central/object/default_dimension_test.rb +0 -170
  93. data/test/business_central/object/dimension_line_test.rb +0 -165
  94. data/test/business_central/object/dimension_test.rb +0 -65
  95. data/test/business_central/object/dimension_value_test.rb +0 -68
  96. data/test/business_central/object/employee_test.rb +0 -141
  97. data/test/business_central/object/general_ledger_entry_test.rb +0 -82
  98. data/test/business_central/object/income_statement_test.rb +0 -82
  99. data/test/business_central/object/irs1099_code_test.rb +0 -124
  100. data/test/business_central/object/item_category_test.rb +0 -122
  101. data/test/business_central/object/item_test.rb +0 -121
  102. data/test/business_central/object/journal_line_test.rb +0 -152
  103. data/test/business_central/object/journal_test.rb +0 -144
  104. data/test/business_central/object/payment_method_test.rb +0 -134
  105. data/test/business_central/object/payment_term_test.rb +0 -134
  106. data/test/business_central/object/purchase_invoice_line_test.rb +0 -123
  107. data/test/business_central/object/purchase_invoice_test.rb +0 -119
  108. data/test/business_central/object/retained_earning_statement_test.rb +0 -52
  109. data/test/business_central/object/sales_credit_memo_line_test.rb +0 -134
  110. data/test/business_central/object/sales_credit_memo_test.rb +0 -146
  111. data/test/business_central/object/sales_invoice_line_test.rb +0 -164
  112. data/test/business_central/object/sales_invoice_test.rb +0 -156
  113. data/test/business_central/object/sales_order_line_test.rb +0 -134
  114. data/test/business_central/object/sales_order_test.rb +0 -146
  115. data/test/business_central/object/sales_quote_line_test.rb +0 -134
  116. data/test/business_central/object/sales_quote_test.rb +0 -146
  117. data/test/business_central/object/shipment_method_test.rb +0 -133
  118. data/test/business_central/object/subscription_test.rb +0 -126
  119. data/test/business_central/object/tax_area_test.rb +0 -126
  120. data/test/business_central/object/tax_group_test.rb +0 -126
  121. data/test/business_central/object/time_registration_entry_test.rb +0 -126
  122. data/test/business_central/object/trial_balance_test.rb +0 -82
  123. data/test/business_central/object/units_of_measure_test.rb +0 -126
  124. data/test/business_central/object/validation_test.rb +0 -62
  125. data/test/business_central/object/vendor_purchase_test.rb +0 -82
  126. data/test/business_central/object/vendor_test.rb +0 -119
@@ -1,72 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
- # rake test TEST=test/business_central/object/customer_sale_test.rb
5
-
6
- class BusinessCentral::Object::CustomerSaleTest < Minitest::Test
7
- def setup
8
- @company_id = '123456'
9
- @client = BusinessCentral::Client.new
10
- @customer_sale = @client.customer_sale(
11
- company_id: @company_id
12
- )
13
- end
14
-
15
- def test_find_all
16
- stub_request(:get, /customerSales/)
17
- .to_return(
18
- status: 200,
19
- body: {
20
- 'value': [
21
- {
22
- customerId: 1,
23
- customerNumber: 'C1',
24
- name: 'Jarrad',
25
- totalSalesAmount: 0
26
- }
27
- ]
28
- }.to_json
29
- )
30
-
31
- response = @customer_sale.find_all
32
- assert_equal response.first[:customer_number], 'C1'
33
- end
34
-
35
- def test_find_by_id
36
- test_id = 2
37
- stub_request(:get, /customerSales\(#{test_id}\)/)
38
- .to_return(
39
- status: 200,
40
- body: {
41
- customerId: 2,
42
- customerNumber: 'C2',
43
- name: 'Jrad',
44
- totalSalesAmount: 0
45
- }.to_json
46
- )
47
-
48
- response = @customer_sale.find_by_id(test_id)
49
- assert_equal response[:customer_number], 'C2'
50
- end
51
-
52
- def test_where
53
- test_filter = "customerNumber eq 'C3'"
54
- stub_request(:get, /customerSales\?\$filter=#{test_filter}/)
55
- .to_return(
56
- status: 200,
57
- body: {
58
- 'value': [
59
- {
60
- customerId: 3,
61
- customerNumber: 'C3',
62
- name: 'Jazza',
63
- totalSalesAmount: 0
64
- }
65
- ]
66
- }.to_json
67
- )
68
-
69
- response = @customer_sale.where(test_filter)
70
- assert_equal response.first[:customer_number], 'C3'
71
- end
72
- end
@@ -1,168 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
- # rake test TEST=test/business_central/object/customer_test.rb
5
-
6
- class BusinessCentral::Object::CustomerTest < Minitest::Test
7
- def setup
8
- @company_id = '123456'
9
- @client = BusinessCentral::Client.new
10
- @customer = @client.customer(company_id: @company_id)
11
- end
12
-
13
- def test_find_all
14
- stub_request(:get, /customers/)
15
- .to_return(
16
- status: 200,
17
- body: {
18
- 'value': [
19
- {
20
- id: 1,
21
- displayName: 'customer1'
22
- }
23
- ]
24
- }.to_json
25
- )
26
-
27
- response = @customer.find_all
28
- assert_equal response.first[:display_name], 'customer1'
29
- end
30
-
31
- def test_find_by_id
32
- test_id = '2'
33
- stub_request(:get, /customers\(#{test_id}\)/)
34
- .to_return(
35
- status: 200,
36
- body: {
37
- id: test_id,
38
- displayName: 'customer2'
39
- }.to_json
40
- )
41
-
42
- response = @customer.find_by_id(test_id)
43
- assert_equal response[:display_name], 'customer2'
44
- end
45
-
46
- def test_where
47
- test_filter = "displayName eq 'customer3'"
48
- stub_request(:get, /customers\?\$filter=#{test_filter}/)
49
- .to_return(
50
- status: 200,
51
- body: {
52
- 'value': [
53
- {
54
- id: 3,
55
- displayName: 'customer3'
56
- }
57
- ]
58
- }.to_json
59
- )
60
-
61
- response = @customer.where(test_filter)
62
- assert_equal response.first[:display_name], 'customer3'
63
- end
64
-
65
- def test_create
66
- stub_request(:post, /customers/)
67
- .to_return(
68
- status: 200,
69
- body: {
70
- displayName: 'customer4'
71
- }.to_json
72
- )
73
-
74
- response = @customer.create(
75
- display_name: 'customer4'
76
- )
77
- assert_equal response[:display_name], 'customer4'
78
- end
79
-
80
- def test_update
81
- test_id = '2'
82
- stub_request(:get, /customers\(#{test_id}\)/)
83
- .to_return(
84
- status: 200,
85
- body: {
86
- etag: '3333',
87
- id: test_id,
88
- displayName: 'customer5'
89
- }.to_json
90
- )
91
-
92
- stub_request(:patch, /customers\(#{test_id}\)/)
93
- .to_return(
94
- status: 200,
95
- body: {
96
- etag: '4444',
97
- displayName: 'customer6'
98
- }.to_json
99
- )
100
-
101
- response = @customer.update(
102
- test_id,
103
- display_name: 'customer6'
104
- )
105
- assert_equal response[:display_name], 'customer6'
106
- end
107
-
108
- def test_delete
109
- test_id = '33333'
110
- stub_request(:get, /customers\(#{test_id}\)/)
111
- .to_return(
112
- status: 200,
113
- body: {
114
- etag: '5555',
115
- displayName: 'customer7'
116
- }.to_json
117
- )
118
-
119
- stub_request(:delete, /customers\(#{test_id}\)/)
120
- .to_return(status: 204)
121
-
122
- assert @customer.destroy(test_id)
123
- end
124
-
125
- def test_default_dimension_navigation
126
- stub_request(:get, %r{customers\(\d+\)\/defaultDimensions})
127
- .to_return(
128
- status: 200,
129
- body: {
130
- 'value': [
131
- {
132
- id: 1,
133
- parentId: '123',
134
- dimensionId: '123',
135
- dimensionCode: 'ABC',
136
- dimensionValueId: 1,
137
- dimensionValueCode: 'DEF'
138
- }
139
- ]
140
- }.to_json
141
- )
142
-
143
- response = @client.customer(company_id: @company_id, id: '123')
144
- .default_dimension.find_all
145
- assert_equal response.first[:parent_id], '123'
146
- end
147
-
148
- def test_picture_navigation
149
- stub_request(:get, %r{customers\(\d+\)\/picture})
150
- .to_return(
151
- status: 200,
152
- body: {
153
- 'value': [
154
- {
155
- id: 1,
156
- width: 500,
157
- height: 496,
158
- contentType: 'image\jpeg'
159
- }
160
- ]
161
- }.to_json
162
- )
163
-
164
- response = @client.customer(company_id: @company_id, id: '123')
165
- .picture.find_all
166
- assert_equal response.first[:width], 500
167
- end
168
- end
@@ -1,170 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
- # rake test TEST=test/business_central/object/default_dimension_test.rb
5
-
6
- class BusinessCentral::Object::DefaultDimensionTest < Minitest::Test
7
- def setup
8
- @company_id = '123456'
9
- @client = BusinessCentral::Client.new
10
- @default_dimension = @client.default_dimension(
11
- company_id: @company_id,
12
- parent: 'vendors',
13
- parent_id: '123'
14
- )
15
- end
16
-
17
- def test_invalid_default_dimension_parent
18
- assert_raises(BusinessCentral::InvalidArgumentException) do
19
- @client.default_dimension(
20
- company_id: @company_id,
21
- parent: 'something that doesnt exist',
22
- parent_id: '1'
23
- )
24
- end
25
- end
26
-
27
- def test_find_all
28
- stub_request(:get, /defaultDimensions/)
29
- .to_return(
30
- status: 200,
31
- body: {
32
- 'value': [
33
- {
34
- id: 1,
35
- parentId: '123',
36
- dimensionId: '123',
37
- dimensionCode: 'ABC',
38
- dimensionValueId: 1,
39
- dimensionValueCode: 'DEF'
40
- }
41
- ]
42
- }.to_json
43
- )
44
-
45
- response = @default_dimension.find_all
46
- assert_equal response.first[:parent_id], '123'
47
- end
48
-
49
- def test_find_by_id
50
- test_id = '2'
51
- stub_request(:get, /defaultDimensions\(#{test_id}\)/)
52
- .to_return(
53
- status: 200,
54
- body: {
55
- id: test_id,
56
- parentId: '123',
57
- dimensionId: '123',
58
- dimensionCode: 'ABC',
59
- dimensionValueId: 1,
60
- dimensionValueCode: 'DEF'
61
- }.to_json
62
- )
63
-
64
- response = @default_dimension.find_by_id(test_id)
65
- assert_equal response[:dimension_code], 'ABC'
66
- end
67
-
68
- def test_where
69
- test_filter = "dimensionCode eq 'ABC'"
70
- stub_request(:get, /defaultDimensions\?\$filter=#{test_filter}/)
71
- .to_return(
72
- status: 200,
73
- body: {
74
- 'value': [
75
- {
76
- id: 3,
77
- parentId: '123',
78
- dimensionId: '123',
79
- dimensionCode: 'ABC',
80
- dimensionValueId: 1,
81
- dimensionValueCode: 'DEF'
82
- }
83
- ]
84
- }.to_json
85
- )
86
-
87
- response = @default_dimension.where(test_filter)
88
- assert_equal response.first[:dimension_code], 'ABC'
89
- end
90
-
91
- def test_create
92
- stub_request(:post, /defaultDimensions/)
93
- .to_return(
94
- status: 200,
95
- body: {
96
- id: 4,
97
- parentId: '123',
98
- dimensionId: '123',
99
- dimensionCode: 'ABC',
100
- dimensionValueId: 1,
101
- dimensionValueCode: 'DEF'
102
- }.to_json
103
- )
104
-
105
- response = @default_dimension.create(
106
- dimension_code: 'DEF',
107
- dimension_value_code: 'GHI'
108
- )
109
- assert_equal response[:id], 4
110
- end
111
-
112
- def test_update
113
- test_id = '2'
114
- stub_request(:get, /defaultDimensions\(#{test_id}\)/)
115
- .to_return(
116
- status: 200,
117
- body: {
118
- etag: '3333',
119
- id: test_id,
120
- parentId: '123',
121
- dimensionId: '123',
122
- dimensionCode: 'ABC',
123
- dimensionValueId: 1,
124
- dimensionValueCode: 'DEF'
125
- }.to_json
126
- )
127
-
128
- stub_request(:patch, /defaultDimensions\(#{test_id}\)/)
129
- .to_return(
130
- status: 200,
131
- body: {
132
- etag: '4444',
133
- id: test_id,
134
- parentId: '123',
135
- dimensionId: '123',
136
- dimensionCode: 'ZYX',
137
- dimensionValueId: 1,
138
- dimensionValueCode: 'DEF'
139
- }.to_json
140
- )
141
-
142
- response = @default_dimension.update(
143
- test_id,
144
- dimension_code: 'ZYX'
145
- )
146
- assert_equal response[:dimension_code], 'ZYX'
147
- end
148
-
149
- def test_delete
150
- test_id = '33333'
151
- stub_request(:get, /defaultDimensions\(#{test_id}\)/)
152
- .to_return(
153
- status: 200,
154
- body: {
155
- etag: '5555',
156
- id: test_id,
157
- parentId: '123',
158
- dimensionId: '123',
159
- dimensionCode: 'ZYX',
160
- dimensionValueId: 1,
161
- dimensionValueCode: 'DEF'
162
- }.to_json
163
- )
164
-
165
- stub_request(:delete, /defaultDimensions\(#{test_id}\)/)
166
- .to_return(status: 204)
167
-
168
- assert @default_dimension.destroy(test_id)
169
- end
170
- end
@@ -1,165 +0,0 @@
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
@@ -1,65 +0,0 @@
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
@@ -1,68 +0,0 @@
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