business-central 1.0.3 → 1.0.7
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/client.rb +71 -41
- data/lib/business_central/exceptions.rb +19 -9
- data/lib/business_central/object/account.rb +4 -2
- data/lib/business_central/object/aged_account_payable.rb +4 -2
- data/lib/business_central/object/aged_account_receivable.rb +4 -2
- 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 +4 -2
- data/lib/business_central/object/base.rb +90 -56
- data/lib/business_central/object/cash_flow_statement.rb +4 -2
- data/lib/business_central/object/company.rb +5 -3
- data/lib/business_central/object/company_information.rb +7 -5
- data/lib/business_central/object/country_region.rb +8 -6
- data/lib/business_central/object/currency.rb +8 -6
- data/lib/business_central/object/customer.rb +16 -9
- data/lib/business_central/object/customer_financial_detail.rb +3 -1
- data/lib/business_central/object/customer_payment.rb +8 -6
- data/lib/business_central/object/customer_payment_journal.rb +8 -6
- data/lib/business_central/object/customer_sale.rb +3 -1
- data/lib/business_central/object/default_dimension.rb +18 -21
- 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 +17 -10
- 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/{helper.rb → object_helper.rb} +18 -10
- 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 -6
- data/lib/business_central/object/purchase_invoice_line.rb +10 -8
- data/lib/business_central/object/purchase_order.rb +16 -0
- data/lib/business_central/object/request.rb +60 -49
- data/lib/business_central/object/response.rb +31 -23
- 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 +44 -0
- data/lib/business_central/object/validation.rb +10 -7
- data/lib/business_central/object/vendor.rb +10 -7
- 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/business_central.rb +40 -2
- data/lib/core_ext/string.rb +18 -12
- data/test/business_central/client_test.rb +18 -11
- data/test/business_central/object/account_test.rb +6 -5
- data/test/business_central/object/aged_account_payable_test.rb +6 -5
- data/test/business_central/object/aged_account_receivable_test.rb +6 -5
- data/test/business_central/object/attachment_test.rb +117 -0
- data/test/business_central/object/balance_sheet_test.rb +6 -5
- data/test/business_central/object/base_test.rb +4 -2
- data/test/business_central/object/cash_flow_statement_test.rb +6 -5
- data/test/business_central/object/company_information_test.rb +9 -10
- data/test/business_central/object/company_test.rb +6 -5
- data/test/business_central/object/country_region_test.rb +16 -17
- data/test/business_central/object/currency_test.rb +17 -18
- data/test/business_central/object/customer_financial_detail_test.rb +8 -6
- data/test/business_central/object/customer_payment_journal_test.rb +14 -15
- data/test/business_central/object/customer_payment_test.rb +15 -16
- data/test/business_central/object/customer_sale_test.rb +8 -6
- data/test/business_central/object/customer_test.rb +59 -16
- data/test/business_central/object/default_dimension_test.rb +15 -16
- 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 -17
- 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 -15
- data/test/business_central/object/purchase_invoice_test.rb +15 -15
- data/test/business_central/object/request_test.rb +17 -9
- data/test/business_central/object/response_test.rb +14 -7
- 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 -16
- data/test/business_central/web_service_test.rb +100 -0
- data/test/business_central_test.rb +3 -1
- data/test/test_helper.rb +12 -6
- metadata +153 -41
@@ -0,0 +1,124 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
# rake test TEST=test/business_central/object/irs1099_code_test.rb
|
5
|
+
|
6
|
+
class BusinessCentral::Object::Irs1099CodeTest < Minitest::Test
|
7
|
+
def setup
|
8
|
+
@company_id = '123456'
|
9
|
+
@client = BusinessCentral::Client.new
|
10
|
+
@irs1099_code = @client.irs1099_code(company_id: @company_id)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_find_all
|
14
|
+
stub_request(:get, /irs1099Codes/)
|
15
|
+
.to_return(
|
16
|
+
status: 200,
|
17
|
+
body: {
|
18
|
+
'value': [
|
19
|
+
{
|
20
|
+
id: 1,
|
21
|
+
displayName: 'code1'
|
22
|
+
}
|
23
|
+
]
|
24
|
+
}.to_json
|
25
|
+
)
|
26
|
+
|
27
|
+
response = @irs1099_code.find_all
|
28
|
+
assert_equal response.first[:display_name], 'code1'
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_find_by_id
|
32
|
+
test_id = '2'
|
33
|
+
stub_request(:get, /irs1099Codes\(#{test_id}\)/)
|
34
|
+
.to_return(
|
35
|
+
status: 200,
|
36
|
+
body: {
|
37
|
+
id: test_id,
|
38
|
+
displayName: 'code2'
|
39
|
+
}.to_json
|
40
|
+
)
|
41
|
+
|
42
|
+
response = @irs1099_code.find_by_id(test_id)
|
43
|
+
assert_equal response[:display_name], 'code2'
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_where
|
47
|
+
test_filter = "displayName eq 'customer3'"
|
48
|
+
stub_request(:get, /irs1099Codes\?\$filter=#{test_filter}/)
|
49
|
+
.to_return(
|
50
|
+
status: 200,
|
51
|
+
body: {
|
52
|
+
'value': [
|
53
|
+
{
|
54
|
+
id: 3,
|
55
|
+
displayName: 'code3'
|
56
|
+
}
|
57
|
+
]
|
58
|
+
}.to_json
|
59
|
+
)
|
60
|
+
|
61
|
+
response = @irs1099_code.where(test_filter)
|
62
|
+
assert_equal response.first[:display_name], 'code3'
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_create
|
66
|
+
stub_request(:post, /irs1099Codes/)
|
67
|
+
.to_return(
|
68
|
+
status: 200,
|
69
|
+
body: {
|
70
|
+
displayName: 'code4'
|
71
|
+
}.to_json
|
72
|
+
)
|
73
|
+
|
74
|
+
response = @irs1099_code.create(
|
75
|
+
display_name: 'code4'
|
76
|
+
)
|
77
|
+
assert_equal response[:display_name], 'code4'
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_update
|
81
|
+
test_id = '2'
|
82
|
+
stub_request(:get, /irs1099Codes\(#{test_id}\)/)
|
83
|
+
.to_return(
|
84
|
+
status: 200,
|
85
|
+
body: {
|
86
|
+
etag: '3333',
|
87
|
+
id: test_id,
|
88
|
+
displayName: 'code5'
|
89
|
+
}.to_json
|
90
|
+
)
|
91
|
+
|
92
|
+
stub_request(:patch, /irs1099Codes\(#{test_id}\)/)
|
93
|
+
.to_return(
|
94
|
+
status: 200,
|
95
|
+
body: {
|
96
|
+
etag: '4444',
|
97
|
+
displayName: 'code6'
|
98
|
+
}.to_json
|
99
|
+
)
|
100
|
+
|
101
|
+
response = @irs1099_code.update(
|
102
|
+
test_id,
|
103
|
+
display_name: 'code6'
|
104
|
+
)
|
105
|
+
assert_equal response[:display_name], 'code6'
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_delete
|
109
|
+
test_id = '33333'
|
110
|
+
stub_request(:get, /irs1099Codes\(#{test_id}\)/)
|
111
|
+
.to_return(
|
112
|
+
status: 200,
|
113
|
+
body: {
|
114
|
+
etag: '5555',
|
115
|
+
displayName: 'code7'
|
116
|
+
}.to_json
|
117
|
+
)
|
118
|
+
|
119
|
+
stub_request(:delete, /irs1099Codes\(#{test_id}\)/)
|
120
|
+
.to_return(status: 204)
|
121
|
+
|
122
|
+
assert @irs1099_code.destroy(test_id)
|
123
|
+
end
|
124
|
+
end
|
@@ -0,0 +1,122 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
# rake test TEST=test/business_central/object/item_category_test.rb
|
5
|
+
|
6
|
+
class BusinessCentral::Object::ItemCategoryTest < Minitest::Test
|
7
|
+
def setup
|
8
|
+
@company_id = '123456'
|
9
|
+
@client = BusinessCentral::Client.new
|
10
|
+
@item_category = @client.item_category(company_id: @company_id)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_find_all
|
14
|
+
stub_request(:get, /itemCategories/)
|
15
|
+
.to_return(
|
16
|
+
status: 200,
|
17
|
+
body: {
|
18
|
+
'value': [
|
19
|
+
{
|
20
|
+
code: '123',
|
21
|
+
displayName: 'item_category1'
|
22
|
+
}
|
23
|
+
]
|
24
|
+
}.to_json
|
25
|
+
)
|
26
|
+
|
27
|
+
response = @item_category.find_all
|
28
|
+
assert_equal response.first[:display_name], 'item_category1'
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_find_by_id
|
32
|
+
test_item_category_id = '345'
|
33
|
+
stub_request(:get, /itemCategories\(#{test_item_category_id}\)/)
|
34
|
+
.to_return(
|
35
|
+
status: 200,
|
36
|
+
body: {
|
37
|
+
id: test_item_category_id,
|
38
|
+
displayName: 'item_category2'
|
39
|
+
}.to_json
|
40
|
+
)
|
41
|
+
|
42
|
+
response = @item_category.find_by_id(test_item_category_id)
|
43
|
+
assert_equal response[:display_name], 'item_category2'
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_where
|
47
|
+
test_filter = "displayName eq 'item_category3'"
|
48
|
+
stub_request(:get, /itemCategories\?\$filter=#{test_filter}/)
|
49
|
+
.to_return(
|
50
|
+
status: 200,
|
51
|
+
body: {
|
52
|
+
'value': [
|
53
|
+
{
|
54
|
+
code: '678',
|
55
|
+
displayName: 'item_category3'
|
56
|
+
}
|
57
|
+
]
|
58
|
+
}.to_json
|
59
|
+
)
|
60
|
+
|
61
|
+
response = @item_category.where(test_filter)
|
62
|
+
assert_equal response.first[:display_name], 'item_category3'
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_create
|
66
|
+
stub_request(:post, /itemCategories/)
|
67
|
+
.to_return(
|
68
|
+
status: 200,
|
69
|
+
body: {
|
70
|
+
displayName: 'item_category4'
|
71
|
+
}.to_json
|
72
|
+
)
|
73
|
+
|
74
|
+
response = @item_category.create(
|
75
|
+
display_name: 'item_category4'
|
76
|
+
)
|
77
|
+
assert_equal response[:display_name], 'item_category4'
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_update
|
81
|
+
test_item_category_id = '011123'
|
82
|
+
stub_request(:get, /itemCategories\(#{test_item_category_id}\)/)
|
83
|
+
.to_return(
|
84
|
+
status: 200,
|
85
|
+
body: {
|
86
|
+
etag: '112',
|
87
|
+
displayName: 'item_category5'
|
88
|
+
}.to_json
|
89
|
+
)
|
90
|
+
|
91
|
+
stub_request(:patch, /itemCategories\(#{test_item_category_id}\)/)
|
92
|
+
.to_return(
|
93
|
+
status: 200,
|
94
|
+
body: {
|
95
|
+
displayName: 'item_category6'
|
96
|
+
}.to_json
|
97
|
+
)
|
98
|
+
|
99
|
+
response = @item_category.update(
|
100
|
+
test_item_category_id,
|
101
|
+
display_name: 'item_category6'
|
102
|
+
)
|
103
|
+
assert_equal response[:display_name], 'item_category6'
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_delete
|
107
|
+
test_item_category_id = '0111245'
|
108
|
+
stub_request(:get, /itemCategories\(#{test_item_category_id}\)/)
|
109
|
+
.to_return(
|
110
|
+
status: 200,
|
111
|
+
body: {
|
112
|
+
etag: '113',
|
113
|
+
displayName: 'item_category7'
|
114
|
+
}.to_json
|
115
|
+
)
|
116
|
+
|
117
|
+
stub_request(:delete, /itemCategories\(#{test_item_category_id}\)/)
|
118
|
+
.to_return(status: 204)
|
119
|
+
|
120
|
+
assert @item_category.destroy(test_item_category_id)
|
121
|
+
end
|
122
|
+
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/item_test.rb
|
3
5
|
|
4
6
|
class BusinessCentral::Object::ItemTest < Minitest::Test
|
@@ -11,14 +13,14 @@ class BusinessCentral::Object::ItemTest < Minitest::Test
|
|
11
13
|
def test_find_all
|
12
14
|
stub_request(:get, /items/)
|
13
15
|
.to_return(
|
14
|
-
status: 200,
|
16
|
+
status: 200,
|
15
17
|
body: {
|
16
18
|
'value': [
|
17
19
|
{
|
18
20
|
displayName: 'item1'
|
19
21
|
}
|
20
22
|
]
|
21
|
-
}.to_json
|
23
|
+
}.to_json
|
22
24
|
)
|
23
25
|
|
24
26
|
response = @item.find_all
|
@@ -29,7 +31,7 @@ class BusinessCentral::Object::ItemTest < Minitest::Test
|
|
29
31
|
test_item_id = '09876'
|
30
32
|
stub_request(:get, /items\(#{test_item_id}\)/)
|
31
33
|
.to_return(
|
32
|
-
status: 200,
|
34
|
+
status: 200,
|
33
35
|
body: {
|
34
36
|
displayName: 'item2'
|
35
37
|
}.to_json
|
@@ -43,7 +45,7 @@ class BusinessCentral::Object::ItemTest < Minitest::Test
|
|
43
45
|
test_filter = "displayName eq 'item3'"
|
44
46
|
stub_request(:get, /items\?\$filter=#{test_filter}/)
|
45
47
|
.to_return(
|
46
|
-
status: 200,
|
48
|
+
status: 200,
|
47
49
|
body: {
|
48
50
|
'value': [
|
49
51
|
{
|
@@ -60,25 +62,24 @@ class BusinessCentral::Object::ItemTest < Minitest::Test
|
|
60
62
|
def test_create
|
61
63
|
stub_request(:post, /items/)
|
62
64
|
.to_return(
|
63
|
-
status: 200,
|
65
|
+
status: 200,
|
64
66
|
body: {
|
65
67
|
displayName: 'item4'
|
66
68
|
}.to_json
|
67
69
|
)
|
68
70
|
|
69
|
-
response = @item.create(
|
71
|
+
response = @item.create(
|
70
72
|
display_name: 'item4',
|
71
73
|
type: 'Inventory'
|
72
|
-
|
74
|
+
)
|
73
75
|
assert_equal response[:display_name], 'item4'
|
74
76
|
end
|
75
77
|
|
76
|
-
|
77
78
|
def test_update
|
78
79
|
test_item_id = '011123'
|
79
80
|
stub_request(:get, /items\(#{test_item_id}\)/)
|
80
81
|
.to_return(
|
81
|
-
status: 200,
|
82
|
+
status: 200,
|
82
83
|
body: {
|
83
84
|
etag: '112',
|
84
85
|
displayName: 'item5'
|
@@ -87,7 +88,7 @@ class BusinessCentral::Object::ItemTest < Minitest::Test
|
|
87
88
|
|
88
89
|
stub_request(:patch, /items\(#{test_item_id}\)/)
|
89
90
|
.to_return(
|
90
|
-
status: 200,
|
91
|
+
status: 200,
|
91
92
|
body: {
|
92
93
|
displayName: 'item6'
|
93
94
|
}.to_json
|
@@ -95,10 +96,8 @@ class BusinessCentral::Object::ItemTest < Minitest::Test
|
|
95
96
|
|
96
97
|
response = @item.update(
|
97
98
|
test_item_id,
|
98
|
-
|
99
|
-
|
100
|
-
type: 'Inventory'
|
101
|
-
}
|
99
|
+
display_name: 'item6',
|
100
|
+
type: 'Inventory'
|
102
101
|
)
|
103
102
|
assert_equal response[:display_name], 'item6'
|
104
103
|
end
|
@@ -107,7 +106,7 @@ class BusinessCentral::Object::ItemTest < Minitest::Test
|
|
107
106
|
test_item_id = '0111245'
|
108
107
|
stub_request(:get, /items\(#{test_item_id}\)/)
|
109
108
|
.to_return(
|
110
|
-
status: 200,
|
109
|
+
status: 200,
|
111
110
|
body: {
|
112
111
|
etag: '113',
|
113
112
|
displayName: 'item7'
|
@@ -119,4 +118,4 @@ class BusinessCentral::Object::ItemTest < Minitest::Test
|
|
119
118
|
|
120
119
|
assert @item.destroy(test_item_id)
|
121
120
|
end
|
122
|
-
end
|
121
|
+
end
|
@@ -0,0 +1,152 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
# rake test TEST=test/business_central/object/journal_line_test.rb
|
5
|
+
|
6
|
+
class BusinessCentral::Object::JournalLineTest < Minitest::Test
|
7
|
+
def setup
|
8
|
+
@company_id = '123456'
|
9
|
+
@client = BusinessCentral::Client.new
|
10
|
+
@journal_line = @client.journal_line(
|
11
|
+
company_id: @company_id,
|
12
|
+
parent: 'journals',
|
13
|
+
parent_id: '123'
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_invalid_journal_line_parent
|
18
|
+
assert_raises(BusinessCentral::InvalidArgumentException) do
|
19
|
+
@client.journal_line(
|
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, %r{journals\(\d+\)\/journalLines})
|
29
|
+
.to_return(
|
30
|
+
status: 200,
|
31
|
+
body: {
|
32
|
+
'value': [
|
33
|
+
{
|
34
|
+
journalDisplayName: 'journal1',
|
35
|
+
lineNumber: 1000,
|
36
|
+
description: 'journalLine1'
|
37
|
+
}
|
38
|
+
]
|
39
|
+
}.to_json
|
40
|
+
)
|
41
|
+
|
42
|
+
response = @journal_line.find_all
|
43
|
+
assert_equal response.first[:description], 'journalLine1'
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_find_by_id
|
47
|
+
test_id = '2'
|
48
|
+
stub_request(:get, %r{journals\(\d+\)\/journalLines\(#{test_id}\)})
|
49
|
+
.to_return(
|
50
|
+
status: 200,
|
51
|
+
body: {
|
52
|
+
id: test_id,
|
53
|
+
journalDisplayName: 'journal1',
|
54
|
+
lineNumber: 2000,
|
55
|
+
description: 'journalLine2'
|
56
|
+
}.to_json
|
57
|
+
)
|
58
|
+
|
59
|
+
response = @journal_line.find_by_id(test_id)
|
60
|
+
assert_equal response[:description], 'journalLine2'
|
61
|
+
end
|
62
|
+
|
63
|
+
def test_where
|
64
|
+
test_filter = "description eq 'journalLine3'"
|
65
|
+
stub_request(:get, %r{journals\(\d+\)\/journalLines\?\$filter=#{test_filter}})
|
66
|
+
.to_return(
|
67
|
+
status: 200,
|
68
|
+
body: {
|
69
|
+
'value': [
|
70
|
+
{
|
71
|
+
id: 3,
|
72
|
+
journalDisplayName: 'journal1',
|
73
|
+
lineNumber: 3000,
|
74
|
+
description: 'journalLine3'
|
75
|
+
}
|
76
|
+
]
|
77
|
+
}.to_json
|
78
|
+
)
|
79
|
+
|
80
|
+
response = @journal_line.where(test_filter)
|
81
|
+
assert_equal response.first[:description], 'journalLine3'
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_create
|
85
|
+
stub_request(:post, %r{journals\(\d+\)\/journalLines})
|
86
|
+
.to_return(
|
87
|
+
status: 200,
|
88
|
+
body: {
|
89
|
+
id: 4,
|
90
|
+
journalDisplayName: 'journal1',
|
91
|
+
lineNumber: 4000,
|
92
|
+
description: 'journalLine4'
|
93
|
+
}.to_json
|
94
|
+
)
|
95
|
+
|
96
|
+
response = @journal_line.create(
|
97
|
+
description: 'journalLine4'
|
98
|
+
)
|
99
|
+
assert_equal response[:id], 4
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_update
|
103
|
+
test_id = '2'
|
104
|
+
stub_request(:get, %r{journals\(\d+\)\/journalLines\(#{test_id}\)})
|
105
|
+
.to_return(
|
106
|
+
status: 200,
|
107
|
+
body: {
|
108
|
+
etag: '3333',
|
109
|
+
id: test_id,
|
110
|
+
journalDisplayName: 'journal1',
|
111
|
+
lineNumber: 4000,
|
112
|
+
description: 'journalLine4'
|
113
|
+
}.to_json
|
114
|
+
)
|
115
|
+
|
116
|
+
stub_request(:patch, %r{journals\(\d+\)\/journalLines\(#{test_id}\)})
|
117
|
+
.to_return(
|
118
|
+
status: 200,
|
119
|
+
body: {
|
120
|
+
etag: '4444',
|
121
|
+
id: test_id,
|
122
|
+
lineNumber: 4000,
|
123
|
+
description: 'journalLine5'
|
124
|
+
}.to_json
|
125
|
+
)
|
126
|
+
|
127
|
+
response = @journal_line.update(
|
128
|
+
test_id,
|
129
|
+
description: 'journalLine5'
|
130
|
+
)
|
131
|
+
assert_equal response[:description], 'journalLine5'
|
132
|
+
end
|
133
|
+
|
134
|
+
def test_delete
|
135
|
+
test_id = '33333'
|
136
|
+
stub_request(:get, %r{journals\(\d+\)\/journalLines\(#{test_id}\)})
|
137
|
+
.to_return(
|
138
|
+
status: 200,
|
139
|
+
body: {
|
140
|
+
etag: '5555',
|
141
|
+
id: test_id,
|
142
|
+
lineNumber: 5000,
|
143
|
+
description: 'journalLine5'
|
144
|
+
}.to_json
|
145
|
+
)
|
146
|
+
|
147
|
+
stub_request(:delete, %r{journals\(\d+\)\/journalLines\(#{test_id}\)})
|
148
|
+
.to_return(status: 204)
|
149
|
+
|
150
|
+
assert @journal_line.destroy(test_id)
|
151
|
+
end
|
152
|
+
end
|
@@ -0,0 +1,144 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
# rake test TEST=test/business_central/object/journal_test.rb
|
5
|
+
|
6
|
+
class BusinessCentral::Object::JournalTest < Minitest::Test
|
7
|
+
def setup
|
8
|
+
@company_id = '123456'
|
9
|
+
@client = BusinessCentral::Client.new
|
10
|
+
@journal = @client.journal(company_id: @company_id)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_find_all
|
14
|
+
stub_request(:get, /journals/)
|
15
|
+
.to_return(
|
16
|
+
status: 200,
|
17
|
+
body: {
|
18
|
+
'value': [
|
19
|
+
{
|
20
|
+
code: '123',
|
21
|
+
displayName: 'journal1'
|
22
|
+
}
|
23
|
+
]
|
24
|
+
}.to_json
|
25
|
+
)
|
26
|
+
|
27
|
+
response = @journal.find_all
|
28
|
+
assert_equal response.first[:display_name], 'journal1'
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_find_by_id
|
32
|
+
test_journal_id = '09876'
|
33
|
+
stub_request(:get, /journals\(#{test_journal_id}\)/)
|
34
|
+
.to_return(
|
35
|
+
status: 200,
|
36
|
+
body: {
|
37
|
+
code: '123',
|
38
|
+
displayName: 'journal1'
|
39
|
+
}.to_json
|
40
|
+
)
|
41
|
+
|
42
|
+
response = @journal.find_by_id(test_journal_id)
|
43
|
+
assert_equal response[:display_name], 'journal1'
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_where
|
47
|
+
test_filter = "displayName eq 'journal2'"
|
48
|
+
stub_request(:get, /journals\?\$filter=#{test_filter}/)
|
49
|
+
.to_return(
|
50
|
+
status: 200,
|
51
|
+
body: {
|
52
|
+
'value': [
|
53
|
+
{
|
54
|
+
code: '456',
|
55
|
+
displayName: 'journal2'
|
56
|
+
}
|
57
|
+
]
|
58
|
+
}.to_json
|
59
|
+
)
|
60
|
+
|
61
|
+
response = @journal.where(test_filter)
|
62
|
+
assert_equal response.first[:display_name], 'journal2'
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_create
|
66
|
+
stub_request(:post, /journals/)
|
67
|
+
.to_return(
|
68
|
+
status: 200,
|
69
|
+
body: {
|
70
|
+
code: '789',
|
71
|
+
displayName: 'journal3'
|
72
|
+
}.to_json
|
73
|
+
)
|
74
|
+
|
75
|
+
response = @journal.create(
|
76
|
+
code: '789',
|
77
|
+
display_name: 'journal3'
|
78
|
+
)
|
79
|
+
assert_equal response[:display_name], 'journal3'
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_update
|
83
|
+
test_journal_id = '011123'
|
84
|
+
stub_request(:get, /journals\(#{test_journal_id}\)/)
|
85
|
+
.to_return(
|
86
|
+
status: 200,
|
87
|
+
body: {
|
88
|
+
etag: '112',
|
89
|
+
displayName: 'journal4'
|
90
|
+
}.to_json
|
91
|
+
)
|
92
|
+
|
93
|
+
stub_request(:patch, /journals\(#{test_journal_id}\)/)
|
94
|
+
.to_return(
|
95
|
+
status: 200,
|
96
|
+
body: {
|
97
|
+
displayName: 'journal5'
|
98
|
+
}.to_json
|
99
|
+
)
|
100
|
+
|
101
|
+
response = @journal.update(
|
102
|
+
test_journal_id,
|
103
|
+
display_name: 'journal5'
|
104
|
+
)
|
105
|
+
assert_equal response[:display_name], 'journal5'
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_delete
|
109
|
+
test_journal_id = '0111245'
|
110
|
+
stub_request(:get, /journals\(#{test_journal_id}\)/)
|
111
|
+
.to_return(
|
112
|
+
status: 200,
|
113
|
+
body: {
|
114
|
+
etag: '113',
|
115
|
+
displayName: 'journal6'
|
116
|
+
}.to_json
|
117
|
+
)
|
118
|
+
|
119
|
+
stub_request(:delete, /journals\(#{test_journal_id}\)/)
|
120
|
+
.to_return(status: 204)
|
121
|
+
|
122
|
+
assert @journal.destroy(test_journal_id)
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_line_navigation
|
126
|
+
stub_request(:get, %r{journals\(\d+\)\/journalLines})
|
127
|
+
.to_return(
|
128
|
+
status: 200,
|
129
|
+
body: {
|
130
|
+
'value': [
|
131
|
+
{
|
132
|
+
journalDisplayName: 'journal1',
|
133
|
+
lineNumber: 1000,
|
134
|
+
description: 'journalLine1'
|
135
|
+
}
|
136
|
+
]
|
137
|
+
}.to_json
|
138
|
+
)
|
139
|
+
|
140
|
+
response = @client.journal(company_id: @company_id, id: '123')
|
141
|
+
.journal_line.find_all
|
142
|
+
assert_equal response.first[:line_number], 1000
|
143
|
+
end
|
144
|
+
end
|