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,129 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+ # rake test TEST=test/business_central/object/country_region_test.rb
5
+
6
+ class BusinessCentral::Object::CountryRegionTest < Minitest::Test
7
+ def setup
8
+ @company_id = '123456'
9
+ @client = BusinessCentral::Client.new
10
+ @country_region = @client.country_region(company_id: @company_id)
11
+ end
12
+
13
+ def test_find_all
14
+ stub_request(:get, /countriesRegions/)
15
+ .to_return(
16
+ status: 200,
17
+ body: {
18
+ 'value': [
19
+ {
20
+ id: 1,
21
+ code: 'C1',
22
+ displayName: 'country1'
23
+ }
24
+ ]
25
+ }.to_json
26
+ )
27
+
28
+ response = @country_region.find_all
29
+ assert_equal response.first[:display_name], 'country1'
30
+ end
31
+
32
+ def test_find_by_id
33
+ test_id = '1111'
34
+ stub_request(:get, /countriesRegions\(#{test_id}\)/)
35
+ .to_return(
36
+ status: 200,
37
+ body: {
38
+ id: 2,
39
+ code: 'C2',
40
+ displayName: 'country2'
41
+ }.to_json
42
+ )
43
+
44
+ response = @country_region.find_by_id(test_id)
45
+ assert_equal response[:display_name], 'country2'
46
+ end
47
+
48
+ def test_where
49
+ test_filter = "displayName eq 'country3'"
50
+ stub_request(:get, /countriesRegions\?\$filter=#{test_filter}/)
51
+ .to_return(
52
+ status: 200,
53
+ body: {
54
+ 'value': [
55
+ {
56
+ displayName: 'country3'
57
+ }
58
+ ]
59
+ }.to_json
60
+ )
61
+
62
+ response = @country_region.where(test_filter)
63
+ assert_equal response.first[:display_name], 'country3'
64
+ end
65
+
66
+ def test_create
67
+ stub_request(:post, /countriesRegions/)
68
+ .to_return(
69
+ status: 200,
70
+ body: {
71
+ displayName: 'country4'
72
+ }.to_json
73
+ )
74
+
75
+ response = @country_region.create(
76
+ code: 'C4',
77
+ display_name: 'country4'
78
+ )
79
+ assert_equal response[:display_name], 'country4'
80
+ end
81
+
82
+ def test_update
83
+ test_id = '22222'
84
+ stub_request(:get, /countriesRegions\(#{test_id}\)/)
85
+ .to_return(
86
+ status: 200,
87
+ body: {
88
+ etag: '2222',
89
+ code: 'C5',
90
+ displayName: 'country5'
91
+ }.to_json
92
+ )
93
+
94
+ stub_request(:patch, /countriesRegions\(#{test_id}\)/)
95
+ .to_return(
96
+ status: 200,
97
+ body: {
98
+ etag: '2222',
99
+ code: 'C6',
100
+ displayName: 'country6'
101
+ }.to_json
102
+ )
103
+
104
+ response = @country_region.update(
105
+ test_id,
106
+ code: 'C6',
107
+ display_name: 'country6'
108
+ )
109
+ assert_equal response[:display_name], 'country6'
110
+ end
111
+
112
+ def test_delete
113
+ test_id = '33333'
114
+ stub_request(:get, /countriesRegions\(#{test_id}\)/)
115
+ .to_return(
116
+ status: 200,
117
+ body: {
118
+ etag: '3333',
119
+ code: 'C7',
120
+ displayName: 'country7'
121
+ }.to_json
122
+ )
123
+
124
+ stub_request(:delete, /countriesRegions\(#{test_id}\)/)
125
+ .to_return(status: 204)
126
+
127
+ assert @country_region.destroy(test_id)
128
+ end
129
+ end
@@ -0,0 +1,150 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+ # rake test TEST=test/business_central/object/currency_test.rb
5
+
6
+ class BusinessCentral::Object::CurrencyTest < Minitest::Test
7
+ def setup
8
+ @company_id = '123456'
9
+ @client = BusinessCentral::Client.new
10
+ @currency = @client.currency(company_id: @company_id)
11
+ end
12
+
13
+ def test_find_all
14
+ stub_request(:get, /currencies/)
15
+ .to_return(
16
+ status: 200,
17
+ body: {
18
+ 'value': [
19
+ {
20
+ id: 1,
21
+ code: 'C1',
22
+ displayName: 'currency1',
23
+ symbol: '$',
24
+ amountDecimalPlaces: '2:2',
25
+ amountRoundingPrecision: 0.01
26
+ }
27
+ ]
28
+ }.to_json
29
+ )
30
+
31
+ response = @currency.find_all
32
+ assert_equal response.first[:display_name], 'currency1'
33
+ end
34
+
35
+ def test_find_by_id
36
+ test_id = '2'
37
+ stub_request(:get, /currencies\(#{test_id}\)/)
38
+ .to_return(
39
+ status: 200,
40
+ body: {
41
+ id: test_id,
42
+ code: 'C2',
43
+ displayName: 'currency2',
44
+ symbol: '$',
45
+ amountDecimalPlaces: '2:2',
46
+ amountRoundingPrecision: 0.01
47
+ }.to_json
48
+ )
49
+
50
+ response = @currency.find_by_id(test_id)
51
+ assert_equal response[:display_name], 'currency2'
52
+ end
53
+
54
+ def test_where
55
+ test_filter = "displayName eq 'country3'"
56
+ stub_request(:get, /currencies\?\$filter=#{test_filter}/)
57
+ .to_return(
58
+ status: 200,
59
+ body: {
60
+ 'value': [
61
+ {
62
+ id: 3,
63
+ code: 'C3',
64
+ displayName: 'currency3',
65
+ symbol: '$',
66
+ amountDecimalPlaces: '2:2',
67
+ amountRoundingPrecision: 0.01
68
+ }
69
+ ]
70
+ }.to_json
71
+ )
72
+
73
+ response = @currency.where(test_filter)
74
+ assert_equal response.first[:display_name], 'currency3'
75
+ end
76
+
77
+ def test_create
78
+ stub_request(:post, /currencies/)
79
+ .to_return(
80
+ status: 200,
81
+ body: {
82
+ code: 'C4',
83
+ displayName: 'currency4',
84
+ symbol: '$'
85
+ }.to_json
86
+ )
87
+
88
+ response = @currency.create(
89
+ code: 'C4',
90
+ display_name: 'currency4',
91
+ symbol: '$'
92
+ )
93
+ assert_equal response[:display_name], 'currency4'
94
+ end
95
+
96
+ def test_update
97
+ test_id = '2'
98
+ stub_request(:get, /currencies\(#{test_id}\)/)
99
+ .to_return(
100
+ status: 200,
101
+ body: {
102
+ etag: '3333',
103
+ id: test_id,
104
+ code: 'C5',
105
+ displayName: 'currency5',
106
+ symbol: '$',
107
+ amountDecimalPlaces: '2:2',
108
+ amountRoundingPrecision: 0.01
109
+ }.to_json
110
+ )
111
+
112
+ stub_request(:patch, /currencies\(#{test_id}\)/)
113
+ .to_return(
114
+ status: 200,
115
+ body: {
116
+ etag: '4444',
117
+ code: 'C6',
118
+ displayName: 'currency6',
119
+ symbol: '$'
120
+ }.to_json
121
+ )
122
+
123
+ response = @currency.update(
124
+ test_id,
125
+ code: 'C6',
126
+ display_name: 'currency6',
127
+ symbol: '$'
128
+ )
129
+ assert_equal response[:display_name], 'currency6'
130
+ end
131
+
132
+ def test_delete
133
+ test_id = '33333'
134
+ stub_request(:get, /currencies\(#{test_id}\)/)
135
+ .to_return(
136
+ status: 200,
137
+ body: {
138
+ etag: '5555',
139
+ code: 'C7',
140
+ displayName: 'currency7',
141
+ symbol: '$'
142
+ }.to_json
143
+ )
144
+
145
+ stub_request(:delete, /currencies\(#{test_id}\)/)
146
+ .to_return(status: 204)
147
+
148
+ assert @currency.destroy(test_id)
149
+ end
150
+ end
@@ -0,0 +1,68 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+ # rake test TEST=test/business_central/object/customer_financial_detail_test.rb
5
+
6
+ class BusinessCentral::Object::CustomerFinancialDetailTest < Minitest::Test
7
+ def setup
8
+ @company_id = '123456'
9
+ @client = BusinessCentral::Client.new
10
+ @customer_financial_detail = @client.customer_financial_detail(
11
+ company_id: @company_id
12
+ )
13
+ end
14
+
15
+ def test_find_all
16
+ stub_request(:get, /customerFinancialDetails/)
17
+ .to_return(
18
+ status: 200,
19
+ body: {
20
+ 'value': [
21
+ {
22
+ id: 1,
23
+ number: 'N1',
24
+ balance: 0
25
+ }
26
+ ]
27
+ }.to_json
28
+ )
29
+
30
+ response = @customer_financial_detail.find_all
31
+ assert_equal response.first[:number], 'N1'
32
+ end
33
+
34
+ def test_find_by_id
35
+ test_id = '2'
36
+ stub_request(:get, /customerFinancialDetails\(#{test_id}\)/)
37
+ .to_return(
38
+ status: 200,
39
+ body: {
40
+ id: test_id,
41
+ number: 'N2',
42
+ balance: 0
43
+ }.to_json
44
+ )
45
+
46
+ response = @customer_financial_detail.find_by_id(test_id)
47
+ assert_equal response[:number], 'N2'
48
+ end
49
+
50
+ def test_where
51
+ test_filter = "number eq 'N3'"
52
+ stub_request(:get, /customerFinancialDetails\?\$filter=#{test_filter}/)
53
+ .to_return(
54
+ status: 200,
55
+ body: {
56
+ 'value': [
57
+ {
58
+ id: 3,
59
+ number: 'N3'
60
+ }
61
+ ]
62
+ }.to_json
63
+ )
64
+
65
+ response = @customer_financial_detail.where(test_filter)
66
+ assert_equal response.first[:number], 'N3'
67
+ end
68
+ end
@@ -0,0 +1,134 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+ # rake test TEST=test/business_central/object/customer_payment_journal_test.rb
5
+
6
+ class BusinessCentral::Object::CustomerPaymentJournalTest < Minitest::Test
7
+ def setup
8
+ @company_id = '123456'
9
+ @client = BusinessCentral::Client.new
10
+ @customer_payment_journal = @client.customer_payment_journal(company_id: @company_id)
11
+ end
12
+
13
+ def test_find_all
14
+ stub_request(:get, /customerPaymentJournals/)
15
+ .to_return(
16
+ status: 200,
17
+ body: {
18
+ 'value': [
19
+ {
20
+ id: 1,
21
+ code: 'GENERAL',
22
+ displayName: 'GENERAL 1'
23
+ }
24
+ ]
25
+ }.to_json
26
+ )
27
+
28
+ response = @customer_payment_journal.find_all
29
+ assert_equal response.first[:display_name], 'GENERAL 1'
30
+ end
31
+
32
+ def test_find_by_id
33
+ test_id = 2
34
+ stub_request(:get, /customerPaymentJournals\(#{test_id}\)/)
35
+ .to_return(
36
+ status: 200,
37
+ body: {
38
+ id: test_id,
39
+ code: 'GENERAL',
40
+ displayName: 'GENERAL 2'
41
+ }.to_json
42
+ )
43
+
44
+ response = @customer_payment_journal.find_by_id(test_id)
45
+ assert_equal response[:display_name], 'GENERAL 2'
46
+ end
47
+
48
+ def test_where
49
+ test_filter = "displayName eq 'GENERAL 3'"
50
+ stub_request(:get, /customerPaymentJournals\?\$filter=#{test_filter}/)
51
+ .to_return(
52
+ status: 200,
53
+ body: {
54
+ 'value': [
55
+ {
56
+ id: 1,
57
+ code: 'GENERAL',
58
+ displayName: 'GENERAL 3'
59
+ }
60
+ ]
61
+ }.to_json
62
+ )
63
+
64
+ response = @customer_payment_journal.where(test_filter)
65
+ assert_equal response.first[:display_name], 'GENERAL 3'
66
+ end
67
+
68
+ def test_create
69
+ stub_request(:post, /customerPaymentJournals/)
70
+ .to_return(
71
+ status: 200,
72
+ body: {
73
+ id: 1,
74
+ code: 'GENERAL',
75
+ displayName: 'GENERAL 4'
76
+ }.to_json
77
+ )
78
+
79
+ response = @customer_payment_journal.create(
80
+ display_name: 'GENERAL 4'
81
+ )
82
+ assert_equal response[:display_name], 'GENERAL 4'
83
+ end
84
+
85
+ def test_update
86
+ test_id = 2
87
+ stub_request(:get, /customerPaymentJournals\(#{test_id}\)/)
88
+ .to_return(
89
+ status: 200,
90
+ body: {
91
+ etag: '3333',
92
+ id: test_id,
93
+ code: 'GENERAL',
94
+ displayName: 'GENERAL 4'
95
+ }.to_json
96
+ )
97
+
98
+ stub_request(:patch, /customerPaymentJournals\(#{test_id}\)/)
99
+ .to_return(
100
+ status: 200,
101
+ body: {
102
+ etag: '4444',
103
+ id: test_id,
104
+ code: 'GENERAL',
105
+ displayName: 'GENERAL 5'
106
+ }.to_json
107
+ )
108
+
109
+ response = @customer_payment_journal.update(
110
+ test_id,
111
+ display_name: 'GENERAL 5'
112
+ )
113
+ assert_equal response[:display_name], 'GENERAL 5'
114
+ end
115
+
116
+ def test_delete
117
+ test_id = '33333'
118
+ stub_request(:get, /customerPaymentJournals\(#{test_id}\)/)
119
+ .to_return(
120
+ status: 200,
121
+ body: {
122
+ etag: '5555',
123
+ id: test_id,
124
+ code: 'GENERAL',
125
+ displayName: 'GENERAL 5'
126
+ }.to_json
127
+ )
128
+
129
+ stub_request(:delete, /customerPaymentJournals\(#{test_id}\)/)
130
+ .to_return(status: 204)
131
+
132
+ assert @customer_payment_journal.destroy(test_id)
133
+ end
134
+ end