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,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