netsuite 0.8.5 → 0.8.9

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 (84) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/main.yml +20 -0
  3. data/.ruby-version +1 -1
  4. data/.tool-versions +1 -0
  5. data/Gemfile +1 -5
  6. data/HISTORY.md +32 -0
  7. data/README.md +48 -21
  8. data/Rakefile +1 -1
  9. data/lib/netsuite/configuration.rb +21 -4
  10. data/lib/netsuite/records/accounting_period.rb +2 -2
  11. data/lib/netsuite/records/assembly_unbuild.rb +1 -3
  12. data/lib/netsuite/records/classification.rb +4 -1
  13. data/lib/netsuite/records/contact.rb +1 -1
  14. data/lib/netsuite/records/cost_category.rb +28 -0
  15. data/lib/netsuite/records/credit_memo.rb +1 -1
  16. data/lib/netsuite/records/currency_rate.rb +1 -1
  17. data/lib/netsuite/records/custom_field_list.rb +9 -3
  18. data/lib/netsuite/records/custom_record.rb +1 -1
  19. data/lib/netsuite/records/customer.rb +2 -1
  20. data/lib/netsuite/records/customer_credit_cards.rb +36 -0
  21. data/lib/netsuite/records/customer_credit_cards_list.rb +10 -0
  22. data/lib/netsuite/records/customer_deposit.rb +5 -5
  23. data/lib/netsuite/records/customer_payment.rb +6 -2
  24. data/lib/netsuite/records/customer_payment_credit.rb +17 -0
  25. data/lib/netsuite/records/customer_payment_credit_list.rb +12 -0
  26. data/lib/netsuite/records/employee.rb +1 -1
  27. data/lib/netsuite/records/estimate.rb +42 -0
  28. data/lib/netsuite/records/estimate_item.rb +40 -0
  29. data/lib/netsuite/records/estimate_item_list.rb +11 -0
  30. data/lib/netsuite/records/inventory_item.rb +62 -1
  31. data/lib/netsuite/records/invoice.rb +97 -4
  32. data/lib/netsuite/records/invoice_item.rb +1 -1
  33. data/lib/netsuite/records/item_fulfillment.rb +1 -1
  34. data/lib/netsuite/records/item_fulfillment_item.rb +1 -1
  35. data/lib/netsuite/records/item_receipt_item.rb +1 -1
  36. data/lib/netsuite/records/member_list.rb +0 -2
  37. data/lib/netsuite/records/non_inventory_purchase_item.rb +1 -1
  38. data/lib/netsuite/records/non_inventory_resale_item.rb +2 -1
  39. data/lib/netsuite/records/non_inventory_sale_item.rb +1 -1
  40. data/lib/netsuite/records/opportunity.rb +2 -2
  41. data/lib/netsuite/records/partner.rb +7 -5
  42. data/lib/netsuite/records/phone_call.rb +1 -1
  43. data/lib/netsuite/records/serialized_assembly_item.rb +3 -2
  44. data/lib/netsuite/records/service_resale_item.rb +2 -2
  45. data/lib/netsuite/records/service_sale_item.rb +1 -1
  46. data/lib/netsuite/records/transfer_order_item.rb +1 -1
  47. data/lib/netsuite/records/vendor.rb +6 -5
  48. data/lib/netsuite/records/vendor_currency.rb +26 -0
  49. data/lib/netsuite/records/vendor_currency_list.rb +9 -0
  50. data/lib/netsuite/support/fields.rb +17 -0
  51. data/lib/netsuite/support/records.rb +1 -1
  52. data/lib/netsuite/support/search_result.rb +23 -4
  53. data/lib/netsuite/utilities.rb +2 -1
  54. data/lib/netsuite/version.rb +1 -1
  55. data/lib/netsuite.rb +10 -0
  56. data/netsuite.gemspec +5 -3
  57. data/spec/netsuite/actions/search_spec.rb +22 -0
  58. data/spec/netsuite/configuration_spec.rb +93 -6
  59. data/spec/netsuite/records/basic_record_spec.rb +8 -1
  60. data/spec/netsuite/records/classification_spec.rb +10 -1
  61. data/spec/netsuite/records/cost_category_spec.rb +105 -0
  62. data/spec/netsuite/records/custom_field_list_spec.rb +46 -6
  63. data/spec/netsuite/records/custom_record_spec.rb +1 -1
  64. data/spec/netsuite/records/customer_credit_cards_list_spec.rb +23 -0
  65. data/spec/netsuite/records/customer_payment_credit_list_spec.rb +26 -0
  66. data/spec/netsuite/records/customer_payment_spec.rb +1 -6
  67. data/spec/netsuite/records/customer_spec.rb +22 -1
  68. data/spec/netsuite/records/employee_spec.rb +2 -2
  69. data/spec/netsuite/records/estimate_item_list_spec.rb +26 -0
  70. data/spec/netsuite/records/estimate_item_spec.rb +40 -0
  71. data/spec/netsuite/records/estimate_spec.rb +216 -0
  72. data/spec/netsuite/records/inventory_item_spec.rb +65 -0
  73. data/spec/netsuite/records/invoice_spec.rb +94 -0
  74. data/spec/netsuite/records/non_inventory_resale_item_spec.rb +165 -0
  75. data/spec/netsuite/records/partner_spec.rb +143 -0
  76. data/spec/netsuite/records/service_resale_item_spec.rb +134 -0
  77. data/spec/netsuite/records/vendor_spec.rb +1 -1
  78. data/spec/netsuite/support/fields_spec.rb +36 -1
  79. data/spec/support/fixtures/custom_fields/multi_select.xml +47 -0
  80. data/spec/support/fixtures/search/saved_search_item.xml +55 -0
  81. data/spec/support/fixtures/search/saved_search_joined_custom_customer.xml +15 -1
  82. data/spec/support/search_only_field_matcher.rb +7 -0
  83. metadata +68 -12
  84. data/circle.yml +0 -17
@@ -41,6 +41,99 @@ describe NetSuite::Records::Invoice do
41
41
  end
42
42
  end
43
43
 
44
+ it 'has all the right search_only_fields' do
45
+ [
46
+ :abbrev, :account_type, :acct_corp_card_exp, :actual_production_end_date,
47
+ :actual_production_start_date, :actual_ship_date, :alt_sales_amount,
48
+ :alt_sales_net_amount, :amount, :amount_unbilled,
49
+ :applied_to_foreign_amount, :applied_to_is_fx_variance,
50
+ :applied_to_link_amount, :applied_to_link_type, :applied_to_transaction,
51
+ :applying_foreign_amount, :applying_is_fx_variance, :applying_link_amount,
52
+ :applying_link_type, :applying_transaction, :auth_code,
53
+ :auto_calculate_lag, :avs_street_match, :avs_zip_match, :billable,
54
+ :bill_address, :bill_address1, :bill_address2, :bill_address3,
55
+ :bill_addressee, :bill_attention, :bill_city, :bill_country,
56
+ :bill_country_code, :billed_date, :billing_amount, :billing_transaction,
57
+ :bill_phone, :bill_state, :bill_variance_status, :bill_zip, :bin_number,
58
+ :bin_number_quantity, :bom_quantity, :build_entire_assembly,
59
+ :build_variance, :built, :can_have_stackable_promotions, :catch_up_period,
60
+ :cc_customer_code, :cc_exp_date, :cc_holder_name, :cc_number, :cc_street,
61
+ :cc_zip_code, :cleared, :closed, :close_date, :cogs_amount,
62
+ :commission_effective_date, :commit, :component_yield,
63
+ :confirmation_number, :contribution, :contribution_primary,
64
+ :cost_component_amount, :cost_component_category, :cost_component_item,
65
+ :cost_component_quantity, :cost_component_standard_cost, :cost_estimate,
66
+ :cost_estimate_rate, :cost_estimate_type, :created_by, :credit_amount,
67
+ :csc_match, :custom_gl, :cust_type, :date_created, :days_open,
68
+ :days_overdue, :debit_amount, :defer_rev_rec, :deposit_date,
69
+ :deposit_transaction, :doc_unit, :dr_account, :effective_rate,
70
+ :entity_status, :est_gross_profit_pct, :exclude_from_rate_request,
71
+ :expected_close_date, :expected_receipt_date, :expense_category,
72
+ :expense_date, :firmed, :forecast_type, :fulfilling_transaction,
73
+ :fx_account, :fx_amount, :fx_cost_estimate, :fx_cost_estimate_rate,
74
+ :fx_est_gross_profit, :fx_tran_cost_estimate, :fx_vsoe_allocation,
75
+ :fx_vsoe_amount, :fx_vsoe_price, :gco_availabel_to_charge,
76
+ :gco_available_to_refund, :gco_avs_street_match, :gco_avs_zip_match,
77
+ :gco_buyer_account_age, :gco_buyer_ip, :gco_charge_amount,
78
+ :gco_chargeback_amount, :gco_confirmed_charged_total,
79
+ :gco_confirmed_refunded_total, :gco_creditcard_number, :gco_csc_match,
80
+ :gco_financial_state, :gco_fulfillment_state, :gco_order_id,
81
+ :gco_order_total, :gco_promotion_amount, :gco_promotion_name,
82
+ :gco_refund_amount, :gco_shipping_total, :gco_state_changed_detail,
83
+ :gift_cert, :gross_amount, :include_in_forecast, :incoterm,
84
+ :interco_status, :interco_transaction, :inventory_location,
85
+ :inventory_subsidiary, :in_vsoe_bundle, :is_allocation, :is_backflush,
86
+ :is_gco_chargeback, :is_gco_charge_confirmed, :is_gco_payment_guaranteed,
87
+ :is_gco_refund_confirmed, :is_inside_delivery, :is_inside_pickup,
88
+ :is_intercompany_adjustment, :is_in_transit_payment, :is_multi_ship_to,
89
+ :is_reversal, :is_rev_rec_transaction, :is_scrap, :is_ship_address,
90
+ :is_transfer_price_costing, :is_wip, :item, :item_fulfillment_choice,
91
+ :item_revision, :landed_cost_per_line, :line, :line_sequence_number,
92
+ :line_unique_key, :location_auto_assigned, :main_line, :main_name,
93
+ :manufacturing_routing, :match_bill_to_receipt, :memo_main, :memorized,
94
+ :merchant_account, :multi_subsidiary, :net_amount, :net_amount_no_tax,
95
+ :next_bill_date, :no_auto_assign_location, :non_reimbursable,
96
+ :one_time_total, :options, :order_allocation_strategy, :order_priority,
97
+ :originator, :overhead_parent_item,
98
+ :override_installments, :package_count, :paid_amount, :paid_transaction,
99
+ :partner_contribution, :partner_role, :partner_team_member,
100
+ :paying_amount, :paying_transaction, :payment_approved,
101
+ :payment_event_date, :payment_event_hold_reason,
102
+ :payment_event_purchase_card_used, :payment_event_purchase_data_sent,
103
+ :payment_event_result, :payment_event_type, :payment_hold,
104
+ :payment_method, :payment_option, :pay_pal_pending, :pay_pal_status,
105
+ :pay_pal_tran_id, :payroll_batch, :pn_ref_num, :po_rate, :posting,
106
+ :price_level, :print, :probability, :projected_amount, :project_task,
107
+ :purchase_order, :quantity, :quantity_billed, :quantity_committed,
108
+ :quantity_packed, :quantity_picked, :quantity_rev_committed,
109
+ :quantity_ship_recv, :quantity_uom, :rate,
110
+ :realized_gain_posting_transaction, :recur_annually_total,
111
+ :recur_monthly_total, :recur_quarterly_total, :recur_weekly_total,
112
+ :ref_number, :requested_date, :rev_commit_status,
113
+ :rev_committing_transaction, :reversal_date, :reversal_number,
114
+ :rg_account, :rg_amount, :sales_order, :sales_team_member,
115
+ :sales_team_role, :scheduling_method, :serial_number, :serial_number_cost,
116
+ :serial_number_cost_adjustment, :serial_number_quantity, :serial_numbers,
117
+ :ship_address, :ship_address1, :ship_address2, :ship_address3,
118
+ :ship_addressee, :ship_attention, :ship_carrier, :ship_city,
119
+ :ship_complete, :ship_country, :ship_country_code, :ship_group,
120
+ :ship_phone, :shipping_amount, :ship_recv_status_line, :ship_state,
121
+ :ship_to, :ship_zip, :signed_amount, :subscription, :subscription_line,
122
+ :tax_amount, :tax_code, :tax_line, :tax_period, :term_in_months,
123
+ :terms_of_sale, :title, :to_subsidiary, :tran_est_gross_profit,
124
+ :tran_fx_est_gross_profit, :transaction_discount, :transaction_line_type,
125
+ :transaction_number, :transfer_location, :transfer_order_item_line,
126
+ :transfer_order_quantity_committed, :transfer_order_quantity_packed,
127
+ :transfer_order_quantity_picked, :transfer_order_quantity_received,
128
+ :transfer_order_quantity_shipped, :type, :unit, :unit_cost_override,
129
+ :vend_type, :visible_to_customer, :vsoe_allocation, :vsoe_amount,
130
+ :vsoe_deferral, :vsoe_delivered, :vsoe_permit_discount, :vsoe_price,
131
+ :web_site,
132
+ ].each do |field|
133
+ expect(NetSuite::Records::Invoice).to have_search_only_field(field)
134
+ end
135
+ end
136
+
44
137
  it 'has the right record_refs' do
45
138
  [
46
139
  :account, :bill_address_list, :job, :custom_form, :department, :entity, :klass, :posting_period, :ship_address_list, :terms,
@@ -329,6 +422,7 @@ describe NetSuite::Records::Invoice do
329
422
  before do
330
423
  invoice.email = 'something@example.com'
331
424
  invoice.tran_id = '4'
425
+ invoice.close_date = '2021-08-04' # Search only, excluded
332
426
  end
333
427
  it 'can represent itself as a SOAP record' do
334
428
  record = {
@@ -0,0 +1,165 @@
1
+ require 'spec_helper'
2
+
3
+ describe NetSuite::Records::NonInventoryResaleItem do
4
+ let(:item) { NetSuite::Records::NonInventoryResaleItem.new }
5
+
6
+ it 'has the right fields' do
7
+ [
8
+ :available_to_partners, :cost_estimate, :cost_estimate_type, :cost_estimate_units, :country_of_manufacture, :created_date,
9
+ :display_name, :dont_show_price, :enforce_min_qty_internally, :exclude_from_sitemap,
10
+ :featured_description, :handling_cost, :handling_cost_units, :include_children, :is_donation_item, :is_fulfillable,
11
+ :is_gco_compliant, :is_inactive, :is_online, :is_taxable, :item_id, :last_modified_date, :manufacturer, :manufacturer_addr1,
12
+ :manufacturer_city, :manufacturer_state, :manufacturer_tariff, :manufacturer_tax_id, :manufacturer_zip, :matrix_option_list,
13
+ :matrix_type, :max_donation_amount, :meta_tag_html, :minimum_quantity, :minimum_quantity_units, :mpn,
14
+ :mult_manufacture_addr, :nex_tag_category, :no_price_message, :offer_support, :on_special, :out_of_stock_behavior,
15
+ :out_of_stock_message, :overall_quantity_pricing_type, :page_title, :preference_criterion, :presentation_item_list,
16
+ :prices_include_tax, :producer, :product_feed_list, :rate, :related_items_description, :sales_description,
17
+ :schedule_b_code, :schedule_b_number, :schedule_b_quantity, :search_keywords, :ship_individually, :shipping_cost,
18
+ :shipping_cost_units, :shopping_dot_com_category, :shopzilla_category_id, :show_default_donation_amount,
19
+ :site_category_list, :sitemap_priority, :soft_descriptor, :specials_description, :stock_description, :store_description,
20
+ :store_detailed_description, :store_display_name, :translations_list, :upc_code, :url_component, :use_marginal_rates,
21
+ :vsoe_deferral, :vsoe_delivered, :vsoe_permit_discount, :vsoe_price, :weight, :weight_unit, :weight_units
22
+ ].each do |field|
23
+ expect(item).to have_field(field)
24
+ end
25
+
26
+ # TODO there is a probably a more robust way to test this
27
+ expect(item.custom_field_list.class).to eq(NetSuite::Records::CustomFieldList)
28
+ expect(item.pricing_matrix.class).to eq(NetSuite::Records::PricingMatrix)
29
+ expect(item.subsidiary_list.class).to eq(NetSuite::Records::RecordRefList)
30
+ expect(item.item_vendor_list.class).to eq(NetSuite::Records::ItemVendorList)
31
+
32
+ end
33
+
34
+ it 'has the right record_refs' do
35
+ [
36
+ :billing_schedule, :cost_category, :custom_form, :deferred_revenue_account, :department, :income_account,
37
+ :issue_product, :item_options_list, :klass, :location, :parent, :pricing_group, :purchase_tax_code,
38
+ :quantity_pricing_schedule, :rev_rec_schedule, :sale_unit, :sales_tax_code, :ship_package, :store_display_image,
39
+ :store_display_thumbnail, :store_item_template, :tax_schedule, :units_type, :expense_account
40
+ ].each do |record_ref|
41
+ expect(item).to have_record_ref(record_ref)
42
+ end
43
+ end
44
+
45
+ describe '.get' do
46
+ context 'when the response is successful' do
47
+ let(:response) { NetSuite::Response.new(:success => true, :body => { :manufacturer_zip => '90401' }) }
48
+
49
+ it 'returns a NonInventoryResaleItem instance populated with the data from the response object' do
50
+ expect(NetSuite::Actions::Get).to receive(:call).with([NetSuite::Records::NonInventoryResaleItem, {:external_id => 20}], {}).and_return(response)
51
+ customer = NetSuite::Records::NonInventoryResaleItem.get(:external_id => 20)
52
+ expect(customer).to be_kind_of(NetSuite::Records::NonInventoryResaleItem)
53
+ expect(customer.manufacturer_zip).to eql('90401')
54
+ end
55
+ end
56
+
57
+ context 'when the response is unsuccessful' do
58
+ let(:response) { NetSuite::Response.new(:success => false, :body => {}) }
59
+
60
+ it 'raises a RecordNotFound exception' do
61
+ expect(NetSuite::Actions::Get).to receive(:call).with([NetSuite::Records::NonInventoryResaleItem, {:external_id => 20}], {}).and_return(response)
62
+ expect {
63
+ NetSuite::Records::NonInventoryResaleItem.get(:external_id => 20)
64
+ }.to raise_error(NetSuite::RecordNotFound,
65
+ /NetSuite::Records::NonInventoryResaleItem with OPTIONS=(.*) could not be found/)
66
+ end
67
+ end
68
+ end
69
+
70
+ describe '#add' do
71
+ context 'when the response is successful' do
72
+ let(:response) { NetSuite::Response.new(:success => true, :body => { :internal_id => '1' }) }
73
+
74
+ it 'returns true' do
75
+ expect(NetSuite::Actions::Add).to receive(:call).
76
+ with([item], {}).
77
+ and_return(response)
78
+ expect(item.add).to be_truthy
79
+ end
80
+ end
81
+
82
+ context 'when the response is unsuccessful' do
83
+ let(:response) { NetSuite::Response.new(:success => false, :body => {}) }
84
+
85
+ it 'returns false' do
86
+ expect(NetSuite::Actions::Add).to receive(:call).
87
+ with([item], {}).
88
+ and_return(response)
89
+ expect(item.add).to be_falsey
90
+ end
91
+ end
92
+ end
93
+
94
+ describe '#update' do
95
+ context 'when the response is successful' do
96
+ let(:response) { NetSuite::Response.new(:success => true, :body => { :internal_id => '1' }) }
97
+
98
+ it 'returns true' do
99
+ expect(NetSuite::Actions::Update).to receive(:call).
100
+ with([item.class, {external_id: 'foo'}], {}).
101
+ and_return(response)
102
+ item.external_id = 'foo'
103
+ expect(item.update).to be_truthy
104
+ end
105
+ end
106
+
107
+ context 'when the response is unsuccessful' do
108
+ let(:response) { NetSuite::Response.new(:success => false, :body => {}) }
109
+
110
+ it 'returns false' do
111
+ expect(NetSuite::Actions::Update).to receive(:call).
112
+ with([item.class, {external_id: 'foo'}], {}).
113
+ and_return(response)
114
+ item.external_id = 'foo'
115
+ expect(item.update).to be_falsey
116
+ end
117
+ end
118
+ end
119
+
120
+ describe '#delete' do
121
+ context 'when the response is successful' do
122
+ let(:response) { NetSuite::Response.new(:success => true, :body => { :internal_id => '1' }) }
123
+
124
+ it 'returns true' do
125
+ expect(NetSuite::Actions::Delete).to receive(:call).
126
+ with([item], {}).
127
+ and_return(response)
128
+ expect(item.delete).to be_truthy
129
+ end
130
+ end
131
+
132
+ context 'when the response is unsuccessful' do
133
+ let(:response) { NetSuite::Response.new(:success => false, :body => {}) }
134
+
135
+ it 'returns false' do
136
+ expect(NetSuite::Actions::Delete).to receive(:call).
137
+ with([item], {}).
138
+ and_return(response)
139
+ expect(item.delete).to be_falsey
140
+ end
141
+ end
142
+ end
143
+
144
+ describe '#to_record' do
145
+ before do
146
+ item.handling_cost = 100.0
147
+ item.is_online = true
148
+ end
149
+
150
+ it 'can represent itself as a SOAP record' do
151
+ record = {
152
+ 'listAcct:handlingCost' => 100.0,
153
+ 'listAcct:isOnline' => true
154
+ }
155
+ expect(item.to_record).to eql(record)
156
+ end
157
+ end
158
+
159
+ describe '#record_type' do
160
+ it 'returns a string of the SOAP type' do
161
+ expect(item.record_type).to eql('listAcct:NonInventoryResaleItem')
162
+ end
163
+ end
164
+
165
+ end
@@ -0,0 +1,143 @@
1
+ require 'spec_helper'
2
+
3
+ describe NetSuite::Records::Partner do
4
+ let(:partner) { NetSuite::Records::Partner.new }
5
+
6
+ it 'has all the right fields' do
7
+ [
8
+ :alt_email, :alt_name, :bcn, :comments, :company_name, :date_created, :default_address,
9
+ :eligible_for_commission, :email, :entity_id, :fax, :first_name, :give_access, :home_phone, :is_inactive,
10
+ :is_person, :last_modified_date, :last_name, :login_as, :middle_name, :mobile_phone, :partner_code,
11
+ :password, :password2, :phone, :phonetic_name, :print_on_check_as, :referring_url, :require_pwd_change,
12
+ :salutation, :send_email, :sub_partner_login, :tax_id_num, :title, :url, :vat_reg_number
13
+ ].each do |field|
14
+ expect(partner).to have_field(field)
15
+ end
16
+ end
17
+
18
+ it 'has all the right record refs' do
19
+ [
20
+ :access_role, :klass, :custom_form, :default_tax_reg, :department, :image, :location, :parent, :subsidiary
21
+ ].each do |record_ref|
22
+ expect(partner).to have_record_ref(record_ref)
23
+ end
24
+ end
25
+
26
+ describe '.get' do
27
+ context 'when the response is successful' do
28
+ let(:response) { NetSuite::Response.new(:success => true, :body => { :account_number => 7 }) }
29
+
30
+ it 'returns an Partner instance populated with the data from the response object' do
31
+ expect(NetSuite::Actions::Get).to receive(:call).with([NetSuite::Records::Partner, { :external_id => 1 }], {}).and_return(response)
32
+ Partner = NetSuite::Records::Partner.get(:external_id => 1)
33
+ expect(Partner).to be_kind_of(NetSuite::Records::Partner)
34
+ end
35
+ end
36
+
37
+ context 'when the response is unsuccessful' do
38
+ let(:response) { NetSuite::Response.new(:success => false, :body => {}) }
39
+
40
+ it 'raises a RecordNotFound exception' do
41
+ expect(NetSuite::Actions::Get).to receive(:call).with([NetSuite::Records::Partner, { :external_id => 1 }], {}).and_return(response)
42
+ expect {
43
+ NetSuite::Records::Partner.get(:external_id => 1)
44
+ }.to raise_error(NetSuite::RecordNotFound,
45
+ /NetSuite::Records::Partner with OPTIONS=(.*) could not be found/)
46
+ end
47
+ end
48
+ end
49
+
50
+ describe '#add' do
51
+ let(:partner) { NetSuite::Records::Partner.new(:email => 'dale.cooper@example.com') }
52
+
53
+ context 'when the response is successful' do
54
+ let(:response) { NetSuite::Response.new(:success => true, :body => { :internal_id => '1' }) }
55
+
56
+ it 'returns true' do
57
+ expect(NetSuite::Actions::Add).to receive(:call).
58
+ with([partner], {}).
59
+ and_return(response)
60
+ expect(partner.add).to be_truthy
61
+ end
62
+ end
63
+
64
+ context 'when the response is unsuccessful' do
65
+ let(:response) { NetSuite::Response.new(:success => false, :body => {}) }
66
+
67
+ it 'returns false' do
68
+ expect(NetSuite::Actions::Add).to receive(:call).
69
+ with([partner], {}).
70
+ and_return(response)
71
+ expect(partner.add).to be_falsey
72
+ end
73
+ end
74
+ end
75
+
76
+ describe '#delete' do
77
+ context 'when the response is successful' do
78
+ let(:response) { NetSuite::Response.new(:success => true, :body => { :internal_id => '1' }) }
79
+
80
+ it 'returns true' do
81
+ expect(NetSuite::Actions::Delete).to receive(:call).
82
+ with([partner], {}).
83
+ and_return(response)
84
+ expect(partner.delete).to be_truthy
85
+ end
86
+ end
87
+
88
+ context 'when the response is unsuccessful' do
89
+ let(:response) { NetSuite::Response.new(:success => false, :body => {}) }
90
+
91
+ it 'returns false' do
92
+ expect(NetSuite::Actions::Delete).to receive(:call).
93
+ with([partner], {}).
94
+ and_return(response)
95
+ expect(partner.delete).to be_falsey
96
+ end
97
+ end
98
+ end
99
+
100
+ describe '.update' do
101
+ context 'when the response is successful' do
102
+ let(:response) { NetSuite::Response.new(:success => true, :body => { :email => 'leland.palmer@example.com' }) }
103
+
104
+ it 'returns true' do
105
+ expect(NetSuite::Actions::Update).to receive(:call).with([NetSuite::Records::Partner, { :internal_id => 1, :email => 'leland.palmer@example.com' }], {}).and_return(response)
106
+ partner = NetSuite::Records::Partner.new(:internal_id => 1)
107
+ expect(partner.update(:email => 'leland.palmer@example.com')).to be_truthy
108
+ end
109
+ end
110
+
111
+ context 'when the response is unsuccessful' do
112
+ let(:response) { NetSuite::Response.new(:success => false, :body => {}) }
113
+
114
+ it 'raises a RecordNotFound exception' do
115
+ expect(NetSuite::Actions::Update).to receive(:call).with([NetSuite::Records::Partner, { :internal_id => 1, :account_number => 7 }], {}).and_return(response)
116
+ partner = NetSuite::Records::Partner.new(:internal_id => 1)
117
+ expect(partner.update(:account_number => 7)).to be_falsey
118
+ end
119
+ end
120
+ end
121
+
122
+ describe '#to_record' do
123
+ let(:partner) { NetSuite::Records::Partner.new(:email => 'bob@example.com') }
124
+
125
+ it 'returns a hash of attributes that can be used in a SOAP request' do
126
+ expect(partner.to_record).to eql({ 'listRel:email' => 'bob@example.com' })
127
+ end
128
+ end
129
+
130
+ describe '#record_type' do
131
+ it 'returns a string type for the record to be used in a SOAP request' do
132
+ expect(partner.record_type).to eql('listRel:Partner')
133
+ end
134
+ end
135
+
136
+ it 'has the right record_refs' do
137
+ [
138
+ :klass, :access_role, :department, :subsidiary
139
+ ].each do |record_ref|
140
+ expect(partner).to have_record_ref(record_ref)
141
+ end
142
+ end
143
+ end
@@ -0,0 +1,134 @@
1
+ require 'spec_helper'
2
+
3
+ describe NetSuite::Records::ServiceResaleItem do
4
+ let(:item) { NetSuite::Records::ServiceResaleItem.new }
5
+
6
+ it 'has the right fields' do
7
+ [
8
+ :available_to_partners, :cost, :cost_estimate, :cost_estimate_type, :cost_estimate_units, :create_job, :created_date,
9
+ :display_name, :dont_show_price, :enforce_min_qty_internally, :exclude_from_sitemap, :featured_description,
10
+ :include_children, :is_donation_item, :is_fulfillable, :is_gco_compliant, :is_inactive, :is_online, :is_taxable,
11
+ :item_id, :last_modified_date, :matrix_option_list, :matrix_type, :max_donation_amount, :meta_tag_html,
12
+ :minimum_quantity, :minimum_quantity_units, :no_price_message, :offer_support, :on_special, :out_of_stock_behavior,
13
+ :out_of_stock_message, :overall_quantity_pricing_type, :page_title, :presentation_item_list, :prices_include_tax,
14
+ :show_default_donation_amount, :site_category_list, :sitemap_priority, :soft_descriptor, :specials_description,
15
+ :store_description, :store_detailed_description, :store_display_name, :translations_list, :upc_code, :url_component,
16
+ :use_marginal_rates, :vsoe_deferral, :vsoe_delivered, :vsoe_permit_discount, :vsoe_price, :vsoe_sop_group
17
+ ].each do |field|
18
+ expect(item).to have_field(field)
19
+ end
20
+
21
+ # TODO there is a probably a more robust way to test this
22
+ expect(item.custom_field_list.class).to eq(NetSuite::Records::CustomFieldList)
23
+ expect(item.pricing_matrix.class).to eq(NetSuite::Records::PricingMatrix)
24
+ expect(item.subsidiary_list.class).to eq(NetSuite::Records::RecordRefList)
25
+ end
26
+
27
+ it 'has the right record_refs' do
28
+ [
29
+ :billing_schedule, :cost_category, :custom_form, :deferred_revenue_account, :department, :income_account,
30
+ :issue_product, :item_options_list, :klass, :location, :parent, :pricing_group, :purchase_tax_code,
31
+ :quantity_pricing_schedule, :rev_rec_schedule, :sale_unit, :sales_tax_code, :store_display_image,
32
+ :store_display_thumbnail, :store_item_template, :tax_schedule, :units_type
33
+ ].each do |record_ref|
34
+ expect(item).to have_record_ref(record_ref)
35
+ end
36
+ end
37
+
38
+ describe '.get' do
39
+ context 'when the response is successful' do
40
+ let(:response) { NetSuite::Response.new(:success => true, :body => { :item_id => 'penguins' }) }
41
+
42
+ it 'returns a ServiceResaleItem instance populated with the data from the response object' do
43
+ expect(NetSuite::Actions::Get).to receive(:call).with([NetSuite::Records::ServiceResaleItem, :external_id => 20], {}).and_return(response)
44
+ customer = NetSuite::Records::ServiceResaleItem.get(:external_id => 20)
45
+ expect(customer).to be_kind_of(NetSuite::Records::ServiceResaleItem)
46
+ expect(customer.item_id).to eql('penguins')
47
+ end
48
+ end
49
+
50
+ context 'when the response is unsuccessful' do
51
+ let(:response) { NetSuite::Response.new(:success => false, :body => {}) }
52
+
53
+ it 'raises a RecordNotFound exception' do
54
+ expect(NetSuite::Actions::Get).to receive(:call).with([NetSuite::Records::ServiceResaleItem, :external_id => 20], {}).and_return(response)
55
+ expect {
56
+ NetSuite::Records::ServiceResaleItem.get(:external_id => 20)
57
+ }.to raise_error(NetSuite::RecordNotFound,
58
+ /NetSuite::Records::ServiceResaleItem with OPTIONS=(.*) could not be found/)
59
+ end
60
+ end
61
+ end
62
+
63
+ describe '#add' do
64
+ let(:item) { NetSuite::Records::ServiceResaleItem.new(:cost => 100, :is_inactive => false) }
65
+
66
+ context 'when the response is successful' do
67
+ let(:response) { NetSuite::Response.new(:success => true, :body => { :internal_id => '1' }) }
68
+
69
+ it 'returns true' do
70
+ expect(NetSuite::Actions::Add).to receive(:call).
71
+ with([item], {}).
72
+ and_return(response)
73
+ expect(item.add).to be_truthy
74
+ end
75
+ end
76
+
77
+ context 'when the response is unsuccessful' do
78
+ let(:response) { NetSuite::Response.new(:success => false, :body => {}) }
79
+
80
+ it 'returns false' do
81
+ expect(NetSuite::Actions::Add).to receive(:call).
82
+ with([item], {}).
83
+ and_return(response)
84
+ expect(item.add).to be_falsey
85
+ end
86
+ end
87
+ end
88
+
89
+ describe '#delete' do
90
+ context 'when the response is successful' do
91
+ let(:response) { NetSuite::Response.new(:success => true, :body => { :internal_id => '1' }) }
92
+
93
+ it 'returns true' do
94
+ expect(NetSuite::Actions::Delete).to receive(:call).
95
+ with([item], {}).
96
+ and_return(response)
97
+ expect(item.delete).to be_truthy
98
+ end
99
+ end
100
+
101
+ context 'when the response is unsuccessful' do
102
+ let(:response) { NetSuite::Response.new(:success => false, :body => {}) }
103
+
104
+ it 'returns false' do
105
+ expect(NetSuite::Actions::Delete).to receive(:call).
106
+ with([item], {}).
107
+ and_return(response)
108
+ expect(item.delete).to be_falsey
109
+ end
110
+ end
111
+ end
112
+
113
+ describe '#to_record' do
114
+ before do
115
+ item.item_id = 'penguins'
116
+ item.is_online = true
117
+ end
118
+
119
+ it 'can represent itself as a SOAP record' do
120
+ record = {
121
+ 'listAcct:itemId' => 'penguins',
122
+ 'listAcct:isOnline' => true
123
+ }
124
+ expect(item.to_record).to eql(record)
125
+ end
126
+ end
127
+
128
+ describe '#record_type' do
129
+ it 'returns a string of the SOAP type' do
130
+ expect(item.record_type).to eql('listAcct:ServiceResaleItem')
131
+ end
132
+ end
133
+
134
+ end