business_central 0.9.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 (152) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +37 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE +373 -0
  5. data/README.md +67 -0
  6. data/Rakefile +41 -0
  7. data/azure-pipelines.yml +30 -0
  8. data/business_central.gemspec +31 -0
  9. data/lib/business_central/account.rb +9 -0
  10. data/lib/business_central/aged_accounts_payable.rb +10 -0
  11. data/lib/business_central/aged_accounts_receivable.rb +10 -0
  12. data/lib/business_central/api_methods.rb +220 -0
  13. data/lib/business_central/balance_sheet.rb +10 -0
  14. data/lib/business_central/base.rb +56 -0
  15. data/lib/business_central/cash_flow_statement.rb +10 -0
  16. data/lib/business_central/client.rb +128 -0
  17. data/lib/business_central/company.rb +9 -0
  18. data/lib/business_central/company_information.rb +10 -0
  19. data/lib/business_central/countries_region.rb +9 -0
  20. data/lib/business_central/currency.rb +9 -0
  21. data/lib/business_central/customer.rb +9 -0
  22. data/lib/business_central/customer_financial_details.rb +10 -0
  23. data/lib/business_central/customer_payment.rb +14 -0
  24. data/lib/business_central/customer_payments_journal.rb +10 -0
  25. data/lib/business_central/customer_sales.rb +10 -0
  26. data/lib/business_central/dimension.rb +10 -0
  27. data/lib/business_central/dimension_line.rb +14 -0
  28. data/lib/business_central/employee.rb +10 -0
  29. data/lib/business_central/general_ledger_entry.rb +10 -0
  30. data/lib/business_central/income_statement.rb +10 -0
  31. data/lib/business_central/irs_1099_code.rb +10 -0
  32. data/lib/business_central/item.rb +10 -0
  33. data/lib/business_central/item_category.rb +10 -0
  34. data/lib/business_central/journal.rb +10 -0
  35. data/lib/business_central/journal_line.rb +14 -0
  36. data/lib/business_central/payment_method.rb +10 -0
  37. data/lib/business_central/payment_term.rb +10 -0
  38. data/lib/business_central/picture.rb +10 -0
  39. data/lib/business_central/purchase_invoice.rb +10 -0
  40. data/lib/business_central/purchase_invoice_line.rb +43 -0
  41. data/lib/business_central/request_builder.rb +60 -0
  42. data/lib/business_central/response/response_handler.rb +57 -0
  43. data/lib/business_central/retained_earnings_statement.rb +9 -0
  44. data/lib/business_central/sales_credit_memo.rb +10 -0
  45. data/lib/business_central/sales_credit_memo_line.rb +14 -0
  46. data/lib/business_central/sales_invoice.rb +10 -0
  47. data/lib/business_central/sales_invoice_line.rb +25 -0
  48. data/lib/business_central/sales_order.rb +9 -0
  49. data/lib/business_central/sales_order_line.rb +14 -0
  50. data/lib/business_central/sales_quote.rb +10 -0
  51. data/lib/business_central/sales_quote_line.rb +14 -0
  52. data/lib/business_central/shipment_method.rb +10 -0
  53. data/lib/business_central/subscription.rb +63 -0
  54. data/lib/business_central/tax_area.rb +10 -0
  55. data/lib/business_central/tax_group.rb +10 -0
  56. data/lib/business_central/trial_balance.rb +10 -0
  57. data/lib/business_central/unit_of_measure.rb +10 -0
  58. data/lib/business_central/url_builder.rb +33 -0
  59. data/lib/business_central/vendor.rb +10 -0
  60. data/lib/business_central/vendor_purchase.rb +10 -0
  61. data/lib/business_central/version.rb +3 -0
  62. data/lib/business_central.rb +67 -0
  63. data/test/business_central/account_test.rb +26 -0
  64. data/test/business_central/aged_accounts_payable_test.rb +8 -0
  65. data/test/business_central/aged_accounts_receivable_test.rb +8 -0
  66. data/test/business_central/base_test.rb +28 -0
  67. data/test/business_central/company_information_test.rb +8 -0
  68. data/test/business_central/company_test.rb +27 -0
  69. data/test/business_central/countries_region_test.rb +69 -0
  70. data/test/business_central/currency_test.rb +8 -0
  71. data/test/business_central/customer_financial_details_test.rb +20 -0
  72. data/test/business_central/customer_payment_test.rb +8 -0
  73. data/test/business_central/customer_payments_journal_test.rb +8 -0
  74. data/test/business_central/customer_sales_test.rb +8 -0
  75. data/test/business_central/customer_test.rb +138 -0
  76. data/test/business_central/dimension_line_test.rb +8 -0
  77. data/test/business_central/dimension_test.rb +8 -0
  78. data/test/business_central/employee_test.rb +8 -0
  79. data/test/business_central/general_ledger_entry_test.rb +8 -0
  80. data/test/business_central/income_statement_test.rb +8 -0
  81. data/test/business_central/irs_1099_code_test.rb +8 -0
  82. data/test/business_central/item_category_test.rb +8 -0
  83. data/test/business_central/item_test.rb +8 -0
  84. data/test/business_central/journal_line_test.rb +8 -0
  85. data/test/business_central/journal_test.rb +8 -0
  86. data/test/business_central/payment_method_test.rb +8 -0
  87. data/test/business_central/payment_term_test.rb +27 -0
  88. data/test/business_central/picture_test.rb +8 -0
  89. data/test/business_central/purchase_invoice_line_test.rb +33 -0
  90. data/test/business_central/purchase_invoice_test.rb +8 -0
  91. data/test/business_central/request_builder_test.rb +43 -0
  92. data/test/business_central/response/response_handler_test.rb +58 -0
  93. data/test/business_central/sales_credit_memo_line_test.rb +8 -0
  94. data/test/business_central/sales_credit_memo_test.rb +8 -0
  95. data/test/business_central/sales_invoice_line_test.rb +58 -0
  96. data/test/business_central/sales_invoice_test.rb +40 -0
  97. data/test/business_central/sales_order_line_test.rb +8 -0
  98. data/test/business_central/sales_order_test.rb +32 -0
  99. data/test/business_central/sales_quote_line_test.rb +8 -0
  100. data/test/business_central/sales_quote_test.rb +8 -0
  101. data/test/business_central/shipment_method_test.rb +19 -0
  102. data/test/business_central/subscription_test.rb +0 -0
  103. data/test/business_central/tax_area_test.rb +19 -0
  104. data/test/business_central/tax_group_test.rb +19 -0
  105. data/test/business_central/trial_balance_test.rb +8 -0
  106. data/test/business_central/unit_of_measure_test.rb +19 -0
  107. data/test/business_central/url_builder_test.rb +19 -0
  108. data/test/business_central/vendor_purchase_test.rb +8 -0
  109. data/test/business_central/vendor_test.rb +8 -0
  110. data/test/client_test.rb +72 -0
  111. data/test/fixtures/filter_customers_200.json +1 -0
  112. data/test/fixtures/get_account_200.json +1 -0
  113. data/test/fixtures/get_accounts_200.json +1 -0
  114. data/test/fixtures/get_companies_200.json +1 -0
  115. data/test/fixtures/get_company_200.json +1 -0
  116. data/test/fixtures/get_countriesRegion_200.json +1 -0
  117. data/test/fixtures/get_countriesRegions_200.json +1 -0
  118. data/test/fixtures/get_currencies_200.json +1 -0
  119. data/test/fixtures/get_currency_200.json +1 -0
  120. data/test/fixtures/get_customer_200.json +1 -0
  121. data/test/fixtures/get_customer_expanded_200.json +1 -0
  122. data/test/fixtures/get_customer_financial_details_200.json +1 -0
  123. data/test/fixtures/get_customers_200.json +1 -0
  124. data/test/fixtures/get_paymentMethod_200.json +1 -0
  125. data/test/fixtures/get_paymentMethods_200.json +1 -0
  126. data/test/fixtures/get_paymentTerm_200.json +1 -0
  127. data/test/fixtures/get_paymentTerms_200.json +1 -0
  128. data/test/fixtures/get_purchaseInvoiceLine_200.json +1 -0
  129. data/test/fixtures/get_purchaseInvoiceLines_200.json +1 -0
  130. data/test/fixtures/get_purchaseInvoice_200.json +1 -0
  131. data/test/fixtures/get_purchase_invoices_200.json +1 -0
  132. data/test/fixtures/get_salesInvoiceLine_200.json +1 -0
  133. data/test/fixtures/get_salesInvoiceLines_200.json +1 -0
  134. data/test/fixtures/get_salesInvoiceLines_single_200.json +1 -0
  135. data/test/fixtures/get_salesInvoice_200.json +1 -0
  136. data/test/fixtures/get_salesInvoices_200.json +1 -0
  137. data/test/fixtures/get_salesOrder_200.json +1 -0
  138. data/test/fixtures/get_salesOrders_200.json +1 -0
  139. data/test/fixtures/get_shipmentMethods_200.json +1 -0
  140. data/test/fixtures/get_taxAreas_200.json +1 -0
  141. data/test/fixtures/get_taxGroups_200.json +1 -0
  142. data/test/fixtures/get_unitsOfMeasure_200.json +1 -0
  143. data/test/fixtures/patch_countriesRegion_200.json +1 -0
  144. data/test/fixtures/patch_customer_200.json +1 -0
  145. data/test/fixtures/post_countriesRegion_200.json +1 -0
  146. data/test/fixtures/post_customer_200.json +1 -0
  147. data/test/fixtures/post_customer_409.json +1 -0
  148. data/test/fixtures/post_salesInvoiceLine_200.json +1 -0
  149. data/test/fixtures/post_salesInvoice_200.json +1 -0
  150. data/test/fixtures/post_subscription_200.json +1 -0
  151. data/test/test_helper.rb +86 -0
  152. metadata +408 -0
@@ -0,0 +1,69 @@
1
+ require 'test_helper'
2
+
3
+ class BusinessCentral::CountriesRegionTest < Test::Unit::TestCase
4
+ def test_initialize
5
+ api_country = BusinessCentral::CountriesRegion.new(bc_client)
6
+ assert_not_nil api_country
7
+ end
8
+
9
+ def test_get_country_region
10
+ stub_get("countriesRegions(1234)").
11
+ with(headers: stub_headers).
12
+ to_return(status: 200, body: fixture("get_countriesRegion_200.json"))
13
+
14
+ country = BusinessCentral::CountriesRegion.new(bc_client).get("1234")
15
+ assert_equal "Brazil", country.displayName
16
+ end
17
+
18
+ def test_get_countries_regions
19
+ stub_get("countriesRegions").
20
+ with(headers: stub_headers).
21
+ to_return(status: 200, body: fixture("get_countriesRegions_200.json"))
22
+
23
+ countries = BusinessCentral::CountriesRegion.new(bc_client).get()
24
+ assert countries.length > 0
25
+ end
26
+
27
+ def test_patch_countries_region
28
+ data = { displayName: "AustraliaFeet" }
29
+ etag = "W/\"JzQ0OzVWd1JHeEdVQ0p3bkZTVWhQMVlsakhYcDdLRmxwUDJQV1BxWERkdWNtbEk9MTswMDsn\""
30
+
31
+ stub_patch("countriesRegions(1234)").
32
+ with(headers: stub_headers.merge({'If-Match'=>etag}), body: data).
33
+ to_return(status: 200, body: fixture("patch_countriesRegion_200.json"))
34
+
35
+ country = BusinessCentral::CountriesRegion.new(bc_client).
36
+ update("1234", etag, data)
37
+
38
+ assert_equal "AustraliaFeet", country.displayName
39
+ end
40
+
41
+ def test_create_countries_region
42
+ stub_post("countriesRegions").
43
+ with(headers: stub_headers, body: new_country_region).
44
+ to_return(status: 201, body: fixture("post_countriesRegion_200.json"))
45
+
46
+ country = BusinessCentral::CountriesRegion.new(bc_client).
47
+ create(new_country_region)
48
+
49
+ assert_equal "New Country", country.displayName
50
+ end
51
+
52
+ def test_delete_countries_region
53
+ etag = "W/\"JzQ0OzVWd1JHeEdVQ0p3bkZTVWhQMVlsakhYcDdLRmxwUDJQV1BxWERkdWNtbEk9MTswMDsn\""
54
+
55
+ stub_delete("countriesRegions(1234)").
56
+ with(headers: stub_headers.merge({'If-Match'=>etag})).
57
+ to_return(status: 204)
58
+
59
+ assert_equal "204", BusinessCentral::CountriesRegion.new(bc_client).delete("1234", etag)
60
+ end
61
+
62
+ def new_country_region
63
+ {
64
+ "code": "CF",
65
+ "displayName": "Chicken Feet",
66
+ "addressFormat": "City+County+State+Post Code"
67
+ }
68
+ end
69
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class BusinessCentral::CurrencyTest < Test::Unit::TestCase
4
+ def test_initialize
5
+ currency = BusinessCentral::Currency.new(bc_client)
6
+ assert_not_nil currency
7
+ end
8
+ end
@@ -0,0 +1,20 @@
1
+ require 'test_helper'
2
+
3
+ class BusinessCentral::CustomerFinancialDetailsTest < Test::Unit::TestCase
4
+ def test_initialize
5
+ cust_details = BusinessCentral::CustomerFinancialDetails.new(bc_client)
6
+ assert_not_nil cust_details
7
+ end
8
+
9
+ test "should retrieve all customerFinancialDetails" do
10
+ stub_get("customerFinancialDetails").
11
+ with(headers: stub_headers).
12
+ to_return(
13
+ status: 200,
14
+ body: fixture("get_customer_financial_details_200.json")
15
+ )
16
+ cust_details = BusinessCentral::CustomerFinancialDetails.new(bc_client).get()
17
+ assert cust_details.is_a?(Array)
18
+ assert cust_details.length > 0
19
+ end
20
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class BusinessCentral::CustomerPaymentTest < Test::Unit::TestCase
4
+ def test_initialize
5
+ api = BusinessCentral::CustomerPayment.new(bc_client)
6
+ assert_not_nil api
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class BusinessCentral::CustomerPaymentsJournalTest < Test::Unit::TestCase
4
+ def test_initialize
5
+ api = BusinessCentral::CustomerPaymentsJournal.new(bc_client)
6
+ assert_not_nil api
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class BusinessCentral::CustomerSalesTest < Test::Unit::TestCase
4
+ def test_initialize
5
+ customer_sales = BusinessCentral::CustomerSales.new(bc_client)
6
+ assert_not_nil customer_sales
7
+ end
8
+ end
@@ -0,0 +1,138 @@
1
+ require 'test_helper'
2
+
3
+ class BusinessCentral::CustomerTest < Test::Unit::TestCase
4
+ def test_initialize
5
+ api_customer = BusinessCentral::Customer.new(bc_client)
6
+ assert_not_nil api_customer
7
+ end
8
+
9
+ def test_customers_success
10
+ stub_get("customers").with(headers: stub_headers).
11
+ to_return(
12
+ status: 200,
13
+ body: fixture("get_customers_200.json")
14
+ )
15
+
16
+ customers = BusinessCentral::Customer.new(bc_client).get
17
+ assert customers.length > 0
18
+ end
19
+
20
+ def test_customer_success
21
+ stub_get("customers(1234)").with(headers: stub_headers).
22
+ to_return(status: 200, body: fixture("get_customer_200.json"))
23
+
24
+ customer = BusinessCentral::Customer.new(bc_client).get("1234")
25
+ assert_equal "School of Fine Art", customer.displayName
26
+ end
27
+
28
+ test "should return the extra details for a customer" do
29
+ stub_get("customers(1234)?$expand=customerFinancialDetails").
30
+ with(headers: stub_headers).
31
+ to_return(
32
+ status: 200,
33
+ body: fixture("get_customer_expanded_200.json"))
34
+
35
+ customer = BusinessCentral::Customer.new(bc_client).get("1234", "$expand=customerFinancialDetails")
36
+ assert_equal "School of Fine Art", customer.displayName
37
+ assert_equal 95193, customer.customerFinancialDetails.first.balance
38
+ end
39
+
40
+ def test_customer_filter
41
+ stub_get("customers?$filter=number eq '1234'").
42
+ with(headers: stub_headers).
43
+ to_return(
44
+ status: 200,
45
+ body: fixture("filter_customers_200.json"))
46
+
47
+ search = BusinessCentral::Customer.new(bc_client).query("number eq '1234'")
48
+ assert_equal "School of Fine Art", search.first.displayName
49
+ end
50
+
51
+ def test_customer_update
52
+ data = { displayName: "Bill Example" }
53
+ etag = "W/\"JzQ0O1JpdzI0TmU4NEpRS0R6cHAzTkVBdHpxYXorc0VLbnJ4OVQyTFJjclREeG89MTswMDsn\""
54
+
55
+ stub_patch("customers(1234)").with(
56
+ headers: stub_headers.merge({'If-Match'=>etag}),
57
+ body: data
58
+ ).to_return(
59
+ status: 200,
60
+ body: fixture("patch_customer_200.json"))
61
+
62
+ customer = BusinessCentral::Customer.new(bc_client).
63
+ update("1234", etag, data)
64
+
65
+ assert_equal "Updated Customer Name", customer.displayName
66
+ end
67
+
68
+ def test_customer_create
69
+ stub_post("customers").
70
+ with(headers: stub_headers,
71
+ body: new_customer).
72
+ to_return(
73
+ status: 201,
74
+ body: fixture("post_customer_200.json"))
75
+
76
+ customer = BusinessCentral::Customer.new(bc_client).
77
+ create(new_customer)
78
+
79
+ assert_equal "Coho Winery", customer.displayName
80
+ assert_equal "Person", customer.type
81
+ assert_equal "CAD", customer.currencyCode
82
+ end
83
+
84
+ test "should return an error when a customer already exists" do
85
+ stub_post("customers").
86
+ with(headers: stub_headers, body: new_customer).
87
+ to_return(
88
+ status: 409,
89
+ body: fixture("post_customer_409.json"))
90
+
91
+ customer = BusinessCentral::Customer.
92
+ new(bc_client).
93
+ create(new_customer)
94
+
95
+ assert_not_nil customer.error
96
+ assert_equal "Internal_EntityWithSameKeyExists", customer.error.code
97
+ assert_match(/Customer already exists/, customer.error.message)
98
+ end
99
+
100
+ def new_customer
101
+ {
102
+ "number": "10000",
103
+ "displayName": "Coho Winery",
104
+ "type": "Company",
105
+ "address": "{
106
+ :street => \"192 Market Square\",
107
+ :city => \"Atlanta\",
108
+ :state => \"GA\",
109
+ :countryLetterCode => \"US\",
110
+ :postalCode => \"31772\"
111
+ }",
112
+ "phoneNumber": "",
113
+ "email": "jim.glynn@cronuscorp.net",
114
+ "website": "",
115
+ "taxLiable": true,
116
+ "taxAreaId": "taxAreaId-value",
117
+ "taxAreaDisplayName": "tax area",
118
+ "taxRegistrationNumber": "28012001T",
119
+ "currencyId": "currencyId-value",
120
+ "currencyCode": "USD",
121
+ "paymentTermsId": "paymentTermsId-value",
122
+ "paymentTerms": "{
123
+ :code => \"1M(8D)\",
124
+ :description => \"1 Month/2% 8 Days\"
125
+ }",
126
+ "shipmentMethodId": "shipmentMethodId-value",
127
+ "shipmentMethod": nil,
128
+ "paymentMethodId": "paymentMethodId-value",
129
+ "paymentMethod": "{
130
+ :code => \"BANK\",
131
+ :description => \"Bank Transfer\"
132
+ }",
133
+ "blocked": " ",
134
+ "overdueAmount": 0,
135
+ "totalSalesExcludingTax": 0,
136
+ }
137
+ end
138
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class BusinessCentral::DimensionLineTest < Test::Unit::TestCase
4
+ def test_initialize
5
+ api = BusinessCentral::DimensionLine.new(bc_client)
6
+ assert_not_nil api
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class BusinessCentral::DimensionTest < Test::Unit::TestCase
4
+ def test_initialize
5
+ api = BusinessCentral::Dimension.new(bc_client)
6
+ assert_not_nil api
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class BusinessCentral::EmployeeTest < Test::Unit::TestCase
4
+ def test_initialize
5
+ employee = BusinessCentral::Employee.new(bc_client)
6
+ assert_not_nil employee
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class BusinessCentral::GeneralLedgerEntryTest < Test::Unit::TestCase
4
+ def test_initialize
5
+ api = BusinessCentral::GeneralLedgerEntry.new(bc_client)
6
+ assert_not_nil api
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class BusinessCentral::IncomeStatementTest < Test::Unit::TestCase
4
+ def test_initialize
5
+ api = BusinessCentral::IncomeStatement.new(bc_client)
6
+ assert_not_nil api
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class BusinessCentral::Irs1099CodeTest < Test::Unit::TestCase
4
+ def test_initialize
5
+ api = BusinessCentral::Irs1099Code.new(bc_client)
6
+ assert_not_nil api
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class BusinessCentral::ItemCategoryTest < Test::Unit::TestCase
4
+ def test_initialize
5
+ category = BusinessCentral::ItemCategory.new(bc_client)
6
+ assert_not_nil category
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class BusinessCentral::ItemTest < Test::Unit::TestCase
4
+ def test_initialize
5
+ item = BusinessCentral::Item.new(bc_client)
6
+ assert_not_nil item
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class BusinessCentral::JournalLineTest < Test::Unit::TestCase
4
+ def test_initialize
5
+ api = BusinessCentral::JournalLine.new(bc_client)
6
+ assert_not_nil api
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class BusinessCentral::JournalTest < Test::Unit::TestCase
4
+ def test_initialize
5
+ journal = BusinessCentral::Journal.new(bc_client)
6
+ assert_not_nil journal
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class BusinessCentral::PaymentMethodTest < Test::Unit::TestCase
4
+ def test_initialize
5
+ payment_method = BusinessCentral::PaymentMethod.new(bc_client)
6
+ assert_not_nil payment_method
7
+ end
8
+ end
@@ -0,0 +1,27 @@
1
+ require 'test_helper'
2
+
3
+ class BusinessCentral::PaymentTermTest < Test::Unit::TestCase
4
+ def test_initialize
5
+ payment_term = BusinessCentral::PaymentTerm.new(bc_client)
6
+ assert_not_nil payment_term
7
+ end
8
+
9
+ test "should return a list of paymentTerms" do
10
+ stub_get("paymentTerms").
11
+ with(headers: stub_headers).
12
+ to_return(status: 200, body: fixture("get_paymentTerms_200.json"))
13
+
14
+ terms = BusinessCentral::PaymentTerm.new(bc_client).get
15
+ assert terms.is_a?(Array)
16
+ end
17
+
18
+ test "should get a single PaymentTerm" do
19
+ stub_get("paymentTerms(1234)").
20
+ with(headers: stub_headers).
21
+ to_return(status: 200, body: fixture("get_paymentTerm_200.json"))
22
+
23
+ term = BusinessCentral::PaymentTerm.new(bc_client).get("1234")
24
+
25
+ assert_equal "7 DAYS", term.code
26
+ end
27
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class BusinessCentral::PictureTest < Test::Unit::TestCase
4
+ def test_initialize
5
+ api = BusinessCentral::Picture.new(bc_client)
6
+ assert_not_nil api
7
+ end
8
+ end
@@ -0,0 +1,33 @@
1
+ require 'test_helper'
2
+
3
+ class BusinessCentral::PurchaseInvoiceLineTest < Test::Unit::TestCase
4
+ def test_initialize
5
+ purchaseInvoiceLine = BusinessCentral::PurchaseInvoiceLine.new(bc_client)
6
+ assert_not_nil purchaseInvoiceLine
7
+ end
8
+
9
+ def test_get_collection
10
+ stub_get("purchaseInvoices(1234)/purchaseInvoiceLines").
11
+ with(headers: stub_headers).
12
+ to_return(status: 200,
13
+ body: fixture("get_purchaseInvoiceLines_200.json"))
14
+
15
+ invoiceLines =
16
+ BusinessCentral::PurchaseInvoiceLine.new(bc_client).get("1234")
17
+
18
+ # assert invoiceLines.length > 0
19
+ end
20
+
21
+ def test_get_invoice
22
+ stub_get("purchaseInvoices(1234)/purchaseInvoiceLines(4321-10000)").
23
+ with(headers: stub_headers).
24
+ to_return(status: 200,
25
+ body: fixture("get_purchaseInvoiceLine_200.json"))
26
+
27
+ invoiceLine =
28
+ BusinessCentral::PurchaseInvoiceLine.new(bc_client).
29
+ get("1234", "4321-10000")
30
+
31
+ assert_equal "LONDON Swivel Chair, blue", invoiceLine.description
32
+ end
33
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class BusinessCentral::PurchaseInvoiceTest < Test::Unit::TestCase
4
+ def test_initialize
5
+ purchase_invoice = BusinessCentral::PurchaseInvoice.new(bc_client)
6
+ assert_not_nil purchase_invoice
7
+ end
8
+ end
@@ -0,0 +1,43 @@
1
+ require 'test_helper'
2
+
3
+ class BusinessCentral::RequestBuilderTest < Test::Unit::TestCase
4
+ def test_initialize
5
+ @builder = BusinessCentral::RequestBuilder.new(bc_client, { verb: "Get",
6
+ url: "/customers" })
7
+ assert_not_nil @builder
8
+ assert_equal "Get", @builder.verb
9
+ assert_equal "/customers", @builder.url
10
+ end
11
+
12
+ def test_request_object
13
+ @builder = BusinessCentral::RequestBuilder.new(bc_client, { verb: "Get",
14
+ url: "/customers" })
15
+ assert_equal Net::HTTP::Get, @builder.request_object
16
+ end
17
+
18
+ def test_uri
19
+ @builder = BusinessCentral::RequestBuilder.new(bc_client, { verb: "Get",
20
+ url: "/customers" })
21
+ assert_equal URI("#{bc_client.base_url}/customers"), @builder.uri
22
+ end
23
+
24
+ def test_build
25
+ @builder = BusinessCentral::RequestBuilder.new(bc_client, { verb: "Get",
26
+ url: "/customers" })
27
+ assert_equal "Net::HTTP::Get", @builder.request.class.to_s
28
+ end
29
+
30
+ def test_build_adds_etag
31
+ @builder = BusinessCentral::RequestBuilder.new(bc_client, { verb: "Get",
32
+ etag: "FOOBAR",
33
+ url: "/customers" })
34
+ assert_equal ["FOOBAR"], @builder.request.get_fields('If-Match')
35
+ end
36
+
37
+ def test_build_adds_data
38
+ @builder = BusinessCentral::RequestBuilder.new(bc_client, { verb: "Post",
39
+ url: "/customers",
40
+ data: { displayName: "Chicken Feet" } })
41
+ end
42
+
43
+ end
@@ -0,0 +1,58 @@
1
+ require 'test_helper'
2
+
3
+ class BusinessCentral::Response::ResponseHandlerTest < Test::Unit::TestCase
4
+
5
+ test "should process the returned data" do
6
+ response = BusinessCentral::Response::ResponseHandler.
7
+ new(sample_company.to_json)
8
+ company = response.compiled_data.first
9
+ assert_equal "1234", company.id
10
+ end
11
+
12
+ test "should process returned data with an address" do
13
+ sample = sample_company.merge({"address":sample_address}).to_json
14
+ response = BusinessCentral::Response::ResponseHandler.new(sample)
15
+ company = response.compiled_data.first
16
+ assert_equal "1234 Fake St", company.address[:street]
17
+ end
18
+
19
+ test "should process data returned with customer financials" do
20
+ sample = sample_company.merge({
21
+ "customerFinancialDetails":sample_financial_data
22
+ }).to_json
23
+ response = BusinessCentral::Response::ResponseHandler.new(sample)
24
+ company = response.compiled_data.first
25
+
26
+ assert_equal "616", company.customerFinancialDetails.first.balance
27
+ end
28
+
29
+ def sample_company
30
+ {
31
+ "@odata.etag":"ETAG",
32
+ "id":"1234",
33
+ "number":"4321",
34
+ "displayName":"Chicken Feet"
35
+ }
36
+ end
37
+
38
+ def sample_address
39
+ {
40
+ "street":"1234 Fake St",
41
+ "city":"Fake Town",
42
+ "state":"EX",
43
+ "countryLetterCode":"AU",
44
+ "postalCode":"6000"
45
+ }
46
+ end
47
+
48
+ def sample_financial_data
49
+ [{
50
+ "@odata.etag": "ETAG_FINANCIAL",
51
+ "id":"1234",
52
+ "number":"4321",
53
+ "balance":"616",
54
+ "totalSalesExcludingTax":16380.55,
55
+ "overdueAmount":616
56
+ }]
57
+ end
58
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class BusinessCentral::SalesCreditMemoLineTest < Test::Unit::TestCase
4
+ test "should initialize" do
5
+ api = BusinessCentral::SalesCreditMemoLine.new(bc_client)
6
+ assert_not_nil api
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class BusinessCentral::SalesCreditMemoTest < Test::Unit::TestCase
4
+ def test_initialize
5
+ sales_credit_memo = BusinessCentral::SalesCreditMemo.new(bc_client)
6
+ assert_not_nil sales_credit_memo
7
+ end
8
+ end
@@ -0,0 +1,58 @@
1
+ require 'test_helper'
2
+
3
+ class BusinessCentral::SalesInvoiceLineTest < Test::Unit::TestCase
4
+ def test_initialize
5
+ api = BusinessCentral::SalesInvoiceLine.new(bc_client)
6
+ assert_not_nil api
7
+ end
8
+
9
+ test "should return a sales invoice line" do
10
+ stub_get("salesInvoices(1234)/salesInvoiceLines(4321-10000)").
11
+ with(headers: stub_headers).
12
+ to_return(status: 200, body: fixture("get_salesInvoiceLine_200.json"))
13
+
14
+ invoiceLine = BusinessCentral::SalesInvoiceLine.new(bc_client).get("1234", "4321-10000")
15
+ assert_equal "ROME Guest Chair, green", invoiceLine.description
16
+ end
17
+
18
+ test "should return all invoice lines for a given salesInvoice" do
19
+ stub_get("salesInvoices(1234)/salesInvoiceLines").
20
+ with(headers: stub_headers).
21
+ to_return(status:200, body: fixture("get_salesInvoiceLines_200.json"))
22
+
23
+ invoiceLines = BusinessCentral::SalesInvoiceLine.new(bc_client).get("1234")
24
+ assert invoiceLines.is_a?(Array)
25
+
26
+ assert_equal "LONDON Swivel Chair, blue", invoiceLines.first.description
27
+ end
28
+
29
+ test "should return salesInvoiceLines when only one line exists" do
30
+ stub_get("salesInvoices(1234)/salesInvoiceLines").
31
+ with(headers: stub_headers).
32
+ to_return(status:200, body: fixture("get_salesInvoiceLines_single_200.json"))
33
+
34
+ invoiceLines = BusinessCentral::SalesInvoiceLine.new(bc_client).get("1234")
35
+ assert invoiceLines.is_a?(Array)
36
+
37
+ assert_equal "ROME Guest Chair, green", invoiceLines.first.description
38
+ end
39
+
40
+ test "should be able to create a new invoiceLine" do
41
+ stub_post("salesInvoices(1234)/salesInvoiceLines").
42
+ with(headers: stub_headers).
43
+ to_return(status: 200, body: fixture("post_salesInvoiceLine_200.json"))
44
+
45
+ invoiceLine = BusinessCentral::SalesInvoiceLine.new(bc_client).create(1234, new_invoice_line)
46
+
47
+ assert_equal "Conference Bundle 1-6", invoiceLine.description
48
+ assert_equal "1925-W", invoiceLine.lineDetails["number"]
49
+ end
50
+
51
+ def new_invoice_line
52
+ {
53
+ "itemId": "1234",
54
+ "lineType": "Item",
55
+ "quantity": 10
56
+ }
57
+ end
58
+ end