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
@@ -1,129 +0,0 @@
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
@@ -1,150 +0,0 @@
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
@@ -1,68 +0,0 @@
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
@@ -1,134 +0,0 @@
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
@@ -1,141 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
- # rake test TEST=test/business_central/object/customer_payment_test.rb
5
-
6
- class BusinessCentral::Object::CustomerPaymentTest < Minitest::Test
7
- def setup
8
- @company_id = '123456'
9
- @client = BusinessCentral::Client.new
10
- @customer_payment = @client.customer_payment(company_id: @company_id)
11
- end
12
-
13
- def test_find_all
14
- stub_request(:get, /customerPayments/)
15
- .to_return(
16
- status: 200,
17
- body: {
18
- 'value': [
19
- {
20
- id: 1,
21
- lineNumber: 1,
22
- customerId: 1,
23
- customerNumber: '123'
24
- }
25
- ]
26
- }.to_json
27
- )
28
-
29
- response = @customer_payment.find_all
30
- assert_equal response.first[:customer_number], '123'
31
- end
32
-
33
- def test_find_by_id
34
- test_id = '2'
35
- stub_request(:get, /customerPayments\(#{test_id}\)/)
36
- .to_return(
37
- status: 200,
38
- body: {
39
- id: test_id,
40
- lineNumber: 1,
41
- customerId: test_id,
42
- customerNumber: '456'
43
- }.to_json
44
- )
45
-
46
- response = @customer_payment.find_by_id(test_id)
47
- assert_equal response[:customer_number], '456'
48
- end
49
-
50
- def test_where
51
- test_filter = "customerNumber eq '123'"
52
- stub_request(:get, /customerPayments\?\$filter=#{test_filter}/)
53
- .to_return(
54
- status: 200,
55
- body: {
56
- 'value': [
57
- {
58
- id: 1,
59
- lineNumber: 1,
60
- customerId: 1,
61
- customerNumber: '123'
62
- }
63
- ]
64
- }.to_json
65
- )
66
-
67
- response = @customer_payment.where(test_filter)
68
- assert_equal response.first[:customer_number], '123'
69
- end
70
-
71
- def test_create
72
- stub_request(:post, /customerPayments/)
73
- .to_return(
74
- status: 200,
75
- body: {
76
- id: 1,
77
- lineNumber: 1,
78
- customerId: 1,
79
- customerNumber: '789'
80
- }.to_json
81
- )
82
-
83
- response = @customer_payment.create(
84
- customer_number: '789'
85
- )
86
- assert_equal response[:customer_number], '789'
87
- end
88
-
89
- def test_update
90
- test_id = '2'
91
- stub_request(:get, /customerPayments\(#{test_id}\)/)
92
- .to_return(
93
- status: 200,
94
- body: {
95
- etag: '3333',
96
- id: test_id,
97
- lineNumber: 1,
98
- customerId: 1,
99
- customerNumber: '789'
100
- }.to_json
101
- )
102
-
103
- stub_request(:patch, /customerPayments\(#{test_id}\)/)
104
- .to_return(
105
- status: 200,
106
- body: {
107
- etag: '4444',
108
- id: test_id,
109
- lineNumber: 1,
110
- customerId: 1,
111
- customerNumber: '1011'
112
- }.to_json
113
- )
114
-
115
- response = @customer_payment.update(
116
- test_id,
117
- customer_number: '1011'
118
- )
119
- assert_equal response[:customer_number], '1011'
120
- end
121
-
122
- def test_delete
123
- test_id = '33333'
124
- stub_request(:get, /customerPayments\(#{test_id}\)/)
125
- .to_return(
126
- status: 200,
127
- body: {
128
- etag: '5555',
129
- id: test_id,
130
- lineNumber: 1,
131
- customerId: 1,
132
- customerNumber: '1213'
133
- }.to_json
134
- )
135
-
136
- stub_request(:delete, /customerPayments\(#{test_id}\)/)
137
- .to_return(status: 204)
138
-
139
- assert @customer_payment.destroy(test_id)
140
- end
141
- end
@@ -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