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,126 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+ # rake test TEST=test/business_central/object/tax_group_test.rb
5
+
6
+ class BusinessCentral::Object::TaxGroupTest < Minitest::Test
7
+ def setup
8
+ @company_id = '123456'
9
+ @client = BusinessCentral::Client.new
10
+ @tax_group = @client.tax_group(company_id: @company_id)
11
+ end
12
+
13
+ def test_find_all
14
+ stub_request(:get, /taxGroups/)
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 = @tax_group.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, /taxGroups\(#{test_id}\)/)
34
+ .to_return(
35
+ status: 200,
36
+ body: {
37
+ id: test_id,
38
+ number: '1010'
39
+ }.to_json
40
+ )
41
+
42
+ response = @tax_group.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, /taxGroups\?\$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 = @tax_group.where(test_filter)
62
+ assert_equal response.first[:number], '1011'
63
+ end
64
+
65
+ def test_create
66
+ stub_request(:post, /taxGroups/)
67
+ .to_return(
68
+ status: 200,
69
+ body: {
70
+ id: '678',
71
+ number: '1012'
72
+ }.to_json
73
+ )
74
+
75
+ response = @tax_group.create(
76
+ number: '1012'
77
+ )
78
+ assert_equal response[:number], '1012'
79
+ end
80
+
81
+ def test_update
82
+ test_id = '011123'
83
+ stub_request(:get, /taxGroups\(#{test_id}\)/)
84
+ .to_return(
85
+ status: 200,
86
+ body: {
87
+ etag: '112',
88
+ id: test_id,
89
+ number: '1012'
90
+ }.to_json
91
+ )
92
+
93
+ stub_request(:patch, /taxGroups\(#{test_id}\)/)
94
+ .to_return(
95
+ status: 200,
96
+ body: {
97
+ id: test_id,
98
+ number: '1013'
99
+ }.to_json
100
+ )
101
+
102
+ response = @tax_group.update(
103
+ test_id,
104
+ number: '1013'
105
+ )
106
+ assert_equal response[:number], '1013'
107
+ end
108
+
109
+ def test_delete
110
+ test_id = '0111245'
111
+ stub_request(:get, /taxGroups\(#{test_id}\)/)
112
+ .to_return(
113
+ status: 200,
114
+ body: {
115
+ etag: '113',
116
+ id: test_id,
117
+ number: '1013'
118
+ }.to_json
119
+ )
120
+
121
+ stub_request(:delete, /taxGroups\(#{test_id}\)/)
122
+ .to_return(status: 204)
123
+
124
+ assert @tax_group.destroy(test_id)
125
+ end
126
+ end
@@ -0,0 +1,126 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+ # rake test TEST=test/business_central/object/time_registration_entry_test.rb
5
+
6
+ class BusinessCentral::Object::TimeRegistrationEntryTest < Minitest::Test
7
+ def setup
8
+ @company_id = '123456'
9
+ @client = BusinessCentral::Client.new
10
+ @time_registration_entry = @client.time_registration_entry(company_id: @company_id)
11
+ end
12
+
13
+ def test_find_all
14
+ stub_request(:get, /timeRegistrationEntries/)
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 = @time_registration_entry.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, /timeRegistrationEntries\(#{test_id}\)/)
34
+ .to_return(
35
+ status: 200,
36
+ body: {
37
+ id: test_id,
38
+ number: '1010'
39
+ }.to_json
40
+ )
41
+
42
+ response = @time_registration_entry.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, /timeRegistrationEntries\?\$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 = @time_registration_entry.where(test_filter)
62
+ assert_equal response.first[:number], '1011'
63
+ end
64
+
65
+ def test_create
66
+ stub_request(:post, /timeRegistrationEntries/)
67
+ .to_return(
68
+ status: 200,
69
+ body: {
70
+ id: '678',
71
+ number: '1012'
72
+ }.to_json
73
+ )
74
+
75
+ response = @time_registration_entry.create(
76
+ number: '1012'
77
+ )
78
+ assert_equal response[:number], '1012'
79
+ end
80
+
81
+ def test_update
82
+ test_id = '011123'
83
+ stub_request(:get, /timeRegistrationEntries\(#{test_id}\)/)
84
+ .to_return(
85
+ status: 200,
86
+ body: {
87
+ etag: '112',
88
+ id: test_id,
89
+ number: '1012'
90
+ }.to_json
91
+ )
92
+
93
+ stub_request(:patch, /timeRegistrationEntries\(#{test_id}\)/)
94
+ .to_return(
95
+ status: 200,
96
+ body: {
97
+ id: test_id,
98
+ number: '1013'
99
+ }.to_json
100
+ )
101
+
102
+ response = @time_registration_entry.update(
103
+ test_id,
104
+ number: '1013'
105
+ )
106
+ assert_equal response[:number], '1013'
107
+ end
108
+
109
+ def test_delete
110
+ test_id = '0111245'
111
+ stub_request(:get, /timeRegistrationEntries\(#{test_id}\)/)
112
+ .to_return(
113
+ status: 200,
114
+ body: {
115
+ etag: '113',
116
+ id: test_id,
117
+ number: '1013'
118
+ }.to_json
119
+ )
120
+
121
+ stub_request(:delete, /timeRegistrationEntries\(#{test_id}\)/)
122
+ .to_return(status: 204)
123
+
124
+ assert @time_registration_entry.destroy(test_id)
125
+ end
126
+ end
@@ -0,0 +1,82 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+ # rake test TEST=test/business_central/object/trial_balance_test.rb
5
+
6
+ class BusinessCentral::Object::TrialBalanceTest < Minitest::Test
7
+ def setup
8
+ @company_id = '123456'
9
+ @client = BusinessCentral::Client.new
10
+ @trial_balance = @client.trial_balance(company_id: @company_id)
11
+ end
12
+
13
+ def test_find_all
14
+ stub_request(:get, /trialBalance/)
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 = @trial_balance.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, /trialBalance\(#{test_id}\)/)
34
+ .to_return(
35
+ status: 200,
36
+ body: {
37
+ id: test_id,
38
+ number: '1010'
39
+ }.to_json
40
+ )
41
+
42
+ response = @trial_balance.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, /trialBalance\?\$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 = @trial_balance.where(test_filter)
62
+ assert_equal response.first[:number], '1011'
63
+ end
64
+
65
+ def test_create
66
+ assert_raises BusinessCentral::NoSupportedMethod do
67
+ @trial_balance.create({})
68
+ end
69
+ end
70
+
71
+ def test_update
72
+ assert_raises BusinessCentral::NoSupportedMethod do
73
+ @trial_balance.update('123', {})
74
+ end
75
+ end
76
+
77
+ def test_delete
78
+ assert_raises BusinessCentral::NoSupportedMethod do
79
+ @trial_balance.destroy('123')
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,126 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'test_helper'
4
+ # rake test TEST=test/business_central/object/units_of_measure_test.rb
5
+
6
+ class BusinessCentral::Object::UnitsOfMeasureTest < Minitest::Test
7
+ def setup
8
+ @company_id = '123456'
9
+ @client = BusinessCentral::Client.new
10
+ @units_of_measure = @client.units_of_measure(company_id: @company_id)
11
+ end
12
+
13
+ def test_find_all
14
+ stub_request(:get, /unitsOfMeasure/)
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 = @units_of_measure.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, /unitsOfMeasure\(#{test_id}\)/)
34
+ .to_return(
35
+ status: 200,
36
+ body: {
37
+ id: test_id,
38
+ number: '1010'
39
+ }.to_json
40
+ )
41
+
42
+ response = @units_of_measure.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, /unitsOfMeasure\?\$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 = @units_of_measure.where(test_filter)
62
+ assert_equal response.first[:number], '1011'
63
+ end
64
+
65
+ def test_create
66
+ stub_request(:post, /unitsOfMeasure/)
67
+ .to_return(
68
+ status: 200,
69
+ body: {
70
+ id: '678',
71
+ number: '1012'
72
+ }.to_json
73
+ )
74
+
75
+ response = @units_of_measure.create(
76
+ number: '1012'
77
+ )
78
+ assert_equal response[:number], '1012'
79
+ end
80
+
81
+ def test_update
82
+ test_id = '011123'
83
+ stub_request(:get, /unitsOfMeasure\(#{test_id}\)/)
84
+ .to_return(
85
+ status: 200,
86
+ body: {
87
+ etag: '112',
88
+ id: test_id,
89
+ number: '1012'
90
+ }.to_json
91
+ )
92
+
93
+ stub_request(:patch, /unitsOfMeasure\(#{test_id}\)/)
94
+ .to_return(
95
+ status: 200,
96
+ body: {
97
+ id: test_id,
98
+ number: '1013'
99
+ }.to_json
100
+ )
101
+
102
+ response = @units_of_measure.update(
103
+ test_id,
104
+ number: '1013'
105
+ )
106
+ assert_equal response[:number], '1013'
107
+ end
108
+
109
+ def test_delete
110
+ test_id = '0111245'
111
+ stub_request(:get, /unitsOfMeasure\(#{test_id}\)/)
112
+ .to_return(
113
+ status: 200,
114
+ body: {
115
+ etag: '113',
116
+ id: test_id,
117
+ number: '1013'
118
+ }.to_json
119
+ )
120
+
121
+ stub_request(:delete, /unitsOfMeasure\(#{test_id}\)/)
122
+ .to_return(status: 204)
123
+
124
+ assert @units_of_measure.destroy(test_id)
125
+ end
126
+ end