business-central 1.0.1 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +58 -15
- data/lib/business_central.rb +47 -2
- data/lib/business_central/client.rb +82 -39
- data/lib/business_central/exceptions.rb +30 -10
- data/lib/business_central/object/account.rb +4 -12
- data/lib/business_central/object/aged_account_payable.rb +4 -12
- data/lib/business_central/object/aged_account_receivable.rb +4 -12
- 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 -12
- data/lib/business_central/object/base.rb +100 -49
- data/lib/business_central/object/cash_flow_statement.rb +4 -12
- data/lib/business_central/object/company.rb +9 -2
- data/lib/business_central/object/company_information.rb +7 -15
- 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 +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 +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 +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 +41 -0
- 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 +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 -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 +75 -12
- data/test/business_central/object/response_test.rb +34 -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 -16
- data/test/business_central/web_service_test.rb +100 -0
- data/test/business_central_test.rb +3 -1
- data/test/test_helper.rb +16 -6
- metadata +188 -37
- data/lib/business_central/object/helper.rb +0 -15
@@ -0,0 +1,141 @@
|
|
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
|
@@ -0,0 +1,72 @@
|
|
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
|
@@ -0,0 +1,168 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
# rake test TEST=test/business_central/object/customer_test.rb
|
5
|
+
|
6
|
+
class BusinessCentral::Object::CustomerTest < Minitest::Test
|
7
|
+
def setup
|
8
|
+
@company_id = '123456'
|
9
|
+
@client = BusinessCentral::Client.new
|
10
|
+
@customer = @client.customer(company_id: @company_id)
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_find_all
|
14
|
+
stub_request(:get, /customers/)
|
15
|
+
.to_return(
|
16
|
+
status: 200,
|
17
|
+
body: {
|
18
|
+
'value': [
|
19
|
+
{
|
20
|
+
id: 1,
|
21
|
+
displayName: 'customer1'
|
22
|
+
}
|
23
|
+
]
|
24
|
+
}.to_json
|
25
|
+
)
|
26
|
+
|
27
|
+
response = @customer.find_all
|
28
|
+
assert_equal response.first[:display_name], 'customer1'
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_find_by_id
|
32
|
+
test_id = '2'
|
33
|
+
stub_request(:get, /customers\(#{test_id}\)/)
|
34
|
+
.to_return(
|
35
|
+
status: 200,
|
36
|
+
body: {
|
37
|
+
id: test_id,
|
38
|
+
displayName: 'customer2'
|
39
|
+
}.to_json
|
40
|
+
)
|
41
|
+
|
42
|
+
response = @customer.find_by_id(test_id)
|
43
|
+
assert_equal response[:display_name], 'customer2'
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_where
|
47
|
+
test_filter = "displayName eq 'customer3'"
|
48
|
+
stub_request(:get, /customers\?\$filter=#{test_filter}/)
|
49
|
+
.to_return(
|
50
|
+
status: 200,
|
51
|
+
body: {
|
52
|
+
'value': [
|
53
|
+
{
|
54
|
+
id: 3,
|
55
|
+
displayName: 'customer3'
|
56
|
+
}
|
57
|
+
]
|
58
|
+
}.to_json
|
59
|
+
)
|
60
|
+
|
61
|
+
response = @customer.where(test_filter)
|
62
|
+
assert_equal response.first[:display_name], 'customer3'
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_create
|
66
|
+
stub_request(:post, /customers/)
|
67
|
+
.to_return(
|
68
|
+
status: 200,
|
69
|
+
body: {
|
70
|
+
displayName: 'customer4'
|
71
|
+
}.to_json
|
72
|
+
)
|
73
|
+
|
74
|
+
response = @customer.create(
|
75
|
+
display_name: 'customer4'
|
76
|
+
)
|
77
|
+
assert_equal response[:display_name], 'customer4'
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_update
|
81
|
+
test_id = '2'
|
82
|
+
stub_request(:get, /customers\(#{test_id}\)/)
|
83
|
+
.to_return(
|
84
|
+
status: 200,
|
85
|
+
body: {
|
86
|
+
etag: '3333',
|
87
|
+
id: test_id,
|
88
|
+
displayName: 'customer5'
|
89
|
+
}.to_json
|
90
|
+
)
|
91
|
+
|
92
|
+
stub_request(:patch, /customers\(#{test_id}\)/)
|
93
|
+
.to_return(
|
94
|
+
status: 200,
|
95
|
+
body: {
|
96
|
+
etag: '4444',
|
97
|
+
displayName: 'customer6'
|
98
|
+
}.to_json
|
99
|
+
)
|
100
|
+
|
101
|
+
response = @customer.update(
|
102
|
+
test_id,
|
103
|
+
display_name: 'customer6'
|
104
|
+
)
|
105
|
+
assert_equal response[:display_name], 'customer6'
|
106
|
+
end
|
107
|
+
|
108
|
+
def test_delete
|
109
|
+
test_id = '33333'
|
110
|
+
stub_request(:get, /customers\(#{test_id}\)/)
|
111
|
+
.to_return(
|
112
|
+
status: 200,
|
113
|
+
body: {
|
114
|
+
etag: '5555',
|
115
|
+
displayName: 'customer7'
|
116
|
+
}.to_json
|
117
|
+
)
|
118
|
+
|
119
|
+
stub_request(:delete, /customers\(#{test_id}\)/)
|
120
|
+
.to_return(status: 204)
|
121
|
+
|
122
|
+
assert @customer.destroy(test_id)
|
123
|
+
end
|
124
|
+
|
125
|
+
def test_default_dimension_navigation
|
126
|
+
stub_request(:get, %r{customers\(\d+\)\/defaultDimensions})
|
127
|
+
.to_return(
|
128
|
+
status: 200,
|
129
|
+
body: {
|
130
|
+
'value': [
|
131
|
+
{
|
132
|
+
id: 1,
|
133
|
+
parentId: '123',
|
134
|
+
dimensionId: '123',
|
135
|
+
dimensionCode: 'ABC',
|
136
|
+
dimensionValueId: 1,
|
137
|
+
dimensionValueCode: 'DEF'
|
138
|
+
}
|
139
|
+
]
|
140
|
+
}.to_json
|
141
|
+
)
|
142
|
+
|
143
|
+
response = @client.customer(company_id: @company_id, id: '123')
|
144
|
+
.default_dimension.find_all
|
145
|
+
assert_equal response.first[:parent_id], '123'
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_picture_navigation
|
149
|
+
stub_request(:get, %r{customers\(\d+\)\/picture})
|
150
|
+
.to_return(
|
151
|
+
status: 200,
|
152
|
+
body: {
|
153
|
+
'value': [
|
154
|
+
{
|
155
|
+
id: 1,
|
156
|
+
width: 500,
|
157
|
+
height: 496,
|
158
|
+
contentType: 'image\jpeg'
|
159
|
+
}
|
160
|
+
]
|
161
|
+
}.to_json
|
162
|
+
)
|
163
|
+
|
164
|
+
response = @client.customer(company_id: @company_id, id: '123')
|
165
|
+
.picture.find_all
|
166
|
+
assert_equal response.first[:width], 500
|
167
|
+
end
|
168
|
+
end
|
@@ -0,0 +1,170 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'test_helper'
|
4
|
+
# rake test TEST=test/business_central/object/default_dimension_test.rb
|
5
|
+
|
6
|
+
class BusinessCentral::Object::DefaultDimensionTest < Minitest::Test
|
7
|
+
def setup
|
8
|
+
@company_id = '123456'
|
9
|
+
@client = BusinessCentral::Client.new
|
10
|
+
@default_dimension = @client.default_dimension(
|
11
|
+
company_id: @company_id,
|
12
|
+
parent: 'vendors',
|
13
|
+
parent_id: '123'
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_invalid_default_dimension_parent
|
18
|
+
assert_raises(BusinessCentral::InvalidArgumentException) do
|
19
|
+
@client.default_dimension(
|
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, /defaultDimensions/)
|
29
|
+
.to_return(
|
30
|
+
status: 200,
|
31
|
+
body: {
|
32
|
+
'value': [
|
33
|
+
{
|
34
|
+
id: 1,
|
35
|
+
parentId: '123',
|
36
|
+
dimensionId: '123',
|
37
|
+
dimensionCode: 'ABC',
|
38
|
+
dimensionValueId: 1,
|
39
|
+
dimensionValueCode: 'DEF'
|
40
|
+
}
|
41
|
+
]
|
42
|
+
}.to_json
|
43
|
+
)
|
44
|
+
|
45
|
+
response = @default_dimension.find_all
|
46
|
+
assert_equal response.first[:parent_id], '123'
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_find_by_id
|
50
|
+
test_id = '2'
|
51
|
+
stub_request(:get, /defaultDimensions\(#{test_id}\)/)
|
52
|
+
.to_return(
|
53
|
+
status: 200,
|
54
|
+
body: {
|
55
|
+
id: test_id,
|
56
|
+
parentId: '123',
|
57
|
+
dimensionId: '123',
|
58
|
+
dimensionCode: 'ABC',
|
59
|
+
dimensionValueId: 1,
|
60
|
+
dimensionValueCode: 'DEF'
|
61
|
+
}.to_json
|
62
|
+
)
|
63
|
+
|
64
|
+
response = @default_dimension.find_by_id(test_id)
|
65
|
+
assert_equal response[:dimension_code], 'ABC'
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_where
|
69
|
+
test_filter = "dimensionCode eq 'ABC'"
|
70
|
+
stub_request(:get, /defaultDimensions\?\$filter=#{test_filter}/)
|
71
|
+
.to_return(
|
72
|
+
status: 200,
|
73
|
+
body: {
|
74
|
+
'value': [
|
75
|
+
{
|
76
|
+
id: 3,
|
77
|
+
parentId: '123',
|
78
|
+
dimensionId: '123',
|
79
|
+
dimensionCode: 'ABC',
|
80
|
+
dimensionValueId: 1,
|
81
|
+
dimensionValueCode: 'DEF'
|
82
|
+
}
|
83
|
+
]
|
84
|
+
}.to_json
|
85
|
+
)
|
86
|
+
|
87
|
+
response = @default_dimension.where(test_filter)
|
88
|
+
assert_equal response.first[:dimension_code], 'ABC'
|
89
|
+
end
|
90
|
+
|
91
|
+
def test_create
|
92
|
+
stub_request(:post, /defaultDimensions/)
|
93
|
+
.to_return(
|
94
|
+
status: 200,
|
95
|
+
body: {
|
96
|
+
id: 4,
|
97
|
+
parentId: '123',
|
98
|
+
dimensionId: '123',
|
99
|
+
dimensionCode: 'ABC',
|
100
|
+
dimensionValueId: 1,
|
101
|
+
dimensionValueCode: 'DEF'
|
102
|
+
}.to_json
|
103
|
+
)
|
104
|
+
|
105
|
+
response = @default_dimension.create(
|
106
|
+
dimension_code: 'DEF',
|
107
|
+
dimension_value_code: 'GHI'
|
108
|
+
)
|
109
|
+
assert_equal response[:id], 4
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_update
|
113
|
+
test_id = '2'
|
114
|
+
stub_request(:get, /defaultDimensions\(#{test_id}\)/)
|
115
|
+
.to_return(
|
116
|
+
status: 200,
|
117
|
+
body: {
|
118
|
+
etag: '3333',
|
119
|
+
id: test_id,
|
120
|
+
parentId: '123',
|
121
|
+
dimensionId: '123',
|
122
|
+
dimensionCode: 'ABC',
|
123
|
+
dimensionValueId: 1,
|
124
|
+
dimensionValueCode: 'DEF'
|
125
|
+
}.to_json
|
126
|
+
)
|
127
|
+
|
128
|
+
stub_request(:patch, /defaultDimensions\(#{test_id}\)/)
|
129
|
+
.to_return(
|
130
|
+
status: 200,
|
131
|
+
body: {
|
132
|
+
etag: '4444',
|
133
|
+
id: test_id,
|
134
|
+
parentId: '123',
|
135
|
+
dimensionId: '123',
|
136
|
+
dimensionCode: 'ZYX',
|
137
|
+
dimensionValueId: 1,
|
138
|
+
dimensionValueCode: 'DEF'
|
139
|
+
}.to_json
|
140
|
+
)
|
141
|
+
|
142
|
+
response = @default_dimension.update(
|
143
|
+
test_id,
|
144
|
+
dimension_code: 'ZYX'
|
145
|
+
)
|
146
|
+
assert_equal response[:dimension_code], 'ZYX'
|
147
|
+
end
|
148
|
+
|
149
|
+
def test_delete
|
150
|
+
test_id = '33333'
|
151
|
+
stub_request(:get, /defaultDimensions\(#{test_id}\)/)
|
152
|
+
.to_return(
|
153
|
+
status: 200,
|
154
|
+
body: {
|
155
|
+
etag: '5555',
|
156
|
+
id: test_id,
|
157
|
+
parentId: '123',
|
158
|
+
dimensionId: '123',
|
159
|
+
dimensionCode: 'ZYX',
|
160
|
+
dimensionValueId: 1,
|
161
|
+
dimensionValueCode: 'DEF'
|
162
|
+
}.to_json
|
163
|
+
)
|
164
|
+
|
165
|
+
stub_request(:delete, /defaultDimensions\(#{test_id}\)/)
|
166
|
+
.to_return(status: 204)
|
167
|
+
|
168
|
+
assert @default_dimension.destroy(test_id)
|
169
|
+
end
|
170
|
+
end
|