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.
Files changed (126) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +45 -32
  3. data/lib/business_central/client.rb +7 -52
  4. data/lib/business_central/exceptions.rb +11 -29
  5. data/lib/business_central/object/{attachment.rb → attachments.rb} +9 -11
  6. data/lib/business_central/object/base.rb +42 -114
  7. data/lib/business_central/object/companies.rb +19 -0
  8. data/lib/business_central/object/filter_query.rb +2 -0
  9. data/lib/business_central/object/object_helper.rb +10 -37
  10. data/lib/business_central/object/picture.rb +4 -40
  11. data/lib/business_central/object/request.rb +14 -15
  12. data/lib/business_central/object/response.rb +5 -1
  13. data/lib/business_central/object/url_builder.rb +16 -12
  14. data/lib/business_central/object/url_helper.rb +16 -2
  15. data/lib/business_central/version.rb +1 -1
  16. data/lib/business_central/web_service.rb +2 -0
  17. data/lib/business_central.rb +4 -55
  18. data/lib/refinements/strings.rb +42 -0
  19. data/test/business_central/client_test.rb +24 -0
  20. data/test/business_central/exceptions_test.rb +40 -0
  21. data/test/business_central/object/{attachment_test.rb → attachments_test.rb} +5 -6
  22. data/test/business_central/object/base_test.rb +59 -22
  23. data/test/business_central/object/{company_test.rb → companies_test.rb} +3 -21
  24. data/test/business_central/object/picture_test.rb +7 -16
  25. data/test/business_central/object/response_test.rb +5 -0
  26. data/test/business_central/web_service_test.rb +7 -2
  27. metadata +38 -167
  28. data/lib/business_central/object/account.rb +0 -13
  29. data/lib/business_central/object/aged_account_payable.rb +0 -13
  30. data/lib/business_central/object/aged_account_receivable.rb +0 -13
  31. data/lib/business_central/object/argument_helper.rb +0 -22
  32. data/lib/business_central/object/balance_sheet.rb +0 -13
  33. data/lib/business_central/object/cash_flow_statement.rb +0 -13
  34. data/lib/business_central/object/company.rb +0 -18
  35. data/lib/business_central/object/company_information.rb +0 -14
  36. data/lib/business_central/object/country_region.rb +0 -26
  37. data/lib/business_central/object/currency.rb +0 -29
  38. data/lib/business_central/object/customer.rb +0 -34
  39. data/lib/business_central/object/customer_financial_detail.rb +0 -13
  40. data/lib/business_central/object/customer_payment.rb +0 -43
  41. data/lib/business_central/object/customer_payment_journal.rb +0 -25
  42. data/lib/business_central/object/customer_sale.rb +0 -13
  43. data/lib/business_central/object/default_dimension.rb +0 -51
  44. data/lib/business_central/object/dimension.rb +0 -20
  45. data/lib/business_central/object/dimension_line.rb +0 -37
  46. data/lib/business_central/object/dimension_value.rb +0 -28
  47. data/lib/business_central/object/employee.rb +0 -21
  48. data/lib/business_central/object/general_ledger_entry.rb +0 -13
  49. data/lib/business_central/object/income_statement.rb +0 -13
  50. data/lib/business_central/object/irs1099_code.rb +0 -16
  51. data/lib/business_central/object/item.rb +0 -47
  52. data/lib/business_central/object/item_category.rb +0 -16
  53. data/lib/business_central/object/journal.rb +0 -29
  54. data/lib/business_central/object/journal_line.rb +0 -48
  55. data/lib/business_central/object/payment_method.rb +0 -16
  56. data/lib/business_central/object/payment_term.rb +0 -16
  57. data/lib/business_central/object/purchase_invoice.rb +0 -69
  58. data/lib/business_central/object/purchase_invoice_line.rb +0 -37
  59. data/lib/business_central/object/retained_earning_statement.rb +0 -13
  60. data/lib/business_central/object/sales_credit_memo.rb +0 -20
  61. data/lib/business_central/object/sales_credit_memo_line.rb +0 -30
  62. data/lib/business_central/object/sales_invoice.rb +0 -62
  63. data/lib/business_central/object/sales_invoice_line.rb +0 -30
  64. data/lib/business_central/object/sales_order.rb +0 -20
  65. data/lib/business_central/object/sales_order_line.rb +0 -30
  66. data/lib/business_central/object/sales_quote.rb +0 -20
  67. data/lib/business_central/object/sales_quote_line.rb +0 -30
  68. data/lib/business_central/object/shipment_method.rb +0 -16
  69. data/lib/business_central/object/subscription.rb +0 -16
  70. data/lib/business_central/object/tax_area.rb +0 -16
  71. data/lib/business_central/object/tax_group.rb +0 -16
  72. data/lib/business_central/object/time_registration_entry.rb +0 -16
  73. data/lib/business_central/object/trial_balance.rb +0 -13
  74. data/lib/business_central/object/units_of_measure.rb +0 -16
  75. data/lib/business_central/object/validation.rb +0 -57
  76. data/lib/business_central/object/vendor.rb +0 -42
  77. data/lib/business_central/object/vendor_purchase.rb +0 -13
  78. data/lib/core_ext/string.rb +0 -31
  79. data/test/business_central/object/account_test.rb +0 -67
  80. data/test/business_central/object/aged_account_payable_test.rb +0 -61
  81. data/test/business_central/object/aged_account_receivable_test.rb +0 -61
  82. data/test/business_central/object/balance_sheet_test.rb +0 -61
  83. data/test/business_central/object/cash_flow_statement_test.rb +0 -61
  84. data/test/business_central/object/company_information_test.rb +0 -81
  85. data/test/business_central/object/country_region_test.rb +0 -129
  86. data/test/business_central/object/currency_test.rb +0 -150
  87. data/test/business_central/object/customer_financial_detail_test.rb +0 -68
  88. data/test/business_central/object/customer_payment_journal_test.rb +0 -134
  89. data/test/business_central/object/customer_payment_test.rb +0 -141
  90. data/test/business_central/object/customer_sale_test.rb +0 -72
  91. data/test/business_central/object/customer_test.rb +0 -168
  92. data/test/business_central/object/default_dimension_test.rb +0 -170
  93. data/test/business_central/object/dimension_line_test.rb +0 -165
  94. data/test/business_central/object/dimension_test.rb +0 -65
  95. data/test/business_central/object/dimension_value_test.rb +0 -68
  96. data/test/business_central/object/employee_test.rb +0 -141
  97. data/test/business_central/object/general_ledger_entry_test.rb +0 -82
  98. data/test/business_central/object/income_statement_test.rb +0 -82
  99. data/test/business_central/object/irs1099_code_test.rb +0 -124
  100. data/test/business_central/object/item_category_test.rb +0 -122
  101. data/test/business_central/object/item_test.rb +0 -121
  102. data/test/business_central/object/journal_line_test.rb +0 -152
  103. data/test/business_central/object/journal_test.rb +0 -144
  104. data/test/business_central/object/payment_method_test.rb +0 -134
  105. data/test/business_central/object/payment_term_test.rb +0 -134
  106. data/test/business_central/object/purchase_invoice_line_test.rb +0 -123
  107. data/test/business_central/object/purchase_invoice_test.rb +0 -119
  108. data/test/business_central/object/retained_earning_statement_test.rb +0 -52
  109. data/test/business_central/object/sales_credit_memo_line_test.rb +0 -134
  110. data/test/business_central/object/sales_credit_memo_test.rb +0 -146
  111. data/test/business_central/object/sales_invoice_line_test.rb +0 -164
  112. data/test/business_central/object/sales_invoice_test.rb +0 -156
  113. data/test/business_central/object/sales_order_line_test.rb +0 -134
  114. data/test/business_central/object/sales_order_test.rb +0 -146
  115. data/test/business_central/object/sales_quote_line_test.rb +0 -134
  116. data/test/business_central/object/sales_quote_test.rb +0 -146
  117. data/test/business_central/object/shipment_method_test.rb +0 -133
  118. data/test/business_central/object/subscription_test.rb +0 -126
  119. data/test/business_central/object/tax_area_test.rb +0 -126
  120. data/test/business_central/object/tax_group_test.rb +0 -126
  121. data/test/business_central/object/time_registration_entry_test.rb +0 -126
  122. data/test/business_central/object/trial_balance_test.rb +0 -82
  123. data/test/business_central/object/units_of_measure_test.rb +0 -126
  124. data/test/business_central/object/validation_test.rb +0 -62
  125. data/test/business_central/object/vendor_purchase_test.rb +0 -82
  126. data/test/business_central/object/vendor_test.rb +0 -119
@@ -1,141 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
- # rake test TEST=test/business_central/object/employee_test.rb
5
-
6
- class BusinessCentral::Object::EmployeeTest < Minitest::Test
7
- def setup
8
- @company_id = '123456'
9
- @client = BusinessCentral::Client.new
10
- @employee = @client.employee(company_id: @company_id)
11
- end
12
-
13
- def test_find_all
14
- stub_request(:get, %r{/employees})
15
- .to_return(
16
- status: 200,
17
- body: {
18
- 'value': [
19
- {
20
- displayName: 'employee1'
21
- }
22
- ]
23
- }.to_json
24
- )
25
-
26
- response = @employee.find_all
27
- assert_equal response.first[:display_name], 'employee1'
28
- end
29
-
30
- def test_find_by_id
31
- test_id = '09876'
32
- stub_request(:get, /employees\(#{test_id}\)/)
33
- .to_return(
34
- status: 200,
35
- body: {
36
- id: test_id,
37
- displayName: 'employee2'
38
- }.to_json
39
- )
40
-
41
- response = @employee.find_by_id(test_id)
42
- assert_equal response[:display_name], 'employee2'
43
- end
44
-
45
- def test_where
46
- test_filter = "displayName eq 'employee3'"
47
- stub_request(:get, /employees\?\$filter=#{test_filter}/)
48
- .to_return(
49
- status: 200,
50
- body: {
51
- 'value': [
52
- {
53
- displayName: 'employee3'
54
- }
55
- ]
56
- }.to_json
57
- )
58
-
59
- response = @employee.where(test_filter)
60
- assert_equal response.first[:display_name], 'employee3'
61
- end
62
-
63
- def test_create
64
- stub_request(:post, /employees/)
65
- .to_return(
66
- status: 200,
67
- body: {
68
- displayName: 'employee4'
69
- }.to_json
70
- )
71
-
72
- response = @employee.create(
73
- display_name: 'employee4'
74
- )
75
- assert_equal response[:display_name], 'employee4'
76
- end
77
-
78
- def test_update
79
- test_id = '011123'
80
- stub_request(:get, /employees\(#{test_id}\)/)
81
- .to_return(
82
- status: 200,
83
- body: {
84
- etag: '112',
85
- id: test_id,
86
- displayName: 'employee5'
87
- }.to_json
88
- )
89
-
90
- stub_request(:patch, /employees\(#{test_id}\)/)
91
- .to_return(
92
- status: 200,
93
- body: {
94
- etag: '112',
95
- id: test_id,
96
- displayName: 'employee6'
97
- }.to_json
98
- )
99
-
100
- response = @employee.update(
101
- test_id,
102
- display_name: 'employee6'
103
- )
104
- assert_equal response[:display_name], 'employee6'
105
- end
106
-
107
- def test_delete
108
- test_id = '0111245'
109
- stub_request(:get, /employees\(#{test_id}\)/)
110
- .to_return(
111
- status: 200,
112
- body: {
113
- etag: '113',
114
- displayName: 'employee7'
115
- }.to_json
116
- )
117
-
118
- stub_request(:delete, /employees\(#{test_id}\)/)
119
- .to_return(status: 204)
120
-
121
- assert @employee.destroy(test_id)
122
- end
123
-
124
- def test_default_dimension_navigation
125
- stub_request(:get, /defaultDimensions/)
126
- .to_return(
127
- status: 200,
128
- body: {
129
- 'value': [
130
- {
131
- id: 1,
132
- parentId: '123',
133
- }
134
- ]
135
- }.to_json
136
- )
137
-
138
- response = @client.employee(company_id: @company_id, id: '123').default_dimension.find_all
139
- assert_equal response.first[:parent_id], '123'
140
- end
141
- end
@@ -1,82 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
- # rake test TEST=test/business_central/object/general_ledger_entry_test.rb
5
-
6
- class BusinessCentral::Object::GeneralLedgerEntryTest < Minitest::Test
7
- def setup
8
- @company_id = '123456'
9
- @client = BusinessCentral::Client.new
10
- @general_ledger_entry = @client.general_ledger_entry(company_id: @company_id)
11
- end
12
-
13
- def test_find_all
14
- stub_request(:get, /generalLedgerEntries/)
15
- .to_return(
16
- status: 200,
17
- body: {
18
- 'value': [
19
- {
20
- id: 1,
21
- number: '1009'
22
- }
23
- ]
24
- }.to_json
25
- )
26
-
27
- response = @general_ledger_entry.find_all
28
- assert_equal response.first[:number], '1009'
29
- end
30
-
31
- def test_find_by_id
32
- test_id = '09876'
33
- stub_request(:get, /generalLedgerEntries\(#{test_id}\)/)
34
- .to_return(
35
- status: 200,
36
- body: {
37
- id: test_id,
38
- number: '1010'
39
- }.to_json
40
- )
41
-
42
- response = @general_ledger_entry.find_by_id(test_id)
43
- assert_equal response[:number], '1010'
44
- end
45
-
46
- def test_where
47
- test_filter = "number eq '1020'"
48
- stub_request(:get, /generalLedgerEntries\?\$filter=#{test_filter}/)
49
- .to_return(
50
- status: 200,
51
- body: {
52
- 'value': [
53
- {
54
- id: '345',
55
- number: '1011'
56
- }
57
- ]
58
- }.to_json
59
- )
60
-
61
- response = @general_ledger_entry.where(test_filter)
62
- assert_equal response.first[:number], '1011'
63
- end
64
-
65
- def test_create
66
- assert_raises BusinessCentral::NoSupportedMethod do
67
- @general_ledger_entry.create({})
68
- end
69
- end
70
-
71
- def test_update
72
- assert_raises BusinessCentral::NoSupportedMethod do
73
- @general_ledger_entry.update('123', {})
74
- end
75
- end
76
-
77
- def test_delete
78
- assert_raises BusinessCentral::NoSupportedMethod do
79
- @general_ledger_entry.destroy('123')
80
- end
81
- end
82
- end
@@ -1,82 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
- # rake test TEST=test/business_central/object/income_statement_test.rb
5
-
6
- class BusinessCentral::Object::IncomeStatementTest < Minitest::Test
7
- def setup
8
- @company_id = '123456'
9
- @client = BusinessCentral::Client.new
10
- @income_statement = @client.income_statement(company_id: @company_id)
11
- end
12
-
13
- def test_find_all
14
- stub_request(:get, /incomeStatement/)
15
- .to_return(
16
- status: 200,
17
- body: {
18
- 'value': [
19
- {
20
- id: 1,
21
- lineNumber: '1009'
22
- }
23
- ]
24
- }.to_json
25
- )
26
-
27
- response = @income_statement.find_all
28
- assert_equal response.first[:line_number], '1009'
29
- end
30
-
31
- def test_find_by_id
32
- test_id = '09876'
33
- stub_request(:get, /incomeStatement\(#{test_id}\)/)
34
- .to_return(
35
- status: 200,
36
- body: {
37
- id: test_id,
38
- lineNumber: '1010'
39
- }.to_json
40
- )
41
-
42
- response = @income_statement.find_by_id(test_id)
43
- assert_equal response[:line_number], '1010'
44
- end
45
-
46
- def test_where
47
- test_filter = "number eq '1020'"
48
- stub_request(:get, /incomeStatement\?\$filter=#{test_filter}/)
49
- .to_return(
50
- status: 200,
51
- body: {
52
- 'value': [
53
- {
54
- id: '345',
55
- lineNumber: '1011'
56
- }
57
- ]
58
- }.to_json
59
- )
60
-
61
- response = @income_statement.where(test_filter)
62
- assert_equal response.first[:line_number], '1011'
63
- end
64
-
65
- def test_create
66
- assert_raises BusinessCentral::NoSupportedMethod do
67
- @income_statement.create({})
68
- end
69
- end
70
-
71
- def test_update
72
- assert_raises BusinessCentral::NoSupportedMethod do
73
- @income_statement.update('123', {})
74
- end
75
- end
76
-
77
- def test_delete
78
- assert_raises BusinessCentral::NoSupportedMethod do
79
- @income_statement.destroy('123')
80
- end
81
- end
82
- end
@@ -1,124 +0,0 @@
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
@@ -1,122 +0,0 @@
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,121 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'test_helper'
4
- # rake test TEST=test/business_central/object/item_test.rb
5
-
6
- class BusinessCentral::Object::ItemTest < Minitest::Test
7
- def setup
8
- @company_id = '123456'
9
- @client = BusinessCentral::Client.new
10
- @item = @client.item(company_id: @company_id)
11
- end
12
-
13
- def test_find_all
14
- stub_request(:get, /items/)
15
- .to_return(
16
- status: 200,
17
- body: {
18
- 'value': [
19
- {
20
- displayName: 'item1'
21
- }
22
- ]
23
- }.to_json
24
- )
25
-
26
- response = @item.find_all
27
- assert_equal response.first[:display_name], 'item1'
28
- end
29
-
30
- def test_find_by_id
31
- test_item_id = '09876'
32
- stub_request(:get, /items\(#{test_item_id}\)/)
33
- .to_return(
34
- status: 200,
35
- body: {
36
- displayName: 'item2'
37
- }.to_json
38
- )
39
-
40
- response = @item.find_by_id(test_item_id)
41
- assert_equal response[:display_name], 'item2'
42
- end
43
-
44
- def test_where
45
- test_filter = "displayName eq 'item3'"
46
- stub_request(:get, /items\?\$filter=#{test_filter}/)
47
- .to_return(
48
- status: 200,
49
- body: {
50
- 'value': [
51
- {
52
- displayName: 'item3'
53
- }
54
- ]
55
- }.to_json
56
- )
57
-
58
- response = @item.where(test_filter)
59
- assert_equal response.first[:display_name], 'item3'
60
- end
61
-
62
- def test_create
63
- stub_request(:post, /items/)
64
- .to_return(
65
- status: 200,
66
- body: {
67
- displayName: 'item4'
68
- }.to_json
69
- )
70
-
71
- response = @item.create(
72
- display_name: 'item4',
73
- type: 'Inventory'
74
- )
75
- assert_equal response[:display_name], 'item4'
76
- end
77
-
78
- def test_update
79
- test_item_id = '011123'
80
- stub_request(:get, /items\(#{test_item_id}\)/)
81
- .to_return(
82
- status: 200,
83
- body: {
84
- etag: '112',
85
- displayName: 'item5'
86
- }.to_json
87
- )
88
-
89
- stub_request(:patch, /items\(#{test_item_id}\)/)
90
- .to_return(
91
- status: 200,
92
- body: {
93
- displayName: 'item6'
94
- }.to_json
95
- )
96
-
97
- response = @item.update(
98
- test_item_id,
99
- display_name: 'item6',
100
- type: 'Inventory'
101
- )
102
- assert_equal response[:display_name], 'item6'
103
- end
104
-
105
- def test_delete
106
- test_item_id = '0111245'
107
- stub_request(:get, /items\(#{test_item_id}\)/)
108
- .to_return(
109
- status: 200,
110
- body: {
111
- etag: '113',
112
- displayName: 'item7'
113
- }.to_json
114
- )
115
-
116
- stub_request(:delete, /items\(#{test_item_id}\)/)
117
- .to_return(status: 204)
118
-
119
- assert @item.destroy(test_item_id)
120
- end
121
- end