netsuite 0.8.5 → 0.8.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (39) hide show
  1. checksums.yaml +5 -5
  2. data/.ruby-version +1 -1
  3. data/Gemfile +3 -2
  4. data/README.md +8 -2
  5. data/circle.yml +33 -14
  6. data/lib/netsuite.rb +5 -0
  7. data/lib/netsuite/configuration.rb +8 -4
  8. data/lib/netsuite/records/classification.rb +4 -1
  9. data/lib/netsuite/records/custom_record.rb +1 -1
  10. data/lib/netsuite/records/customer.rb +2 -1
  11. data/lib/netsuite/records/customer_credit_cards.rb +36 -0
  12. data/lib/netsuite/records/customer_credit_cards_list.rb +10 -0
  13. data/lib/netsuite/records/customer_payment.rb +1 -0
  14. data/lib/netsuite/records/employee.rb +1 -1
  15. data/lib/netsuite/records/estimate.rb +42 -0
  16. data/lib/netsuite/records/estimate_item.rb +40 -0
  17. data/lib/netsuite/records/estimate_item_list.rb +11 -0
  18. data/lib/netsuite/records/invoice.rb +1 -1
  19. data/lib/netsuite/records/item_fulfillment.rb +1 -1
  20. data/lib/netsuite/records/non_inventory_resale_item.rb +1 -0
  21. data/lib/netsuite/records/partner.rb +1 -1
  22. data/lib/netsuite/records/service_resale_item.rb +1 -1
  23. data/lib/netsuite/utilities.rb +1 -1
  24. data/lib/netsuite/version.rb +1 -1
  25. data/netsuite.gemspec +3 -2
  26. data/spec/netsuite/configuration_spec.rb +61 -6
  27. data/spec/netsuite/records/classification_spec.rb +10 -1
  28. data/spec/netsuite/records/custom_field_list_spec.rb +6 -4
  29. data/spec/netsuite/records/custom_record_spec.rb +1 -1
  30. data/spec/netsuite/records/customer_credit_cards_list_spec.rb +23 -0
  31. data/spec/netsuite/records/customer_spec.rb +22 -1
  32. data/spec/netsuite/records/employee_spec.rb +2 -2
  33. data/spec/netsuite/records/estimate_item_list_spec.rb +26 -0
  34. data/spec/netsuite/records/estimate_item_spec.rb +40 -0
  35. data/spec/netsuite/records/estimate_spec.rb +216 -0
  36. data/spec/netsuite/records/non_inventory_resale_item_spec.rb +165 -0
  37. data/spec/netsuite/records/partner_spec.rb +141 -0
  38. data/spec/netsuite/records/service_resale_item_spec.rb +134 -0
  39. metadata +31 -6
@@ -326,15 +326,11 @@ describe NetSuite::Configuration do
326
326
 
327
327
  describe "#credentials" do
328
328
  context "when none are defined" do
329
- skip "should properly create the auth credentials" do
330
-
331
- end
329
+ skip "should properly create the auth credentials"
332
330
  end
333
331
 
334
332
  context "when they are defined" do
335
- it "should properly replace the default auth credentials" do
336
-
337
- end
333
+ skip "should properly replace the default auth credentials"
338
334
  end
339
335
  end
340
336
 
@@ -371,6 +367,65 @@ describe NetSuite::Configuration do
371
367
  end
372
368
  end
373
369
 
370
+ describe "#log" do
371
+ it 'allows a file path to be set as the log destination' do
372
+ file_path = Tempfile.new.path
373
+ config.log = file_path
374
+ config.logger.info "foo"
375
+
376
+ log_contents = open(file_path).read
377
+ expect(log_contents).to include("foo")
378
+ end
379
+
380
+ it 'allows an IO device to bet set as the log destination' do
381
+ stream = StringIO.new
382
+ config.log = stream
383
+ config.logger.info "foo"
384
+
385
+ expect(stream.string).to include("foo")
386
+ end
387
+ end
388
+
389
+ describe '#log_level' do
390
+ it 'defaults to :debug' do
391
+ expect(config.log_level).to eq(:debug)
392
+ end
393
+
394
+ it 'can be initially set to any log level' do
395
+ config.log_level(:info)
396
+
397
+ expect(config.log_level).to eq(:info)
398
+ end
399
+
400
+ it 'can override itself' do
401
+ config.log_level = :info
402
+
403
+ expect(config.log_level).to eq(:info)
404
+
405
+ config.log_level(:debug)
406
+
407
+ expect(config.log_level).to eq(:debug)
408
+ end
409
+ end
410
+
411
+ describe '#log_level=' do
412
+ it 'can set the initial log_level' do
413
+ config.log_level = :info
414
+
415
+ expect(config.log_level).to eq(:info)
416
+ end
417
+
418
+ it 'can override a previously set log level' do
419
+ config.log_level = :info
420
+
421
+ expect(config.log_level).to eq(:info)
422
+
423
+ config.log_level = :debug
424
+
425
+ expect(config.log_level).to eq(:debug)
426
+ end
427
+ end
428
+
374
429
  describe 'timeouts' do
375
430
  it 'has defaults' do
376
431
  expect(config.read_timeout).to eql(60)
@@ -5,12 +5,21 @@ describe NetSuite::Records::Classification do
5
5
 
6
6
  it 'has all the right fields' do
7
7
  [
8
- :name, :include_children, :is_inactive, :class_translation_list, :custom_field_list
8
+ :name, :include_children, :is_inactive, :class_translation_list
9
9
  ].each do |field|
10
10
  expect(classification).to have_field(field)
11
11
  end
12
12
 
13
13
  expect(classification.subsidiary_list.class).to eq(NetSuite::Records::RecordRefList)
14
+ expect(classification.custom_field_list.class).to eq(NetSuite::Records::CustomFieldList)
15
+ end
16
+
17
+ it 'has all the right record refs' do
18
+ [
19
+ :parent
20
+ ].each do |record_ref|
21
+ expect(classification).to have_record_ref(record_ref)
22
+ end
14
23
  end
15
24
 
16
25
  describe '.get' do
@@ -37,9 +37,11 @@ describe NetSuite::Records::CustomFieldList do
37
37
  context 'writing convience methods' do
38
38
  it "should create a custom field entry when none exists" do
39
39
  list.custrecord_somefield = 'a value'
40
- list.custom_fields.size.should == 1
41
- list.custom_fields.first.value.should == 'a value'
42
- list.custom_fields.first.type.should == 'platformCore:StringCustomFieldRef'
40
+ custom_fields = list.custom_fields
41
+
42
+ expect(custom_fields.size).to eq(1)
43
+ expect(custom_fields.first.value).to eq('a value')
44
+ expect(custom_fields.first.type).to eq('platformCore:StringCustomFieldRef')
43
45
  end
44
46
 
45
47
  # https://github.com/NetSweet/netsuite/issues/325
@@ -116,7 +118,7 @@ describe NetSuite::Records::CustomFieldList do
116
118
  end
117
119
 
118
120
  it "should raise an error if custom field entry does not exist" do
119
- expect{ list.nonexisting_custom_field }.to raise_error
121
+ expect{ list.nonexisting_custom_field }.to raise_error(NoMethodError)
120
122
  end
121
123
  end
122
124
  end
@@ -18,7 +18,7 @@ describe NetSuite::Records::CustomRecord do
18
18
 
19
19
  it 'has all the right record_refs' do
20
20
  [
21
- :custom_form, :owner
21
+ :custom_form, :owner, :rec_type, :parent
22
22
  ].each do |record_ref|
23
23
  expect(record).to have_record_ref(record_ref)
24
24
  end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe NetSuite::Records::CustomerCreditCardsList do
4
+ let(:list) { NetSuite::Records::CustomerCreditCardsList.new }
5
+
6
+ it 'has a credit_cards attribute' do
7
+ expect(list.credit_cards).to be_kind_of(Array)
8
+ end
9
+
10
+ describe '#to_record' do
11
+ it 'can represent itself as a SOAP record' do
12
+ list.replace_all = true
13
+
14
+ record = {
15
+ 'listRel:creditCards' => [],
16
+ 'listRel:replaceAll' => true
17
+ }
18
+
19
+ expect(list.to_record).to eql(record)
20
+ end
21
+ end
22
+
23
+ end
@@ -8,7 +8,7 @@ describe NetSuite::Records::Customer do
8
8
  :account_number, :aging, :alt_email, :alt_name, :alt_phone, :balance, :bill_pay,
9
9
  :buying_reason, :buying_time_frame, :campaign_category, :click_stream, :comments, :company_name,
10
10
  :consol_aging, :consol_balance, :consol_days_overdue, :consol_deposit_balance, :consol_overdue_balance,
11
- :consol_unbilled_orders, :contrib_pct, :credit_cards_list, :credit_hold_override, :credit_limit,
11
+ :consol_unbilled_orders, :contrib_pct, :credit_hold_override, :credit_limit,
12
12
  :date_created, :days_overdue, :default_address,
13
13
  :deposit_balance, :download_list, :email, :email_preference, :email_transactions, :end_date, :entity_id,
14
14
  :estimated_budget, :fax, :fax_transactions, :first_name, :first_visit, :give_access, :global_subscription_status,
@@ -65,6 +65,27 @@ describe NetSuite::Records::Customer do
65
65
  end
66
66
  end
67
67
 
68
+ describe '#credit_cards_list' do
69
+ it 'can be set from attributes' do
70
+ customer.credit_cards_list = {
71
+ :credit_cards => {
72
+ :internal_id => '1234567',
73
+ :cc_default => true,
74
+ :cc_expire_date => '2099-12-01T00:00:00.000-08:00'
75
+ }
76
+ }
77
+
78
+ expect(customer.credit_cards_list).to be_kind_of(NetSuite::Records::CustomerCreditCardsList)
79
+ expect(customer.credit_cards_list.credit_cards.length).to eql(1)
80
+ end
81
+
82
+ it 'can be set from a CustomerCreditCardsList object' do
83
+ customer_credit_cards_list = NetSuite::Records::CustomerCreditCardsList.new
84
+ customer.credit_cards_list = customer_credit_cards_list
85
+ expect(customer.credit_cards_list).to eql(customer_credit_cards_list)
86
+ end
87
+ end
88
+
68
89
  describe '#custom_field_list' do
69
90
  it 'can be set from attributes' do
70
91
  attributes = {
@@ -21,7 +21,7 @@ describe NetSuite::Records::Employee do
21
21
 
22
22
  it 'has all the right record refs' do
23
23
  [
24
- :location, :employee_status, :employee_type
24
+ :currency, :department, :location, :sales_role, :subsidiary, :employee_type, :employee_status, :supervisor
25
25
  ].each do |record_ref|
26
26
  expect(employee).to have_record_ref(record_ref)
27
27
  end
@@ -144,7 +144,7 @@ describe NetSuite::Records::Employee do
144
144
 
145
145
  it 'has the right record_refs' do
146
146
  [
147
- :currency, :department, :location, :subsidiary
147
+ :currency, :department, :location, :sales_role, :subsidiary, :employee_type, :employee_status, :supervisor
148
148
  ].each do |record_ref|
149
149
  expect(employee).to have_record_ref(record_ref)
150
150
  end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe NetSuite::Records::EstimateItemList do
4
+ let(:list) { NetSuite::Records::EstimateItemList.new }
5
+
6
+ it 'has a items attribute' do
7
+ expect(list.items).to be_kind_of(Array)
8
+ end
9
+
10
+ describe '#to_record' do
11
+ before do
12
+ list.items << NetSuite::Records::EstimateItem.new(
13
+ :rate => 10
14
+ )
15
+ end
16
+
17
+ it 'can represent itself as a SOAP record' do
18
+ record = {
19
+ 'tranSales:item' => [{
20
+ 'tranSales:rate' => 10
21
+ }]
22
+ }
23
+ expect(list.to_record).to eql(record)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe NetSuite::Records::EstimateItem do
4
+ let(:item) { NetSuite::Records::EstimateItem.new }
5
+
6
+ it 'has all the right fields' do
7
+ [
8
+ :amount, :cost_estimate, :cost_estimate_type,
9
+ :defer_rev_rec, :description,
10
+ :is_taxable, :line, :quantity,
11
+ :rate, :tax_rate1
12
+ ].each do |field|
13
+ expect(item).to have_field(field)
14
+ end
15
+ end
16
+
17
+ it 'has all the right record refs' do
18
+ [
19
+ :item, :job, :price, :tax_code, :units
20
+ ].each do |record_ref|
21
+ expect(item).to have_record_ref(record_ref)
22
+ end
23
+ end
24
+
25
+ describe '#options' do
26
+ it 'can be set from attributes'
27
+ it 'can be set from a CustomFieldList object'
28
+ end
29
+
30
+ describe '#inventory_detail' do
31
+ it 'can be set from attributes'
32
+ it 'can be set from an InventoryDetail object'
33
+ end
34
+
35
+ describe '#custom_field_list' do
36
+ it 'can be set from attributes'
37
+ it 'can be set from a CustomFieldList object'
38
+ end
39
+
40
+ end
@@ -0,0 +1,216 @@
1
+ require 'spec_helper'
2
+
3
+ describe NetSuite::Records::Estimate do
4
+ let(:estimate) { NetSuite::Records::Estimate.new }
5
+ let(:customer) { NetSuite::Records::Customer.new }
6
+ let(:response) { NetSuite::Response.new(:success => true, :body => { :internal_id => '1' }) }
7
+
8
+ it 'has all the right fields' do
9
+ [
10
+ :alt_handling_cost, :alt_shipping_cost,
11
+ :balance, :bill_address, :created_date, :currency_name,
12
+ :discount_rate, :email, :end_date, :est_gross_profit,
13
+ :exchange_rate,
14
+ :handling_cost, :handling_tax1_rate, :is_taxable,
15
+ :last_modified_date, :memo, :message, :other_ref_num,
16
+ :shipping_cost, :shipping_tax1_rate,
17
+ :source, :start_date, :status, :sync_partner_teams,
18
+ :sync_sales_teams, :to_be_emailed, :to_be_faxed, :to_be_printed,
19
+ :total_cost_estimate, :tran_date, :tran_id
20
+ ].each do |field|
21
+ expect(estimate).to have_field(field)
22
+ end
23
+ end
24
+
25
+ it 'has all the right record refs' do
26
+ [
27
+ :bill_address_list, :created_from, :currency, :custom_form, :department, :discount_item,
28
+ :entity, :handling_tax_code, :job, :klass, :lead_source, :location, :message_sel,
29
+ :opportunity, :partner, :promo_code, :sales_group, :sales_rep,
30
+ :ship_method, :shipping_tax_code, :subsidiary
31
+ ].each do |record_ref|
32
+ expect(estimate).to have_record_ref(record_ref)
33
+ end
34
+ end
35
+
36
+ describe '#order_status' do
37
+ it 'can be set from attributes'
38
+ it 'can be set from a EstimateStatus object'
39
+ end
40
+
41
+ describe '#item_list' do
42
+ it 'can be set from attributes' do
43
+ attributes = {
44
+ :item => {
45
+ :amount => 10
46
+ }
47
+ }
48
+ estimate.item_list = attributes
49
+ expect(estimate.item_list).to be_kind_of(NetSuite::Records::EstimateItemList)
50
+ expect(estimate.item_list.items.length).to eql(1)
51
+ end
52
+
53
+ it 'can be set from a EstimateItemList object' do
54
+ item_list = NetSuite::Records::EstimateItemList.new
55
+ estimate.item_list = item_list
56
+ expect(estimate.item_list).to eql(item_list)
57
+ end
58
+ end
59
+
60
+ describe '#transaction_bill_address' do
61
+ it 'can be set from attributes'
62
+ it 'can be set from a BillAddress object'
63
+ end
64
+
65
+ describe '#transaction_ship_address' do
66
+ it 'can be set from attributes'
67
+ it 'can be set from a ShipAddress object'
68
+ end
69
+
70
+ describe '#revenue_status' do
71
+ it 'can be set from attributes'
72
+ it 'can be set from a RevenueStatus object'
73
+ end
74
+
75
+ describe '#sales_team_list' do
76
+ it 'can be set from attributes'
77
+ it 'can be set from a EstimateSalesTeamList object'
78
+ end
79
+
80
+ describe '#partners_list' do
81
+ it 'can be set from attributes'
82
+ it 'can be set from a EstimatePartnersList object'
83
+ end
84
+
85
+ describe '#custom_field_list' do
86
+ it 'can be set from attributes'
87
+ it 'can be set from a CustomFieldList object'
88
+ end
89
+
90
+ describe '.get' do
91
+ context 'when the response is successful' do
92
+ let(:response) { NetSuite::Response.new(:success => true, :body => { :alt_shipping_cost => 100 }) }
93
+
94
+ it 'returns a Estimate instance populated with the data from the response object' do
95
+ expect(NetSuite::Actions::Get).to receive(:call).with([NetSuite::Records::Estimate, :external_id => 1], {}).and_return(response)
96
+ estimate = NetSuite::Records::Estimate.get(:external_id => 1)
97
+ expect(estimate).to be_kind_of(NetSuite::Records::Estimate)
98
+ expect(estimate.alt_shipping_cost).to eql(100)
99
+ end
100
+ end
101
+
102
+ context 'when the response is unsuccessful' do
103
+ let(:response) { NetSuite::Response.new(:success => false, :body => {}) }
104
+
105
+ it 'raises a RecordNotFound exception' do
106
+ expect(NetSuite::Actions::Get).to receive(:call).with([NetSuite::Records::Estimate, :external_id => 1], {}).and_return(response)
107
+ expect {
108
+ NetSuite::Records::Estimate.get(:external_id => 1)
109
+ }.to raise_error(NetSuite::RecordNotFound,
110
+ /NetSuite::Records::Estimate with OPTIONS=(.*) could not be found/)
111
+ end
112
+ end
113
+ end
114
+
115
+ describe '.initialize' do
116
+ context 'when the request is successful' do
117
+ it 'returns an initialized sales order from the customer entity' do
118
+ expect(NetSuite::Actions::Initialize).to receive(:call).with([NetSuite::Records::Estimate, customer], {}).and_return(response)
119
+ estimate = NetSuite::Records::Estimate.initialize(customer)
120
+ expect(estimate).to be_kind_of(NetSuite::Records::Estimate)
121
+ end
122
+ end
123
+
124
+ context 'when the response is unsuccessful' do
125
+ skip
126
+ end
127
+ end
128
+
129
+ describe '#add' do
130
+ let(:test_data) { { :email => 'test@example.com', :fax => '1234567890' } }
131
+
132
+ context 'when the response is successful' do
133
+ let(:response) { NetSuite::Response.new(:success => true, :body => { :internal_id => '1' }) }
134
+
135
+ it 'returns true' do
136
+ estimate = NetSuite::Records::Estimate.new(test_data)
137
+ expect(NetSuite::Actions::Add).to receive(:call).
138
+ with([estimate], {}).
139
+ and_return(response)
140
+ expect(estimate.add).to be_truthy
141
+ end
142
+ end
143
+
144
+ context 'when the response is unsuccessful' do
145
+ let(:response) { NetSuite::Response.new(:success => false, :body => {}) }
146
+
147
+ it 'returns false' do
148
+ estimate = NetSuite::Records::Estimate.new(test_data)
149
+ expect(NetSuite::Actions::Add).to receive(:call).
150
+ with([estimate], {}).
151
+ and_return(response)
152
+ expect(estimate.add).to be_falsey
153
+ end
154
+ end
155
+ end
156
+
157
+ describe '#delete' do
158
+ let(:test_data) { { :internal_id => '1' } }
159
+
160
+ context 'when the response is successful' do
161
+ let(:response) { NetSuite::Response.new(:success => true, :body => { :internal_id => '1' }) }
162
+
163
+ it 'returns true' do
164
+ estimate = NetSuite::Records::Estimate.new(test_data)
165
+ expect(NetSuite::Actions::Delete).to receive(:call).
166
+ with([estimate], {}).
167
+ and_return(response)
168
+ expect(estimate.delete).to be_truthy
169
+ end
170
+ end
171
+
172
+ context 'when the response is unsuccessful' do
173
+ let(:response) { NetSuite::Response.new(:success => false, :body => {}) }
174
+
175
+ it 'returns false' do
176
+ estimate = NetSuite::Records::Estimate.new(test_data)
177
+ expect(NetSuite::Actions::Delete).to receive(:call).
178
+ with([estimate], {}).
179
+ and_return(response)
180
+ expect(estimate.delete).to be_falsey
181
+ end
182
+ end
183
+ end
184
+
185
+ describe '#to_record' do
186
+ before do
187
+ estimate.email = 'something@example.com'
188
+ estimate.tran_id = '4'
189
+ end
190
+ it 'can represent itself as a SOAP record' do
191
+ record = {
192
+ 'tranSales:email' => 'something@example.com',
193
+ 'tranSales:tranId' => '4'
194
+ }
195
+ expect(estimate.to_record).to eql(record)
196
+ end
197
+ end
198
+
199
+ describe '#record_type' do
200
+ it 'returns a string representation of the SOAP type' do
201
+ expect(estimate.record_type).to eql('tranSales:Estimate')
202
+ end
203
+ end
204
+
205
+ skip "closing a sales order" do
206
+ it "closes each line to close the sales order" do
207
+ attributes = sales_order.attributes
208
+ attributes[:item_list].items.each do |item|
209
+ item.is_closed = true
210
+ item.attributes = item.attributes.slice(:line, :is_closed)
211
+ end
212
+
213
+ sales_order.update({ item_list: attributes[:item_list] })
214
+ end
215
+ end
216
+ end