business-central 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. checksums.yaml +4 -4
  2. data/lib/business_central.rb +6 -0
  3. data/lib/business_central/client.rb +16 -4
  4. data/lib/business_central/exceptions.rb +11 -1
  5. data/lib/business_central/object/account.rb +0 -10
  6. data/lib/business_central/object/aged_account_payable.rb +0 -10
  7. data/lib/business_central/object/aged_account_receivable.rb +0 -10
  8. data/lib/business_central/object/balance_sheet.rb +0 -10
  9. data/lib/business_central/object/base.rb +30 -13
  10. data/lib/business_central/object/cash_flow_statement.rb +0 -10
  11. data/lib/business_central/object/company.rb +5 -0
  12. data/lib/business_central/object/company_information.rb +0 -10
  13. data/lib/business_central/object/country_region.rb +0 -10
  14. data/lib/business_central/object/currency.rb +0 -10
  15. data/lib/business_central/object/customer.rb +27 -0
  16. data/lib/business_central/object/customer_financial_detail.rb +11 -0
  17. data/lib/business_central/object/customer_payment.rb +41 -0
  18. data/lib/business_central/object/customer_payment_journal.rb +23 -0
  19. data/lib/business_central/object/customer_sale.rb +11 -0
  20. data/lib/business_central/object/default_dimension.rb +54 -0
  21. data/lib/business_central/object/helper.rb +29 -3
  22. data/lib/business_central/object/item.rb +0 -10
  23. data/lib/business_central/object/purchase_invoice.rb +0 -10
  24. data/lib/business_central/object/purchase_invoice_line.rb +4 -10
  25. data/lib/business_central/object/request.rb +2 -2
  26. data/lib/business_central/object/vendor.rb +3 -9
  27. data/lib/business_central/version.rb +1 -1
  28. data/test/business_central/client_test.rb +37 -2
  29. data/test/business_central/object/base_test.rb +39 -0
  30. data/test/business_central/object/customer_financial_detail_test.rb +66 -0
  31. data/test/business_central/object/customer_payment_journal_test.rb +135 -0
  32. data/test/business_central/object/customer_payment_test.rb +142 -0
  33. data/test/business_central/object/customer_sale_test.rb +70 -0
  34. data/test/business_central/object/customer_test.rb +125 -0
  35. data/test/business_central/object/default_dimension_test.rb +171 -0
  36. data/test/business_central/object/request_test.rb +58 -3
  37. data/test/business_central/object/response_test.rb +24 -6
  38. data/test/test_helper.rb +6 -2
  39. metadata +36 -2
@@ -0,0 +1,142 @@
1
+ require "test_helper"
2
+ # rake test TEST=test/business_central/object/customer_payment_test.rb
3
+
4
+ class BusinessCentral::Object::CustomerPaymentTest < Minitest::Test
5
+ def setup
6
+ @company_id = '123456'
7
+ @client = BusinessCentral::Client.new
8
+ @customer_payment = @client.customer_payment(company_id: @company_id)
9
+ end
10
+
11
+ def test_find_all
12
+ stub_request(:get, /customerPayments/)
13
+ .to_return(
14
+ status: 200,
15
+ body: {
16
+ 'value': [
17
+ {
18
+ id: 1,
19
+ lineNumber: 1,
20
+ customerId: 1,
21
+ customerNumber: '123'
22
+ }
23
+ ]
24
+ }.to_json,
25
+ )
26
+
27
+ response = @customer_payment.find_all
28
+ assert_equal response.first[:customer_number], '123'
29
+ end
30
+
31
+ def test_find_by_id
32
+ test_id = '2'
33
+ stub_request(:get, /customerPayments\(#{test_id}\)/)
34
+ .to_return(
35
+ status: 200,
36
+ body: {
37
+ id: test_id,
38
+ lineNumber: 1,
39
+ customerId: test_id,
40
+ customerNumber: '456'
41
+ }.to_json
42
+ )
43
+
44
+ response = @customer_payment.find_by_id(test_id)
45
+ assert_equal response[:customer_number], '456'
46
+ end
47
+
48
+ def test_where
49
+ test_filter = "customerNumber eq '123'"
50
+ stub_request(:get, /customerPayments\?\$filter=#{test_filter}/)
51
+ .to_return(
52
+ status: 200,
53
+ body: {
54
+ 'value': [
55
+ {
56
+ id: 1,
57
+ lineNumber: 1,
58
+ customerId: 1,
59
+ customerNumber: '123'
60
+ }
61
+ ]
62
+ }.to_json
63
+ )
64
+
65
+ response = @customer_payment.where(test_filter)
66
+ assert_equal response.first[:customer_number], '123'
67
+ end
68
+
69
+ def test_create
70
+ stub_request(:post, /customerPayments/)
71
+ .to_return(
72
+ status: 200,
73
+ body: {
74
+ id: 1,
75
+ lineNumber: 1,
76
+ customerId: 1,
77
+ customerNumber: '789'
78
+ }.to_json
79
+ )
80
+
81
+ response = @customer_payment.create({
82
+ customer_number: '789'
83
+ })
84
+ assert_equal response[:customer_number], '789'
85
+ end
86
+
87
+
88
+ def test_update
89
+ test_id = '2'
90
+ stub_request(:get, /customerPayments\(#{test_id}\)/)
91
+ .to_return(
92
+ status: 200,
93
+ body: {
94
+ etag: '3333',
95
+ id: test_id,
96
+ lineNumber: 1,
97
+ customerId: 1,
98
+ customerNumber: '789'
99
+ }.to_json
100
+ )
101
+
102
+ stub_request(:patch, /customerPayments\(#{test_id}\)/)
103
+ .to_return(
104
+ status: 200,
105
+ body: {
106
+ etag: '4444',
107
+ id: test_id,
108
+ lineNumber: 1,
109
+ customerId: 1,
110
+ customerNumber: '1011'
111
+ }.to_json
112
+ )
113
+
114
+ response = @customer_payment.update(
115
+ test_id,
116
+ {
117
+ customer_number: '1011'
118
+ }
119
+ )
120
+ assert_equal response[:customer_number], '1011'
121
+ end
122
+
123
+ def test_delete
124
+ test_id = '33333'
125
+ stub_request(:get, /customerPayments\(#{test_id}\)/)
126
+ .to_return(
127
+ status: 200,
128
+ body: {
129
+ etag: '5555',
130
+ id: test_id,
131
+ lineNumber: 1,
132
+ customerId: 1,
133
+ customerNumber: '1213'
134
+ }.to_json
135
+ )
136
+
137
+ stub_request(:delete, /customerPayments\(#{test_id}\)/)
138
+ .to_return(status: 204)
139
+
140
+ assert @customer_payment.destroy(test_id)
141
+ end
142
+ end
@@ -0,0 +1,70 @@
1
+ require "test_helper"
2
+ # rake test TEST=test/business_central/object/customer_sale_test.rb
3
+
4
+ class BusinessCentral::Object::CustomerSaleTest < Minitest::Test
5
+ def setup
6
+ @company_id = '123456'
7
+ @client = BusinessCentral::Client.new
8
+ @customer_sale = @client.customer_sale(
9
+ company_id: @company_id
10
+ )
11
+ end
12
+
13
+ def test_find_all
14
+ stub_request(:get, /customerSales/)
15
+ .to_return(
16
+ status: 200,
17
+ body: {
18
+ 'value': [
19
+ {
20
+ customerId: 1,
21
+ customerNumber: 'C1',
22
+ name: 'Jarrad',
23
+ totalSalesAmount: 0
24
+ }
25
+ ]
26
+ }.to_json,
27
+ )
28
+
29
+ response = @customer_sale.find_all
30
+ assert_equal response.first[:customer_number], 'C1'
31
+ end
32
+
33
+ def test_find_by_id
34
+ test_id = 2
35
+ stub_request(:get, /customerSales\(#{test_id}\)/)
36
+ .to_return(
37
+ status: 200,
38
+ body: {
39
+ customerId: 2,
40
+ customerNumber: 'C2',
41
+ name: 'Jrad',
42
+ totalSalesAmount: 0
43
+ }.to_json
44
+ )
45
+
46
+ response = @customer_sale.find_by_id(test_id)
47
+ assert_equal response[:customer_number], 'C2'
48
+ end
49
+
50
+ def test_where
51
+ test_filter = "customerNumber eq 'C3'"
52
+ stub_request(:get, /customerSales\?\$filter=#{test_filter}/)
53
+ .to_return(
54
+ status: 200,
55
+ body: {
56
+ 'value': [
57
+ {
58
+ customerId: 3,
59
+ customerNumber: 'C3',
60
+ name: 'Jazza',
61
+ totalSalesAmount: 0
62
+ }
63
+ ]
64
+ }.to_json
65
+ )
66
+
67
+ response = @customer_sale.where(test_filter)
68
+ assert_equal response.first[:customer_number], 'C3'
69
+ end
70
+ end
@@ -0,0 +1,125 @@
1
+ require "test_helper"
2
+ # rake test TEST=test/business_central/object/customer_test.rb
3
+
4
+ class BusinessCentral::Object::CustomerTest < Minitest::Test
5
+ def setup
6
+ @company_id = '123456'
7
+ @client = BusinessCentral::Client.new
8
+ @customer = @client.customer(company_id: @company_id)
9
+ end
10
+
11
+ def test_find_all
12
+ stub_request(:get, /customers/)
13
+ .to_return(
14
+ status: 200,
15
+ body: {
16
+ 'value': [
17
+ {
18
+ id: 1,
19
+ displayName: 'customer1'
20
+ }
21
+ ]
22
+ }.to_json,
23
+ )
24
+
25
+ response = @customer.find_all
26
+ assert_equal response.first[:display_name], 'customer1'
27
+ end
28
+
29
+ def test_find_by_id
30
+ test_id = '2'
31
+ stub_request(:get, /customers\(#{test_id}\)/)
32
+ .to_return(
33
+ status: 200,
34
+ body: {
35
+ id: test_id,
36
+ displayName: 'customer2'
37
+ }.to_json
38
+ )
39
+
40
+ response = @customer.find_by_id(test_id)
41
+ assert_equal response[:display_name], 'customer2'
42
+ end
43
+
44
+ def test_where
45
+ test_filter = "displayName eq 'customer3'"
46
+ stub_request(:get, /customers\?\$filter=#{test_filter}/)
47
+ .to_return(
48
+ status: 200,
49
+ body: {
50
+ 'value': [
51
+ {
52
+ id: 3,
53
+ displayName: 'customer3'
54
+ }
55
+ ]
56
+ }.to_json
57
+ )
58
+
59
+ response = @customer.where(test_filter)
60
+ assert_equal response.first[:display_name], 'customer3'
61
+ end
62
+
63
+ def test_create
64
+ stub_request(:post, /customers/)
65
+ .to_return(
66
+ status: 200,
67
+ body: {
68
+ displayName: 'customer4'
69
+ }.to_json
70
+ )
71
+
72
+ response = @customer.create({
73
+ display_name: 'customer4'
74
+ })
75
+ assert_equal response[:display_name], 'customer4'
76
+ end
77
+
78
+
79
+ def test_update
80
+ test_id = '2'
81
+ stub_request(:get, /customers\(#{test_id}\)/)
82
+ .to_return(
83
+ status: 200,
84
+ body: {
85
+ etag: '3333',
86
+ id: test_id,
87
+ displayName: 'customer5'
88
+ }.to_json
89
+ )
90
+
91
+ stub_request(:patch, /customers\(#{test_id}\)/)
92
+ .to_return(
93
+ status: 200,
94
+ body: {
95
+ etag: '4444',
96
+ displayName: 'customer6'
97
+ }.to_json
98
+ )
99
+
100
+ response = @customer.update(
101
+ test_id,
102
+ {
103
+ display_name: 'customer6'
104
+ }
105
+ )
106
+ assert_equal response[:display_name], 'customer6'
107
+ end
108
+
109
+ def test_delete
110
+ test_id = '33333'
111
+ stub_request(:get, /customers\(#{test_id}\)/)
112
+ .to_return(
113
+ status: 200,
114
+ body: {
115
+ etag: '5555',
116
+ displayName: 'customer7'
117
+ }.to_json
118
+ )
119
+
120
+ stub_request(:delete, /customers\(#{test_id}\)/)
121
+ .to_return(status: 204)
122
+
123
+ assert @customer.destroy(test_id)
124
+ end
125
+ end
@@ -0,0 +1,171 @@
1
+ require "test_helper"
2
+ # rake test TEST=test/business_central/object/default_dimension_test.rb
3
+
4
+ class BusinessCentral::Object::DefaultDimensionTest < Minitest::Test
5
+ def setup
6
+ @company_id = '123456'
7
+ @client = BusinessCentral::Client.new
8
+ @default_dimension = @client.default_dimension(
9
+ company_id: @company_id,
10
+ parent: 'vendors',
11
+ parent_id: '123'
12
+ )
13
+ end
14
+
15
+ def test_invalid_default_dimension_parent
16
+ assert_raises(BusinessCentral::InvalidArgumentException) do
17
+ @client.default_dimension(
18
+ company_id: @company_id,
19
+ parent: 'something that doesnt exist',
20
+ parent_id: '1'
21
+ )
22
+ end
23
+ end
24
+
25
+ def test_find_all
26
+ stub_request(:get, /defaultDimensions/)
27
+ .to_return(
28
+ status: 200,
29
+ body: {
30
+ 'value': [
31
+ {
32
+ id: 1,
33
+ parentId: '123',
34
+ dimensionId: '123',
35
+ dimensionCode: 'ABC',
36
+ dimensionValueId: 1,
37
+ dimensionValueCode: 'DEF'
38
+ }
39
+ ]
40
+ }.to_json,
41
+ )
42
+
43
+ response = @default_dimension.find_all
44
+ assert_equal response.first[:parent_id], '123'
45
+ end
46
+
47
+ def test_find_by_id
48
+ test_id = '2'
49
+ stub_request(:get, /defaultDimensions\(#{test_id}\)/)
50
+ .to_return(
51
+ status: 200,
52
+ body: {
53
+ id: test_id,
54
+ parentId: '123',
55
+ dimensionId: '123',
56
+ dimensionCode: 'ABC',
57
+ dimensionValueId: 1,
58
+ dimensionValueCode: 'DEF'
59
+ }.to_json
60
+ )
61
+
62
+ response = @default_dimension.find_by_id(test_id)
63
+ assert_equal response[:dimension_code], 'ABC'
64
+ end
65
+
66
+ def test_where
67
+ test_filter = "dimensionCode eq 'ABC'"
68
+ stub_request(:get, /defaultDimensions\?\$filter=#{test_filter}/)
69
+ .to_return(
70
+ status: 200,
71
+ body: {
72
+ 'value': [
73
+ {
74
+ id: 3,
75
+ parentId: '123',
76
+ dimensionId: '123',
77
+ dimensionCode: 'ABC',
78
+ dimensionValueId: 1,
79
+ dimensionValueCode: 'DEF'
80
+ }
81
+ ]
82
+ }.to_json
83
+ )
84
+
85
+ response = @default_dimension.where(test_filter)
86
+ assert_equal response.first[:dimension_code], 'ABC'
87
+ end
88
+
89
+ def test_create
90
+ stub_request(:post, /defaultDimensions/)
91
+ .to_return(
92
+ status: 200,
93
+ body: {
94
+ id: 4,
95
+ parentId: '123',
96
+ dimensionId: '123',
97
+ dimensionCode: 'ABC',
98
+ dimensionValueId: 1,
99
+ dimensionValueCode: 'DEF'
100
+ }.to_json
101
+ )
102
+
103
+ response = @default_dimension.create({
104
+ dimension_code: 'DEF',
105
+ dimension_value_code: 'GHI'
106
+ })
107
+ assert_equal response[:id], 4
108
+ end
109
+
110
+
111
+ def test_update
112
+ test_id = '2'
113
+ stub_request(:get, /defaultDimensions\(#{test_id}\)/)
114
+ .to_return(
115
+ status: 200,
116
+ body: {
117
+ etag: '3333',
118
+ id: test_id,
119
+ parentId: '123',
120
+ dimensionId: '123',
121
+ dimensionCode: 'ABC',
122
+ dimensionValueId: 1,
123
+ dimensionValueCode: 'DEF'
124
+ }.to_json
125
+ )
126
+
127
+ stub_request(:patch, /defaultDimensions\(#{test_id}\)/)
128
+ .to_return(
129
+ status: 200,
130
+ body: {
131
+ etag: '4444',
132
+ id: test_id,
133
+ parentId: '123',
134
+ dimensionId: '123',
135
+ dimensionCode: 'ZYX',
136
+ dimensionValueId: 1,
137
+ dimensionValueCode: 'DEF'
138
+ }.to_json
139
+ )
140
+
141
+ response = @default_dimension.update(
142
+ test_id,
143
+ {
144
+ dimension_code: 'ZYX'
145
+ }
146
+ )
147
+ assert_equal response[:dimension_code], 'ZYX'
148
+ end
149
+
150
+ def test_delete
151
+ test_id = '33333'
152
+ stub_request(:get, /defaultDimensions\(#{test_id}\)/)
153
+ .to_return(
154
+ status: 200,
155
+ body: {
156
+ etag: '5555',
157
+ id: test_id,
158
+ parentId: '123',
159
+ dimensionId: '123',
160
+ dimensionCode: 'ZYX',
161
+ dimensionValueId: 1,
162
+ dimensionValueCode: 'DEF'
163
+ }.to_json
164
+ )
165
+
166
+ stub_request(:delete, /defaultDimensions\(#{test_id}\)/)
167
+ .to_return(status: 204)
168
+
169
+ assert @default_dimension.destroy(test_id)
170
+ end
171
+ end