business-central 1.0.0 → 1.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +58 -15
- data/lib/business_central.rb +52 -2
- data/lib/business_central/client.rb +87 -39
- data/lib/business_central/exceptions.rb +30 -10
- data/lib/business_central/object/account.rb +4 -2
- data/lib/business_central/object/aged_account_payable.rb +13 -0
- data/lib/business_central/object/aged_account_receivable.rb +13 -0
- data/lib/business_central/object/argument_helper.rb +22 -0
- data/lib/business_central/object/attachment.rb +30 -0
- data/lib/business_central/object/balance_sheet.rb +13 -0
- data/lib/business_central/object/base.rb +100 -49
- data/lib/business_central/object/cash_flow_statement.rb +13 -0
- data/lib/business_central/object/company.rb +9 -2
- data/lib/business_central/object/company_information.rb +14 -0
- data/lib/business_central/object/country_region.rb +26 -0
- data/lib/business_central/object/currency.rb +29 -0
- data/lib/business_central/object/customer.rb +34 -0
- data/lib/business_central/object/customer_financial_detail.rb +13 -0
- data/lib/business_central/object/customer_payment.rb +43 -0
- data/lib/business_central/object/customer_payment_journal.rb +25 -0
- data/lib/business_central/object/customer_sale.rb +13 -0
- data/lib/business_central/object/default_dimension.rb +51 -0
- data/lib/business_central/object/dimension.rb +20 -0
- data/lib/business_central/object/dimension_line.rb +37 -0
- data/lib/business_central/object/dimension_value.rb +28 -0
- data/lib/business_central/object/employee.rb +21 -0
- data/lib/business_central/object/filter_query.rb +18 -0
- data/lib/business_central/object/general_ledger_entry.rb +13 -0
- data/lib/business_central/object/income_statement.rb +13 -0
- data/lib/business_central/object/irs1099_code.rb +16 -0
- data/lib/business_central/object/item.rb +16 -19
- data/lib/business_central/object/item_category.rb +16 -0
- data/lib/business_central/object/journal.rb +29 -0
- data/lib/business_central/object/journal_line.rb +48 -0
- data/lib/business_central/object/object_helper.rb +49 -0
- data/lib/business_central/object/payment_method.rb +16 -0
- data/lib/business_central/object/payment_term.rb +16 -0
- data/lib/business_central/object/picture.rb +53 -0
- data/lib/business_central/object/purchase_invoice.rb +8 -16
- data/lib/business_central/object/purchase_invoice_line.rb +14 -18
- data/lib/business_central/object/request.rb +61 -50
- data/lib/business_central/object/response.rb +28 -22
- data/lib/business_central/object/retained_earning_statement.rb +13 -0
- data/lib/business_central/object/sales_credit_memo.rb +20 -0
- data/lib/business_central/object/sales_credit_memo_line.rb +30 -0
- data/lib/business_central/object/sales_invoice.rb +62 -0
- data/lib/business_central/object/sales_invoice_line.rb +30 -0
- data/lib/business_central/object/sales_order.rb +20 -0
- data/lib/business_central/object/sales_order_line.rb +30 -0
- data/lib/business_central/object/sales_quote.rb +20 -0
- data/lib/business_central/object/sales_quote_line.rb +30 -0
- data/lib/business_central/object/shipment_method.rb +16 -0
- data/lib/business_central/object/subscription.rb +16 -0
- data/lib/business_central/object/tax_area.rb +16 -0
- data/lib/business_central/object/tax_group.rb +16 -0
- data/lib/business_central/object/time_registration_entry.rb +16 -0
- data/lib/business_central/object/trial_balance.rb +13 -0
- data/lib/business_central/object/units_of_measure.rb +16 -0
- data/lib/business_central/object/url_builder.rb +59 -0
- data/lib/business_central/object/url_helper.rb +32 -0
- data/lib/business_central/object/validation.rb +11 -8
- data/lib/business_central/object/vendor.rb +12 -15
- data/lib/business_central/object/vendor_purchase.rb +13 -0
- data/lib/business_central/version.rb +4 -2
- data/lib/business_central/web_service.rb +78 -0
- data/lib/core_ext/string.rb +18 -12
- data/test/business_central/client_test.rb +49 -7
- data/test/business_central/object/account_test.rb +24 -5
- data/test/business_central/object/aged_account_payable_test.rb +61 -0
- data/test/business_central/object/aged_account_receivable_test.rb +61 -0
- data/test/business_central/object/attachment_test.rb +117 -0
- data/test/business_central/object/balance_sheet_test.rb +61 -0
- data/test/business_central/object/base_test.rb +41 -0
- data/test/business_central/object/cash_flow_statement_test.rb +61 -0
- data/test/business_central/object/company_information_test.rb +81 -0
- data/test/business_central/object/company_test.rb +24 -11
- data/test/business_central/object/country_region_test.rb +129 -0
- data/test/business_central/object/currency_test.rb +150 -0
- data/test/business_central/object/customer_financial_detail_test.rb +68 -0
- data/test/business_central/object/customer_payment_journal_test.rb +134 -0
- data/test/business_central/object/customer_payment_test.rb +141 -0
- data/test/business_central/object/customer_sale_test.rb +72 -0
- data/test/business_central/object/customer_test.rb +168 -0
- data/test/business_central/object/default_dimension_test.rb +170 -0
- data/test/business_central/object/dimension_line_test.rb +165 -0
- data/test/business_central/object/dimension_test.rb +65 -0
- data/test/business_central/object/dimension_value_test.rb +68 -0
- data/test/business_central/object/employee_test.rb +141 -0
- data/test/business_central/object/filter_query_test.rb +36 -0
- data/test/business_central/object/general_ledger_entry_test.rb +82 -0
- data/test/business_central/object/income_statement_test.rb +82 -0
- data/test/business_central/object/irs1099_code_test.rb +124 -0
- data/test/business_central/object/item_category_test.rb +122 -0
- data/test/business_central/object/item_test.rb +16 -23
- data/test/business_central/object/journal_line_test.rb +152 -0
- data/test/business_central/object/journal_test.rb +144 -0
- data/test/business_central/object/payment_method_test.rb +134 -0
- data/test/business_central/object/payment_term_test.rb +134 -0
- data/test/business_central/object/picture_test.rb +74 -0
- data/test/business_central/object/purchase_invoice_line_test.rb +15 -21
- data/test/business_central/object/purchase_invoice_test.rb +15 -21
- data/test/business_central/object/request_test.rb +75 -18
- data/test/business_central/object/response_test.rb +29 -9
- data/test/business_central/object/retained_earning_statement_test.rb +52 -0
- data/test/business_central/object/sales_credit_memo_line_test.rb +134 -0
- data/test/business_central/object/sales_credit_memo_test.rb +146 -0
- data/test/business_central/object/sales_invoice_line_test.rb +164 -0
- data/test/business_central/object/sales_invoice_test.rb +156 -0
- data/test/business_central/object/sales_order_line_test.rb +134 -0
- data/test/business_central/object/sales_order_test.rb +146 -0
- data/test/business_central/object/sales_quote_line_test.rb +134 -0
- data/test/business_central/object/sales_quote_test.rb +146 -0
- data/test/business_central/object/shipment_method_test.rb +133 -0
- data/test/business_central/object/subscription_test.rb +126 -0
- data/test/business_central/object/tax_area_test.rb +126 -0
- data/test/business_central/object/tax_group_test.rb +126 -0
- data/test/business_central/object/time_registration_entry_test.rb +126 -0
- data/test/business_central/object/trial_balance_test.rb +82 -0
- data/test/business_central/object/units_of_measure_test.rb +126 -0
- data/test/business_central/object/validation_test.rb +5 -4
- data/test/business_central/object/vendor_purchase_test.rb +82 -0
- data/test/business_central/object/vendor_test.rb +16 -22
- data/test/business_central/web_service_test.rb +95 -0
- data/test/business_central_test.rb +3 -1
- data/test/test_helper.rb +16 -6
- metadata +199 -33
- data/lib/business_central/object/helper.rb +0 -15
@@ -0,0 +1,74 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
# rake test TEST=test/business_central/object/picture_test.rb
|
5
|
+
|
6
|
+
class BusinessCentral::Object::PictureTest < Minitest::Test
|
7
|
+
def setup
|
8
|
+
@company_id = '123456'
|
9
|
+
@client = BusinessCentral::Client.new
|
10
|
+
@picture = @client.picture(parent: 'vendors', parent_id: '123', company_id: @company_id)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_find_all
|
14
|
+
stub_request(:get, /picture/)
|
15
|
+
.to_return(
|
16
|
+
status: 200,
|
17
|
+
body: {
|
18
|
+
'value': [
|
19
|
+
{
|
20
|
+
id: 112,
|
21
|
+
width: 500,
|
22
|
+
height: 496,
|
23
|
+
contentType: 'image\jpeg'
|
24
|
+
}
|
25
|
+
]
|
26
|
+
}.to_json
|
27
|
+
)
|
28
|
+
|
29
|
+
response = @picture.find_all
|
30
|
+
assert_equal response.first[:content_type], 'image\jpeg'
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_create
|
34
|
+
stub_request(:patch, /picture/)
|
35
|
+
.to_return(status: 204)
|
36
|
+
|
37
|
+
response = @picture.create('ImageData')
|
38
|
+
assert response
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_update
|
42
|
+
stub_request(:get, /picture/)
|
43
|
+
.to_return(
|
44
|
+
status: 200,
|
45
|
+
body: {
|
46
|
+
etag: '112',
|
47
|
+
contentType: 'image\jpeg'
|
48
|
+
}.to_json
|
49
|
+
)
|
50
|
+
|
51
|
+
stub_request(:patch, /picture/)
|
52
|
+
.to_return(status: 204)
|
53
|
+
|
54
|
+
response = @picture.update('ImageData')
|
55
|
+
assert response
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_delete
|
59
|
+
test_id = 2
|
60
|
+
stub_request(:get, /picture/)
|
61
|
+
.to_return(
|
62
|
+
status: 200,
|
63
|
+
body: {
|
64
|
+
etag: '113',
|
65
|
+
contentType: 'image\jpeg'
|
66
|
+
}.to_json
|
67
|
+
)
|
68
|
+
|
69
|
+
stub_request(:delete, /picture/)
|
70
|
+
.to_return(status: 204)
|
71
|
+
|
72
|
+
assert @picture.destroy(test_id)
|
73
|
+
end
|
74
|
+
end
|
@@ -1,4 +1,6 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
2
4
|
# rake test TEST=test/business_central/object/purchase_invoice_line_test.rb
|
3
5
|
|
4
6
|
class BusinessCentral::Object::PurchaseInvoiceLineTest < Minitest::Test
|
@@ -6,12 +8,6 @@ class BusinessCentral::Object::PurchaseInvoiceLineTest < Minitest::Test
|
|
6
8
|
@company_id = '123456'
|
7
9
|
@purchase_invoice_id = '789456'
|
8
10
|
@client = BusinessCentral::Client.new
|
9
|
-
@client.authorize_from_token(
|
10
|
-
token: '123',
|
11
|
-
refresh_token: '456',
|
12
|
-
expires_at: Time.now + 3600,
|
13
|
-
expires_in: 3600
|
14
|
-
)
|
15
11
|
@purchase_invoice_line = @client.purchase_invoice_line(
|
16
12
|
company_id: @company_id,
|
17
13
|
purchase_invoice_id: @purchase_invoice_id
|
@@ -21,14 +17,14 @@ class BusinessCentral::Object::PurchaseInvoiceLineTest < Minitest::Test
|
|
21
17
|
def test_find_all
|
22
18
|
stub_request(:get, /purchaseInvoiceLines/)
|
23
19
|
.to_return(
|
24
|
-
status: 200,
|
20
|
+
status: 200,
|
25
21
|
body: {
|
26
22
|
'value': [
|
27
23
|
{
|
28
24
|
description: 'po line 1'
|
29
25
|
}
|
30
26
|
]
|
31
|
-
}.to_json
|
27
|
+
}.to_json
|
32
28
|
)
|
33
29
|
|
34
30
|
response = @purchase_invoice_line.find_all
|
@@ -39,7 +35,7 @@ class BusinessCentral::Object::PurchaseInvoiceLineTest < Minitest::Test
|
|
39
35
|
test_purchase_invoice_line_id = '09876'
|
40
36
|
stub_request(:get, /purchaseInvoiceLines\(#{test_purchase_invoice_line_id}\)/)
|
41
37
|
.to_return(
|
42
|
-
status: 200,
|
38
|
+
status: 200,
|
43
39
|
body: {
|
44
40
|
description: 'po line 2'
|
45
41
|
}.to_json
|
@@ -53,7 +49,7 @@ class BusinessCentral::Object::PurchaseInvoiceLineTest < Minitest::Test
|
|
53
49
|
test_filter = "description eq 'po line 3'"
|
54
50
|
stub_request(:get, /purchaseInvoiceLines\?\$filter=#{test_filter}/)
|
55
51
|
.to_return(
|
56
|
-
status: 200,
|
52
|
+
status: 200,
|
57
53
|
body: {
|
58
54
|
'value': [
|
59
55
|
{
|
@@ -70,15 +66,15 @@ class BusinessCentral::Object::PurchaseInvoiceLineTest < Minitest::Test
|
|
70
66
|
def test_create
|
71
67
|
stub_request(:post, /purchaseInvoiceLines/)
|
72
68
|
.to_return(
|
73
|
-
status: 200,
|
69
|
+
status: 200,
|
74
70
|
body: {
|
75
71
|
description: 'po line 4'
|
76
72
|
}.to_json
|
77
73
|
)
|
78
74
|
|
79
|
-
response = @purchase_invoice_line.create(
|
75
|
+
response = @purchase_invoice_line.create(
|
80
76
|
description: 'po line 4'
|
81
|
-
|
77
|
+
)
|
82
78
|
assert_equal response[:description], 'po line 4'
|
83
79
|
end
|
84
80
|
|
@@ -86,7 +82,7 @@ class BusinessCentral::Object::PurchaseInvoiceLineTest < Minitest::Test
|
|
86
82
|
test_purchase_invoice_line_id = '011123'
|
87
83
|
stub_request(:get, /purchaseInvoiceLines\(#{test_purchase_invoice_line_id}\)/)
|
88
84
|
.to_return(
|
89
|
-
status: 200,
|
85
|
+
status: 200,
|
90
86
|
body: {
|
91
87
|
etag: '112',
|
92
88
|
description: 'po line 5'
|
@@ -95,7 +91,7 @@ class BusinessCentral::Object::PurchaseInvoiceLineTest < Minitest::Test
|
|
95
91
|
|
96
92
|
stub_request(:patch, /purchaseInvoiceLines\(#{test_purchase_invoice_line_id}\)/)
|
97
93
|
.to_return(
|
98
|
-
status: 200,
|
94
|
+
status: 200,
|
99
95
|
body: {
|
100
96
|
description: 'po line 6'
|
101
97
|
}.to_json
|
@@ -103,9 +99,7 @@ class BusinessCentral::Object::PurchaseInvoiceLineTest < Minitest::Test
|
|
103
99
|
|
104
100
|
response = @purchase_invoice_line.update(
|
105
101
|
test_purchase_invoice_line_id,
|
106
|
-
|
107
|
-
description: 'po line 6'
|
108
|
-
}
|
102
|
+
description: 'po line 6'
|
109
103
|
)
|
110
104
|
assert_equal response[:description], 'po line 6'
|
111
105
|
end
|
@@ -114,7 +108,7 @@ class BusinessCentral::Object::PurchaseInvoiceLineTest < Minitest::Test
|
|
114
108
|
test_purchase_invoice_line_id = '0111245'
|
115
109
|
stub_request(:get, /purchaseInvoiceLines\(#{test_purchase_invoice_line_id}\)/)
|
116
110
|
.to_return(
|
117
|
-
status: 200,
|
111
|
+
status: 200,
|
118
112
|
body: {
|
119
113
|
etag: '113',
|
120
114
|
description: 'po line 6'
|
@@ -126,4 +120,4 @@ class BusinessCentral::Object::PurchaseInvoiceLineTest < Minitest::Test
|
|
126
120
|
|
127
121
|
assert @purchase_invoice_line.destroy(test_purchase_invoice_line_id)
|
128
122
|
end
|
129
|
-
end
|
123
|
+
end
|
@@ -1,30 +1,26 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
2
4
|
# rake test TEST=test/business_central/object/purchase_invoice_test.rb
|
3
5
|
|
4
6
|
class BusinessCentral::Object::PurchaseInvoiceTest < Minitest::Test
|
5
7
|
def setup
|
6
8
|
@company_id = '123456'
|
7
9
|
@client = BusinessCentral::Client.new
|
8
|
-
@client.authorize_from_token(
|
9
|
-
token: '123',
|
10
|
-
refresh_token: '456',
|
11
|
-
expires_at: Time.now + 3600,
|
12
|
-
expires_in: 3600
|
13
|
-
)
|
14
10
|
@purchase_invoice = @client.purchase_invoice(company_id: @company_id)
|
15
11
|
end
|
16
12
|
|
17
13
|
def test_find_all
|
18
14
|
stub_request(:get, /purchaseInvoices/)
|
19
15
|
.to_return(
|
20
|
-
status: 200,
|
16
|
+
status: 200,
|
21
17
|
body: {
|
22
18
|
'value': [
|
23
19
|
{
|
24
20
|
displayName: 'po1'
|
25
21
|
}
|
26
22
|
]
|
27
|
-
}.to_json
|
23
|
+
}.to_json
|
28
24
|
)
|
29
25
|
|
30
26
|
response = @purchase_invoice.find_all
|
@@ -35,7 +31,7 @@ class BusinessCentral::Object::PurchaseInvoiceTest < Minitest::Test
|
|
35
31
|
test_purchase_invoice_id = '09876'
|
36
32
|
stub_request(:get, /purchaseInvoices\(#{test_purchase_invoice_id}\)/)
|
37
33
|
.to_return(
|
38
|
-
status: 200,
|
34
|
+
status: 200,
|
39
35
|
body: {
|
40
36
|
displayName: 'po2'
|
41
37
|
}.to_json
|
@@ -49,7 +45,7 @@ class BusinessCentral::Object::PurchaseInvoiceTest < Minitest::Test
|
|
49
45
|
test_filter = "displayName eq 'po3'"
|
50
46
|
stub_request(:get, /purchaseInvoices\?\$filter=#{test_filter}/)
|
51
47
|
.to_return(
|
52
|
-
status: 200,
|
48
|
+
status: 200,
|
53
49
|
body: {
|
54
50
|
'value': [
|
55
51
|
{
|
@@ -66,15 +62,15 @@ class BusinessCentral::Object::PurchaseInvoiceTest < Minitest::Test
|
|
66
62
|
def test_create
|
67
63
|
stub_request(:post, /purchaseInvoices/)
|
68
64
|
.to_return(
|
69
|
-
status: 200,
|
65
|
+
status: 200,
|
70
66
|
body: {
|
71
67
|
displayName: 'po4'
|
72
68
|
}.to_json
|
73
69
|
)
|
74
70
|
|
75
|
-
response = @purchase_invoice.create(
|
71
|
+
response = @purchase_invoice.create(
|
76
72
|
display_name: 'po4'
|
77
|
-
|
73
|
+
)
|
78
74
|
assert_equal response[:display_name], 'po4'
|
79
75
|
end
|
80
76
|
|
@@ -82,7 +78,7 @@ class BusinessCentral::Object::PurchaseInvoiceTest < Minitest::Test
|
|
82
78
|
test_purchase_invoice_id = '011123'
|
83
79
|
stub_request(:get, /purchaseInvoices\(#{test_purchase_invoice_id}\)/)
|
84
80
|
.to_return(
|
85
|
-
status: 200,
|
81
|
+
status: 200,
|
86
82
|
body: {
|
87
83
|
etag: '112',
|
88
84
|
displayName: 'po5'
|
@@ -91,7 +87,7 @@ class BusinessCentral::Object::PurchaseInvoiceTest < Minitest::Test
|
|
91
87
|
|
92
88
|
stub_request(:patch, /purchaseInvoices\(#{test_purchase_invoice_id}\)/)
|
93
89
|
.to_return(
|
94
|
-
status: 200,
|
90
|
+
status: 200,
|
95
91
|
body: {
|
96
92
|
displayName: 'po6'
|
97
93
|
}.to_json
|
@@ -99,9 +95,7 @@ class BusinessCentral::Object::PurchaseInvoiceTest < Minitest::Test
|
|
99
95
|
|
100
96
|
response = @purchase_invoice.update(
|
101
97
|
test_purchase_invoice_id,
|
102
|
-
|
103
|
-
display_name: 'po6'
|
104
|
-
}
|
98
|
+
display_name: 'po6'
|
105
99
|
)
|
106
100
|
assert_equal response[:display_name], 'po6'
|
107
101
|
end
|
@@ -110,7 +104,7 @@ class BusinessCentral::Object::PurchaseInvoiceTest < Minitest::Test
|
|
110
104
|
test_purchase_invoice_id = '0111245'
|
111
105
|
stub_request(:get, /purchaseInvoices\(#{test_purchase_invoice_id}\)/)
|
112
106
|
.to_return(
|
113
|
-
status: 200,
|
107
|
+
status: 200,
|
114
108
|
body: {
|
115
109
|
etag: '113',
|
116
110
|
displayName: 'po7'
|
@@ -122,4 +116,4 @@ class BusinessCentral::Object::PurchaseInvoiceTest < Minitest::Test
|
|
122
116
|
|
123
117
|
assert @purchase_invoice.destroy(test_purchase_invoice_id)
|
124
118
|
end
|
125
|
-
end
|
119
|
+
end
|
@@ -1,29 +1,25 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
2
4
|
# rake test TEST=test/business_central/object/request_test.rb
|
3
5
|
|
4
6
|
class BusinessCentral::Object::RequestTest < Minitest::Test
|
5
7
|
def setup
|
6
8
|
@url = BusinessCentral::Client::DEFAULT_URL
|
7
9
|
@client = BusinessCentral::Client.new
|
8
|
-
@client.authorize_from_token(
|
9
|
-
token: '123',
|
10
|
-
refresh_token: '456',
|
11
|
-
expires_at: Time.now + 3600,
|
12
|
-
expires_in: 3600
|
13
|
-
)
|
14
10
|
end
|
15
11
|
|
16
12
|
def test_get_request
|
17
13
|
stub_request(:get, @url)
|
18
14
|
.to_return(
|
19
|
-
status: 200,
|
15
|
+
status: 200,
|
20
16
|
body: {
|
21
17
|
'value': [
|
22
18
|
{
|
23
19
|
displayName: 'value1'
|
24
20
|
}
|
25
21
|
]
|
26
|
-
}.to_json
|
22
|
+
}.to_json
|
27
23
|
)
|
28
24
|
|
29
25
|
response = BusinessCentral::Object::Request.get(@client, @url)
|
@@ -34,17 +30,17 @@ class BusinessCentral::Object::RequestTest < Minitest::Test
|
|
34
30
|
def test_post_request
|
35
31
|
stub_request(:post, @url)
|
36
32
|
.to_return(
|
37
|
-
status: 200,
|
33
|
+
status: 200,
|
38
34
|
body: {
|
39
35
|
'value': [
|
40
36
|
{
|
41
37
|
displayName: 'value2'
|
42
38
|
}
|
43
39
|
]
|
44
|
-
}.to_json
|
40
|
+
}.to_json
|
45
41
|
)
|
46
42
|
|
47
|
-
response = BusinessCentral::Object::Request.post(@client, @url,
|
43
|
+
response = BusinessCentral::Object::Request.post(@client, @url, display_name: 'value2')
|
48
44
|
|
49
45
|
assert_equal 'value2', response.first[:display_name]
|
50
46
|
end
|
@@ -52,17 +48,17 @@ class BusinessCentral::Object::RequestTest < Minitest::Test
|
|
52
48
|
def test_patch_request
|
53
49
|
stub_request(:patch, @url)
|
54
50
|
.to_return(
|
55
|
-
status: 200,
|
51
|
+
status: 200,
|
56
52
|
body: {
|
57
53
|
'value': [
|
58
54
|
{
|
59
55
|
displayName: 'value3'
|
60
56
|
}
|
61
57
|
]
|
62
|
-
}.to_json
|
58
|
+
}.to_json
|
63
59
|
)
|
64
60
|
|
65
|
-
response = BusinessCentral::Object::Request.patch(@client, @url, '1',
|
61
|
+
response = BusinessCentral::Object::Request.patch(@client, @url, '1', display_name: 'value3')
|
66
62
|
|
67
63
|
assert_equal 'value3', response.first[:display_name]
|
68
64
|
end
|
@@ -74,9 +70,70 @@ class BusinessCentral::Object::RequestTest < Minitest::Test
|
|
74
70
|
assert BusinessCentral::Object::Request.delete(@client, @url, '1')
|
75
71
|
end
|
76
72
|
|
77
|
-
def
|
73
|
+
def test_request_convert_symbol_parameters
|
78
74
|
param = { new_key: 'value' }
|
79
75
|
request = JSON.parse(BusinessCentral::Object::Request.convert(param))
|
80
|
-
assert request.
|
76
|
+
assert request.key?('newKey')
|
77
|
+
end
|
78
|
+
|
79
|
+
def test_skip_request_converting_string_parameters
|
80
|
+
param = { 'New_Key' => 'value' }
|
81
|
+
request = JSON.parse(BusinessCentral::Object::Request.convert(param))
|
82
|
+
assert request.key?('New_Key')
|
83
|
+
end
|
84
|
+
|
85
|
+
def test_get_request_returns_unathorized_error
|
86
|
+
stub_request(:get, @url)
|
87
|
+
.to_return(status: 401)
|
88
|
+
|
89
|
+
assert_raises(BusinessCentral::UnauthorizedException) do
|
90
|
+
BusinessCentral::Object::Request.get(@client, @url)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_get_request_returns_error_company_not_found
|
95
|
+
stub_request(:get, @url)
|
96
|
+
.to_return(
|
97
|
+
status: 400,
|
98
|
+
body: {
|
99
|
+
error: {
|
100
|
+
code: 'Internal_CompanyNotFound'
|
101
|
+
}
|
102
|
+
}.to_json
|
103
|
+
)
|
104
|
+
|
105
|
+
assert_raises(BusinessCentral::CompanyNotFoundException) do
|
106
|
+
BusinessCentral::Object::Request.get(@client, @url)
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
def test_get_request_returns_error_code
|
111
|
+
stub_request(:get, @url)
|
112
|
+
.to_return(
|
113
|
+
status: 400,
|
114
|
+
body: {
|
115
|
+
error: {
|
116
|
+
code: 'Not_Catered_For'
|
117
|
+
}
|
118
|
+
}.to_json
|
119
|
+
)
|
120
|
+
|
121
|
+
assert_raises(BusinessCentral::ApiException) do
|
122
|
+
BusinessCentral::Object::Request.get(@client, @url)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
def test_get_request_returns_error_with_no_code
|
127
|
+
stub_request(:get, @url)
|
128
|
+
.to_return(
|
129
|
+
status: 400,
|
130
|
+
body: {
|
131
|
+
nope: 'wup wup'
|
132
|
+
}.to_json
|
133
|
+
)
|
134
|
+
|
135
|
+
assert_raises(BusinessCentral::ApiException) do
|
136
|
+
BusinessCentral::Object::Request.get(@client, @url)
|
137
|
+
end
|
81
138
|
end
|
82
|
-
end
|
139
|
+
end
|