business-central 1.0.5 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +45 -32
- data/lib/business_central/client.rb +7 -52
- data/lib/business_central/exceptions.rb +11 -29
- data/lib/business_central/object/{attachment.rb → attachments.rb} +9 -11
- data/lib/business_central/object/base.rb +42 -114
- data/lib/business_central/object/companies.rb +19 -0
- data/lib/business_central/object/filter_query.rb +2 -0
- data/lib/business_central/object/object_helper.rb +10 -37
- data/lib/business_central/object/picture.rb +4 -40
- data/lib/business_central/object/request.rb +14 -15
- data/lib/business_central/object/response.rb +5 -1
- data/lib/business_central/object/url_builder.rb +16 -12
- data/lib/business_central/object/url_helper.rb +16 -2
- data/lib/business_central/version.rb +1 -1
- data/lib/business_central/web_service.rb +2 -0
- data/lib/business_central.rb +4 -55
- data/lib/refinements/strings.rb +42 -0
- data/test/business_central/client_test.rb +24 -0
- data/test/business_central/exceptions_test.rb +40 -0
- data/test/business_central/object/{attachment_test.rb → attachments_test.rb} +5 -6
- data/test/business_central/object/base_test.rb +59 -22
- data/test/business_central/object/{company_test.rb → companies_test.rb} +3 -21
- data/test/business_central/object/picture_test.rb +7 -16
- data/test/business_central/object/response_test.rb +5 -0
- data/test/business_central/web_service_test.rb +7 -2
- metadata +38 -167
- data/lib/business_central/object/account.rb +0 -13
- data/lib/business_central/object/aged_account_payable.rb +0 -13
- data/lib/business_central/object/aged_account_receivable.rb +0 -13
- data/lib/business_central/object/argument_helper.rb +0 -22
- data/lib/business_central/object/balance_sheet.rb +0 -13
- data/lib/business_central/object/cash_flow_statement.rb +0 -13
- data/lib/business_central/object/company.rb +0 -18
- data/lib/business_central/object/company_information.rb +0 -14
- data/lib/business_central/object/country_region.rb +0 -26
- data/lib/business_central/object/currency.rb +0 -29
- data/lib/business_central/object/customer.rb +0 -34
- data/lib/business_central/object/customer_financial_detail.rb +0 -13
- data/lib/business_central/object/customer_payment.rb +0 -43
- data/lib/business_central/object/customer_payment_journal.rb +0 -25
- data/lib/business_central/object/customer_sale.rb +0 -13
- data/lib/business_central/object/default_dimension.rb +0 -51
- data/lib/business_central/object/dimension.rb +0 -20
- data/lib/business_central/object/dimension_line.rb +0 -37
- data/lib/business_central/object/dimension_value.rb +0 -28
- data/lib/business_central/object/employee.rb +0 -21
- data/lib/business_central/object/general_ledger_entry.rb +0 -13
- data/lib/business_central/object/income_statement.rb +0 -13
- data/lib/business_central/object/irs1099_code.rb +0 -16
- data/lib/business_central/object/item.rb +0 -47
- data/lib/business_central/object/item_category.rb +0 -16
- data/lib/business_central/object/journal.rb +0 -29
- data/lib/business_central/object/journal_line.rb +0 -48
- data/lib/business_central/object/payment_method.rb +0 -16
- data/lib/business_central/object/payment_term.rb +0 -16
- data/lib/business_central/object/purchase_invoice.rb +0 -69
- data/lib/business_central/object/purchase_invoice_line.rb +0 -37
- data/lib/business_central/object/retained_earning_statement.rb +0 -13
- data/lib/business_central/object/sales_credit_memo.rb +0 -20
- data/lib/business_central/object/sales_credit_memo_line.rb +0 -30
- data/lib/business_central/object/sales_invoice.rb +0 -62
- data/lib/business_central/object/sales_invoice_line.rb +0 -30
- data/lib/business_central/object/sales_order.rb +0 -20
- data/lib/business_central/object/sales_order_line.rb +0 -30
- data/lib/business_central/object/sales_quote.rb +0 -20
- data/lib/business_central/object/sales_quote_line.rb +0 -30
- data/lib/business_central/object/shipment_method.rb +0 -16
- data/lib/business_central/object/subscription.rb +0 -16
- data/lib/business_central/object/tax_area.rb +0 -16
- data/lib/business_central/object/tax_group.rb +0 -16
- data/lib/business_central/object/time_registration_entry.rb +0 -16
- data/lib/business_central/object/trial_balance.rb +0 -13
- data/lib/business_central/object/units_of_measure.rb +0 -16
- data/lib/business_central/object/validation.rb +0 -57
- data/lib/business_central/object/vendor.rb +0 -42
- data/lib/business_central/object/vendor_purchase.rb +0 -13
- data/lib/core_ext/string.rb +0 -31
- data/test/business_central/object/account_test.rb +0 -67
- data/test/business_central/object/aged_account_payable_test.rb +0 -61
- data/test/business_central/object/aged_account_receivable_test.rb +0 -61
- data/test/business_central/object/balance_sheet_test.rb +0 -61
- data/test/business_central/object/cash_flow_statement_test.rb +0 -61
- data/test/business_central/object/company_information_test.rb +0 -81
- data/test/business_central/object/country_region_test.rb +0 -129
- data/test/business_central/object/currency_test.rb +0 -150
- data/test/business_central/object/customer_financial_detail_test.rb +0 -68
- data/test/business_central/object/customer_payment_journal_test.rb +0 -134
- data/test/business_central/object/customer_payment_test.rb +0 -141
- data/test/business_central/object/customer_sale_test.rb +0 -72
- data/test/business_central/object/customer_test.rb +0 -168
- data/test/business_central/object/default_dimension_test.rb +0 -170
- data/test/business_central/object/dimension_line_test.rb +0 -165
- data/test/business_central/object/dimension_test.rb +0 -65
- data/test/business_central/object/dimension_value_test.rb +0 -68
- data/test/business_central/object/employee_test.rb +0 -141
- data/test/business_central/object/general_ledger_entry_test.rb +0 -82
- data/test/business_central/object/income_statement_test.rb +0 -82
- data/test/business_central/object/irs1099_code_test.rb +0 -124
- data/test/business_central/object/item_category_test.rb +0 -122
- data/test/business_central/object/item_test.rb +0 -121
- data/test/business_central/object/journal_line_test.rb +0 -152
- data/test/business_central/object/journal_test.rb +0 -144
- data/test/business_central/object/payment_method_test.rb +0 -134
- data/test/business_central/object/payment_term_test.rb +0 -134
- data/test/business_central/object/purchase_invoice_line_test.rb +0 -123
- data/test/business_central/object/purchase_invoice_test.rb +0 -119
- data/test/business_central/object/retained_earning_statement_test.rb +0 -52
- data/test/business_central/object/sales_credit_memo_line_test.rb +0 -134
- data/test/business_central/object/sales_credit_memo_test.rb +0 -146
- data/test/business_central/object/sales_invoice_line_test.rb +0 -164
- data/test/business_central/object/sales_invoice_test.rb +0 -156
- data/test/business_central/object/sales_order_line_test.rb +0 -134
- data/test/business_central/object/sales_order_test.rb +0 -146
- data/test/business_central/object/sales_quote_line_test.rb +0 -134
- data/test/business_central/object/sales_quote_test.rb +0 -146
- data/test/business_central/object/shipment_method_test.rb +0 -133
- data/test/business_central/object/subscription_test.rb +0 -126
- data/test/business_central/object/tax_area_test.rb +0 -126
- data/test/business_central/object/tax_group_test.rb +0 -126
- data/test/business_central/object/time_registration_entry_test.rb +0 -126
- data/test/business_central/object/trial_balance_test.rb +0 -82
- data/test/business_central/object/units_of_measure_test.rb +0 -126
- data/test/business_central/object/validation_test.rb +0 -62
- data/test/business_central/object/vendor_purchase_test.rb +0 -82
- data/test/business_central/object/vendor_test.rb +0 -119
@@ -1,81 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'test_helper'
|
4
|
-
# rake test TEST=test/business_central/object/company_information_test.rb
|
5
|
-
|
6
|
-
class BusinessCentral::Object::CompanyInformationTest < Minitest::Test
|
7
|
-
def setup
|
8
|
-
@company_id = '123456'
|
9
|
-
@client = BusinessCentral::Client.new
|
10
|
-
@company_information = @client.company_information(company_id: @company_id)
|
11
|
-
end
|
12
|
-
|
13
|
-
def test_find_all
|
14
|
-
stub_request(:get, /companyInformation/)
|
15
|
-
.to_return(
|
16
|
-
status: 200,
|
17
|
-
body: {
|
18
|
-
'value': [
|
19
|
-
{
|
20
|
-
displayName: 'business1'
|
21
|
-
}
|
22
|
-
]
|
23
|
-
}.to_json
|
24
|
-
)
|
25
|
-
|
26
|
-
response = @company_information.find_all
|
27
|
-
assert_equal response.first[:display_name], 'business1'
|
28
|
-
end
|
29
|
-
|
30
|
-
def test_find_by_id
|
31
|
-
test_company_id = '123'
|
32
|
-
stub_request(:get, /companyInformation\(#{test_company_id}\)/)
|
33
|
-
.to_return(
|
34
|
-
status: 200,
|
35
|
-
body: {
|
36
|
-
displayName: 'business2'
|
37
|
-
}.to_json
|
38
|
-
)
|
39
|
-
|
40
|
-
response = @company_information.find_by_id(test_company_id)
|
41
|
-
assert_equal response[:display_name], 'business2'
|
42
|
-
end
|
43
|
-
|
44
|
-
def test_create
|
45
|
-
assert_raises BusinessCentral::NoSupportedMethod do
|
46
|
-
@company_information.create({})
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
def test_update
|
51
|
-
test_company_id = '123'
|
52
|
-
stub_request(:get, /companyInformation\(#{test_company_id}\)/)
|
53
|
-
.to_return(
|
54
|
-
status: 200,
|
55
|
-
body: {
|
56
|
-
etag: '112',
|
57
|
-
displayName: 'business3'
|
58
|
-
}.to_json
|
59
|
-
)
|
60
|
-
|
61
|
-
stub_request(:patch, /companyInformation\(#{test_company_id}\)/)
|
62
|
-
.to_return(
|
63
|
-
status: 200,
|
64
|
-
body: {
|
65
|
-
displayName: 'business4'
|
66
|
-
}.to_json
|
67
|
-
)
|
68
|
-
|
69
|
-
response = @company_information.update(
|
70
|
-
test_company_id,
|
71
|
-
display_name: 'business4'
|
72
|
-
)
|
73
|
-
assert_equal response[:display_name], 'business4'
|
74
|
-
end
|
75
|
-
|
76
|
-
def test_delete
|
77
|
-
assert_raises BusinessCentral::NoSupportedMethod do
|
78
|
-
@company_information.destroy('123')
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
@@ -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
|