netsuite 0.3.3 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +15 -0
  2. data/README.md +14 -12
  3. data/lib/netsuite.rb +16 -2
  4. data/lib/netsuite/actions/delete_list.rb +104 -0
  5. data/lib/netsuite/actions/login.rb +26 -1
  6. data/lib/netsuite/actions/search.rb +7 -3
  7. data/lib/netsuite/actions/upsert.rb +0 -4
  8. data/lib/netsuite/configuration.rb +1 -0
  9. data/lib/netsuite/namespaces/tran_purch.rb +11 -0
  10. data/lib/netsuite/records/cash_refund.rb +2 -2
  11. data/lib/netsuite/records/cash_sale.rb +41 -1
  12. data/lib/netsuite/records/cash_sale_item.rb +40 -0
  13. data/lib/netsuite/records/cash_sale_item_list.rb +25 -0
  14. data/lib/netsuite/records/contact.rb +1 -1
  15. data/lib/netsuite/records/contact_list.rb +1 -4
  16. data/lib/netsuite/records/credit_memo.rb +1 -1
  17. data/lib/netsuite/records/credit_memo_apply_list.rb +1 -4
  18. data/lib/netsuite/records/credit_memo_item.rb +1 -0
  19. data/lib/netsuite/records/credit_memo_item_list.rb +1 -4
  20. data/lib/netsuite/records/custom_field_list.rb +3 -0
  21. data/lib/netsuite/records/customer.rb +8 -8
  22. data/lib/netsuite/records/customer_payment.rb +1 -1
  23. data/lib/netsuite/records/customer_payment_apply.rb +1 -1
  24. data/lib/netsuite/records/customer_payment_apply_list.rb +13 -9
  25. data/lib/netsuite/records/customer_refund.rb +1 -1
  26. data/lib/netsuite/records/customer_refund_apply_list.rb +7 -3
  27. data/lib/netsuite/records/customer_refund_deposit_list.rb +1 -1
  28. data/lib/netsuite/records/deposit.rb +3 -3
  29. data/lib/netsuite/records/deposit_payment_list.rb +5 -2
  30. data/lib/netsuite/records/employee.rb +12 -4
  31. data/lib/netsuite/records/inventory_assignment.rb +1 -1
  32. data/lib/netsuite/records/inventory_assignment_list.rb +3 -1
  33. data/lib/netsuite/records/inventory_detail.rb +3 -3
  34. data/lib/netsuite/records/inventory_item.rb +4 -0
  35. data/lib/netsuite/records/invoice.rb +8 -4
  36. data/lib/netsuite/records/invoice_item_list.rb +4 -21
  37. data/lib/netsuite/records/job.rb +1 -1
  38. data/lib/netsuite/records/kit_item.rb +1 -1
  39. data/lib/netsuite/records/partner.rb +4 -2
  40. data/lib/netsuite/records/payment_method.rb +1 -1
  41. data/lib/netsuite/records/promotion_code.rb +1 -1
  42. data/lib/netsuite/records/rev_rec_template.rb +1 -1
  43. data/lib/netsuite/records/sales_order.rb +1 -1
  44. data/lib/netsuite/records/sales_order_item_list.rb +0 -1
  45. data/lib/netsuite/records/service_sale_item.rb +2 -2
  46. data/lib/netsuite/records/vendor_bill.rb +45 -0
  47. data/lib/netsuite/records/vendor_bill_expense.rb +40 -0
  48. data/lib/netsuite/records/vendor_bill_expense_list.rb +32 -0
  49. data/lib/netsuite/records/vendor_bill_item.rb +45 -0
  50. data/lib/netsuite/records/vendor_bill_item_list.rb +32 -0
  51. data/lib/netsuite/records/vendor_payment.rb +43 -0
  52. data/lib/netsuite/records/vendor_payment_apply.rb +16 -0
  53. data/lib/netsuite/records/vendor_payment_apply_list.rb +32 -0
  54. data/lib/netsuite/support/actions.rb +2 -2
  55. data/lib/netsuite/support/sublist.rb +13 -0
  56. data/lib/netsuite/version.rb +1 -1
  57. data/netsuite.gemspec +1 -1
  58. data/spec/netsuite/actions/delete_list_spec.rb +86 -0
  59. data/spec/netsuite/actions/login_spec.rb +21 -0
  60. data/spec/netsuite/records/cash_refund_spec.rb +1 -1
  61. data/spec/netsuite/records/cash_sale_item_list_spec.rb +27 -0
  62. data/spec/netsuite/records/cash_sale_item_spec.rb +23 -0
  63. data/spec/netsuite/records/credit_memo_apply_list_spec.rb +7 -8
  64. data/spec/netsuite/records/credit_memo_item_list_spec.rb +6 -8
  65. data/spec/netsuite/records/customer_payment_apply_list_spec.rb +25 -0
  66. data/spec/netsuite/records/customer_refund_apply_list_spec.rb +6 -8
  67. data/spec/netsuite/records/customer_spec.rb +6 -6
  68. data/spec/netsuite/records/employee_spec.rb +152 -0
  69. data/spec/netsuite/records/inventory_assignment_list_spec.rb +59 -0
  70. data/spec/netsuite/records/inventory_assignment_spec.rb +21 -0
  71. data/spec/netsuite/records/inventory_detail_spec.rb +13 -0
  72. data/spec/netsuite/records/invoice_spec.rb +3 -3
  73. data/spec/netsuite/records/job_spec.rb +4 -0
  74. data/spec/netsuite/records/vendor_bill_expense_list_spec.rb +36 -0
  75. data/spec/netsuite/records/vendor_bill_expense_spec.rb +72 -0
  76. data/spec/netsuite/records/vendor_bill_item_list_spec.rb +36 -0
  77. data/spec/netsuite/records/vendor_bill_item_spec.rb +118 -0
  78. data/spec/netsuite/records/vendor_bill_spec.rb +187 -0
  79. data/spec/netsuite/records/vendor_payment_apply_list_spec.rb +25 -0
  80. data/spec/netsuite/records/vendor_payment_apply_spec.rb +15 -0
  81. data/spec/netsuite/records/vendor_payment_spec.rb +164 -0
  82. data/spec/netsuite/support/sublist_spec.rb +6 -0
  83. data/spec/support/fixtures/delete_list/delete_list_customers.xml +26 -0
  84. data/spec/support/fixtures/delete_list/delete_list_customers_with_errors.xml +31 -0
  85. data/spec/support/fixtures/login.xml +35 -0
  86. metadata +58 -12
@@ -0,0 +1,59 @@
1
+ require 'spec_helper'
2
+
3
+ describe NetSuite::Records::InventoryAssignmentList do
4
+ let(:list) { NetSuite::Records::InventoryAssignmentList.new }
5
+
6
+ it 'has an assignments attribute' do
7
+ list.inventory_assignment.should be_kind_of(Array)
8
+ end
9
+
10
+ describe '#to_record' do
11
+ before do
12
+ list.inventory_assignment << NetSuite::Records::InventoryAssignment.new(
13
+ :quantity => 1
14
+ )
15
+ end
16
+
17
+ it 'can represent itself as a SOAP record' do
18
+
19
+ record = {
20
+ 'tranInvt:inventoryAssignment' => [{
21
+ 'platformCommon:quantity' => 1
22
+ }]
23
+ }
24
+ list.to_record.should eql(record)
25
+ end
26
+
27
+ it 'can represent replacing all' do
28
+ list.replace_all = true
29
+
30
+ record = {
31
+ 'tranInvt:inventoryAssignment' => [{
32
+ 'platformCommon:quantity' => 1
33
+ }],
34
+ :@replaceAll => true,
35
+ }
36
+
37
+ list.to_record.should eql(record)
38
+ end
39
+
40
+ it 'accepts a false replacing all' do
41
+ list = NetSuite::Records::InventoryAssignmentList.new(
42
+ :inventory_assignment => {
43
+ :quantity => 1
44
+ },
45
+ :replace_all => true,
46
+ )
47
+ list.replace_all = false
48
+
49
+ record = {
50
+ 'tranInvt:inventoryAssignment' => [{
51
+ 'platformCommon:quantity' => 1
52
+ }],
53
+ :@replaceAll => false,
54
+ }
55
+
56
+ list.to_record.should eql(record)
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe NetSuite::Records::InventoryAssignment do
4
+ let(:item) { NetSuite::Records::InventoryAssignment.new }
5
+
6
+ it 'has all the right fields' do
7
+ [
8
+ :expiration_date, :quantity, :quantity_available, :receipt_inventory_number
9
+ ].each do |field|
10
+ item.should have_field(field)
11
+ end
12
+ end
13
+
14
+ it 'has all the right record refs' do
15
+ [
16
+ :bin_number, :issue_inventory_number, :to_bin_number
17
+ ].each do |record_ref|
18
+ item.should have_record_ref(record_ref)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ require 'spec_helper'
2
+
3
+ describe NetSuite::Records::InventoryDetail do
4
+ let(:item) { NetSuite::Records::InventoryDetail.new }
5
+
6
+ it 'has all the right record refs' do
7
+ [
8
+ :custom_form
9
+ ].each do |record_ref|
10
+ item.should have_record_ref(record_ref)
11
+ end
12
+ end
13
+ end
@@ -17,8 +17,8 @@ describe NetSuite::Records::Invoice do
17
17
  :handling_tax_2_rate, :handling_tax_code, :is_taxable, :item_cost_disc_amount, :item_cost_disc_print,
18
18
  :item_cost_disc_rate, :item_cost_disc_tax_1_amt, :item_cost_disc_taxable, :item_cost_discount, :item_cost_list,
19
19
  :item_cost_tax_code, :item_cost_tax_rate_1, :item_cost_tax_rate_2, :job, :last_modified_date,
20
- :lead_source, :linked_tracking_numbers, :memo, :message, :message_sel, :on_credit_hold, :opportunity,
21
- :other_ref_num, :partners_list, :promo_code, :rev_rec_end_date,
20
+ :linked_tracking_numbers, :memo, :message, :message_sel, :on_credit_hold, :opportunity,
21
+ :other_ref_num, :partners_list, :rev_rec_end_date,
22
22
  :rev_rec_on_rev_commitment, :rev_rec_schedule, :rev_rec_start_date, :revenue_status, :sales_effective_date,
23
23
  :sales_group, :sales_team_list, :ship_address, :ship_date, :ship_group_list,
24
24
  :shipping_cost, :shipping_tax_1_rate, :shipping_tax_2_rate, :shipping_tax_code, :source, :start_date,
@@ -44,7 +44,7 @@ describe NetSuite::Records::Invoice do
44
44
  it 'has the right record_refs' do
45
45
  [
46
46
  :account, :bill_address_list, :custom_form, :department, :entity, :klass, :posting_period, :ship_address_list, :terms,
47
- :created_from, :location, :sales_rep, :ship_method, :tax_item, :partner
47
+ :created_from, :location, :sales_rep, :ship_method, :tax_item, :partner, :lead_source, :promo_code
48
48
  ].each do |record_ref|
49
49
  expect(invoice).to have_record_ref(record_ref)
50
50
  end
@@ -200,6 +200,10 @@ describe NetSuite::Records::Job do
200
200
  end
201
201
  end
202
202
 
203
+ describe '.search' do
204
+ it 'searches'
205
+ end
206
+
203
207
  describe '#to_record' do
204
208
  let(:job) { NetSuite::Records::Job.new(:entity_id => 'TEST JOB', :account_number => 7) }
205
209
 
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe NetSuite::Records::VendorBillExpenseList do
4
+ let(:expense_list) { NetSuite::Records::VendorBillExpenseList.new }
5
+ let(:expense) { NetSuite::Records::VendorBillExpense.new }
6
+
7
+ it 'can be initialized with a hash' do
8
+ expense_list = NetSuite::Records::VendorBillExpenseList.new(expense: {})
9
+ expect(expense_list.expenses).to be_kind_of(Array)
10
+ expect(expense_list.expenses.length).to eql(1)
11
+ expect(expense_list.expenses[0]).to be_kind_of(NetSuite::Records::VendorBillExpense)
12
+ end
13
+
14
+ it 'can be initialized with a hash list' do
15
+ expense_list = NetSuite::Records::VendorBillExpenseList.new(expense: [{}])
16
+ expect(expense_list.expenses).to be_kind_of(Array)
17
+ expect(expense_list.expenses.length).to eql(1)
18
+ expect(expense_list.expenses[0]).to be_kind_of(NetSuite::Records::VendorBillExpense)
19
+ end
20
+
21
+ it 'can have expenses be added to it' do
22
+ expense_list.expenses << expense
23
+ expect(expense_list.expenses).to be_kind_of(Array)
24
+ expect(expense_list.expenses.length).to eql(1)
25
+ expect(expense_list.expenses[0]).to be_kind_of(NetSuite::Records::VendorBillExpense)
26
+ end
27
+
28
+ describe '#to_record' do
29
+ it 'can represent itself as a SOAP record' do
30
+ record = {
31
+ 'tranPurch:expense' => []
32
+ }
33
+ expect(expense_list.to_record).to eql(record)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,72 @@
1
+ require 'spec_helper'
2
+
3
+ describe NetSuite::Records::VendorBillExpense do
4
+ let(:expense) { NetSuite::Records::VendorBillExpense.new }
5
+
6
+ it 'has the right fields' do
7
+ [
8
+ :amount, :amortization_end_date, :amortiz_start_date, :amortization_residual, :gross_amt, :is_billable,
9
+ :line, :memo, :order_doc, :order_line, :tax_1_amt, :tax_rate_1, :tax_rate_2
10
+ ].each do |field|
11
+ expect(expense).to have_field(field)
12
+ end
13
+ end
14
+
15
+ it 'has the right record_refs' do
16
+ [
17
+ :account, :amortization_sched, :klass, :category, :customer, :department, :location, :tax_code
18
+ ].each do |record_ref|
19
+ expect(expense).to have_record_ref(record_ref)
20
+ end
21
+ end
22
+
23
+ it 'can initialize from a record' do
24
+ record = NetSuite::Records::VendorBillExpense.new(:amount => 123)
25
+ expense = NetSuite::Records::VendorBillExpense.new(record)
26
+ expect(expense).to be_kind_of(NetSuite::Records::VendorBillExpense)
27
+ expect(expense.amount).to eql(123)
28
+ end
29
+
30
+ describe '#custom_field_list' do
31
+ it 'can be set from attributes' do
32
+ attributes = {
33
+ :custom_field => {
34
+ :value => 10,
35
+ :internal_id => 'custfield_value'
36
+ }
37
+ }
38
+ expense.custom_field_list = attributes
39
+ expect(expense.custom_field_list).to be_kind_of(NetSuite::Records::CustomFieldList)
40
+ expect(expense.custom_field_list.custom_fields.length).to eql(1)
41
+ expect(expense.custom_field_list.custfield_value.attributes[:value]).to eq(10)
42
+ end
43
+
44
+ it 'can be set from a CustomFieldList object' do
45
+ custom_field_list = NetSuite::Records::CustomFieldList.new
46
+ expense.custom_field_list = custom_field_list
47
+ expect(expense.custom_field_list).to eql(custom_field_list)
48
+ end
49
+ end
50
+
51
+ describe '#to_record' do
52
+ before do
53
+ expense.amount = '123'
54
+ expense.memo = 'a memo'
55
+ end
56
+
57
+ it 'can represent itself as a SOAP record' do
58
+ record = {
59
+ 'tranPurch:amount' => '123',
60
+ 'tranPurch:memo' => 'a memo'
61
+ }
62
+ expect(expense.to_record).to eql(record)
63
+ end
64
+ end
65
+
66
+ describe '#record_type' do
67
+ it 'returns a string of the SOAP record type' do
68
+ expect(expense.record_type).to eql('tranPurch:VendorBillExpense')
69
+ end
70
+ end
71
+
72
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe NetSuite::Records::VendorBillItemList do
4
+ let(:item_list) { NetSuite::Records::VendorBillItemList.new }
5
+ let(:item) { NetSuite::Records::VendorBillItem.new }
6
+
7
+ it 'can be initialized with a hash' do
8
+ item_list = NetSuite::Records::VendorBillItemList.new(item: {})
9
+ expect(item_list.items).to be_kind_of(Array)
10
+ expect(item_list.items.length).to eql(1)
11
+ expect(item_list.items[0]).to be_kind_of(NetSuite::Records::VendorBillItem)
12
+ end
13
+
14
+ it 'can be initialized with a hash list' do
15
+ item_list = NetSuite::Records::VendorBillItemList.new(item: [{}])
16
+ expect(item_list.items).to be_kind_of(Array)
17
+ expect(item_list.items.length).to eql(1)
18
+ expect(item_list.items[0]).to be_kind_of(NetSuite::Records::VendorBillItem)
19
+ end
20
+
21
+ it 'can have items be added to it' do
22
+ item_list.items << item
23
+ expect(item_list.items).to be_kind_of(Array)
24
+ expect(item_list.items.length).to eql(1)
25
+ expect(item_list.items[0]).to be_kind_of(NetSuite::Records::VendorBillItem)
26
+ end
27
+
28
+ describe '#to_record' do
29
+ it 'can represent itself as a SOAP record' do
30
+ record = {
31
+ 'tranPurch:item' => []
32
+ }
33
+ expect(item_list.to_record).to eql(record)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,118 @@
1
+ require 'spec_helper'
2
+
3
+ describe NetSuite::Records::VendorBillItem do
4
+ let(:item) { NetSuite::Records::VendorBillItem.new }
5
+
6
+ it 'has the right fields' do
7
+ [
8
+ :amortization_end_date, :amortization_residual, :amortiz_start_date, :bin_numbers, :bill_variance_status,
9
+ :description, :expiration_date, :gross_amt, :inventory_detail, :is_billable, :landed_cost, :line,
10
+ :order_doc, :order_line, :quantity, :serial_numbers, :tax_rate_1, :tax_rate_2, :tax_1_amt, :vendor_name
11
+ ].each do |field|
12
+ expect(item).to have_field(field)
13
+ end
14
+ end
15
+
16
+ it 'has the right record_refs' do
17
+ [
18
+ :amortization_sched, :klass, :customer, :department, :item, :landed_cost_category, :location, :tax_code, :units
19
+ ].each do |record_ref|
20
+ expect(item).to have_record_ref(record_ref)
21
+ end
22
+ end
23
+
24
+ it 'has all the right read_only_fields' do
25
+ [
26
+ :amount
27
+ ].each do |field|
28
+ expect(NetSuite::Records::VendorBillItem).to have_read_only_field(field)
29
+ end
30
+ end
31
+
32
+ it 'can initialize from a record' do
33
+ record = NetSuite::Records::VendorBillItem.new(:gross_amt => 123, :description => 'some item')
34
+ item = NetSuite::Records::VendorBillItem.new(record)
35
+ expect(item).to be_kind_of(NetSuite::Records::VendorBillItem)
36
+ expect(item.gross_amt).to eql(123)
37
+ expect(item.description).to eql('some item')
38
+ end
39
+
40
+ describe '#custom_field_list' do
41
+ it 'can be set from attributes' do
42
+ attributes = {
43
+ :custom_field => {
44
+ :value => 10,
45
+ :internal_id => 'custfield_value'
46
+ }
47
+ }
48
+ item.custom_field_list = attributes
49
+ expect(item.custom_field_list).to be_kind_of(NetSuite::Records::CustomFieldList)
50
+ expect(item.custom_field_list.custom_fields.length).to eql(1)
51
+ expect(item.custom_field_list.custfield_value.attributes[:value]).to eq(10)
52
+ end
53
+
54
+ it 'can be set from a CustomFieldList object' do
55
+ custom_field_list = NetSuite::Records::CustomFieldList.new
56
+ item.custom_field_list = custom_field_list
57
+ expect(item.custom_field_list).to eql(custom_field_list)
58
+ end
59
+ end
60
+
61
+ describe '#options' do
62
+ it 'can be set from attributes' do
63
+ attributes = {
64
+ :custom_field => {
65
+ :value => 10,
66
+ :internal_id => 'custfield_value'
67
+ }
68
+ }
69
+ item.options = attributes
70
+ expect(item.options).to be_kind_of(NetSuite::Records::CustomFieldList)
71
+ expect(item.options.custom_fields.length).to eql(1)
72
+ expect(item.options.custfield_value.attributes[:value]).to eq(10)
73
+ end
74
+
75
+ it 'can be set from a CustomFieldList object' do
76
+ custom_field_list = NetSuite::Records::CustomFieldList.new
77
+ item.custom_field_list = custom_field_list
78
+ expect(item.custom_field_list).to eql(custom_field_list)
79
+ end
80
+ end
81
+
82
+ describe '#bill_receipts_list' do
83
+ it 'can be set from attributes' do
84
+ attributes = {
85
+ :record_ref => {
86
+ :internal_id => 'some id',
87
+ :value => 'some value'
88
+ }
89
+ }
90
+ item.bill_receipts_list = attributes
91
+ expect(item.bill_receipts_list).to be_kind_of(NetSuite::Records::RecordRefList)
92
+ expect(item.bill_receipts_list.record_ref.length).to eql(1)
93
+ expect(item.bill_receipts_list.record_ref[0].value).to eq('some value')
94
+ end
95
+ end
96
+
97
+ describe '#to_record' do
98
+ before do
99
+ item.gross_amt = '123'
100
+ item.description = 'some item'
101
+ end
102
+
103
+ it 'can represent itself as a SOAP record' do
104
+ record = {
105
+ 'tranPurch:grossAmt' => '123',
106
+ 'tranPurch:description' => 'some item'
107
+ }
108
+ expect(item.to_record).to eql(record)
109
+ end
110
+ end
111
+
112
+ describe '#record_type' do
113
+ it 'returns a string of the SOAP record type' do
114
+ expect(item.record_type).to eql('tranPurch:VendorBillItem')
115
+ end
116
+ end
117
+
118
+ end
@@ -0,0 +1,187 @@
1
+ require 'spec_helper'
2
+
3
+ describe NetSuite::Records::VendorBill do
4
+ let(:bill) { NetSuite::Records::VendorBill.new(external_id: 'some id') }
5
+ let(:vendor) { NetSuite::Records::Vendor.new }
6
+ let(:response) { NetSuite::Response.new(:success => true, :body => { :@internal_id => '1', :@external_id =>'some id' }) }
7
+
8
+ it 'has all the right fields' do
9
+ [
10
+ :created_date, :credit_limit, :currency_name, :discount_amount, :discount_date, :due_date, :exchange_rate,
11
+ :landed_costs_list, :landed_cost_method, :landed_cost_per_line, :last_modified_date, :memo, :tax_total,
12
+ :tax_2_total, :transaction_number, :tran_date, :tran_id, :user_total, :vat_reg_num
13
+ ].each do |field|
14
+ expect(bill).to have_field(field)
15
+ end
16
+ end
17
+
18
+ it 'has all the right read_only_fields' do
19
+ [
20
+ :status
21
+ ].each do |field|
22
+ expect(NetSuite::Records::VendorBill).to have_read_only_field(field)
23
+ end
24
+ end
25
+
26
+ it 'has the right record_refs' do
27
+ [
28
+ :custom_form, :account, :entity, :subsidiary, :approval_status, :next_approver, :posting_period, :terms,
29
+ :currency, :klass, :department, :location
30
+ ].each do |record_ref|
31
+ expect(bill).to have_record_ref(record_ref)
32
+ end
33
+ end
34
+
35
+ describe '#custom_field_list' do
36
+ it 'can be set from attributes' do
37
+ attributes = {
38
+ :custom_field => {
39
+ :amount => 10,
40
+ :internal_id => 'custfield_amount'
41
+ }
42
+ }
43
+ bill.custom_field_list = attributes
44
+ expect(bill.custom_field_list).to be_kind_of(NetSuite::Records::CustomFieldList)
45
+ expect(bill.custom_field_list.custom_fields.length).to eql(1)
46
+ end
47
+
48
+ it 'can be set from a CustomFieldList object' do
49
+ custom_field_list = NetSuite::Records::CustomFieldList.new
50
+ bill.custom_field_list = custom_field_list
51
+ expect(bill.custom_field_list).to eql(custom_field_list)
52
+ end
53
+ end
54
+
55
+ describe '#item_list' do
56
+ it 'can be set from attributes' do
57
+ attributes = {
58
+ :item => {
59
+ :amount => 10
60
+ }
61
+ }
62
+ bill.item_list = attributes
63
+ expect(bill.item_list).to be_kind_of(NetSuite::Records::VendorBillItemList)
64
+ expect(bill.item_list.items.length).to eql(1)
65
+ end
66
+
67
+ it 'can be set from a VendorBillItemList object' do
68
+ item_list = NetSuite::Records::VendorBillItemList.new
69
+ bill.item_list = item_list
70
+ expect(bill.item_list).to eql(item_list)
71
+ end
72
+ end
73
+
74
+ describe '#expense_list' do
75
+ it 'can be set from attributes' do
76
+ attributes = {
77
+ :expense => {
78
+ :gross_amt => 10
79
+ }
80
+ }
81
+ bill.expense_list = attributes
82
+ expect(bill.expense_list).to be_kind_of(NetSuite::Records::VendorBillExpenseList)
83
+ expect(bill.expense_list.expenses.length).to eql(1)
84
+ end
85
+
86
+ it 'can be set from a VendorBillExpenseList object' do
87
+ expense_list = NetSuite::Records::VendorBillExpenseList.new
88
+ bill.expense_list = expense_list
89
+ expect(bill.expense_list).to eql(expense_list)
90
+ end
91
+ end
92
+
93
+ describe '#purchase_order_list' do
94
+ it 'can be set from attributes' do
95
+ attributes = {
96
+ :record_ref => {
97
+ :internal_id => 'some id',
98
+ :value => 'some value'
99
+ }
100
+ }
101
+ bill.purchase_order_list = attributes
102
+ expect(bill.purchase_order_list).to be_kind_of(NetSuite::Records::RecordRefList)
103
+ expect(bill.purchase_order_list.record_ref.length).to eql(1)
104
+ expect(bill.purchase_order_list.record_ref[0].value).to eq('some value')
105
+ end
106
+ end
107
+
108
+ describe '.get' do
109
+ context 'when the response is successful' do
110
+ it 'returns an VendorBill instance populated with the data from the response object' do
111
+ expect(NetSuite::Actions::Get).to receive(:call).with([NetSuite::Records::VendorBill, external_id: 'some id'], {}).and_return(response)
112
+ bill = NetSuite::Records::VendorBill.get(external_id: 'some id')
113
+ expect(bill).to be_kind_of(NetSuite::Records::VendorBill)
114
+ expect(bill.internal_id).to eq('1')
115
+ end
116
+ end
117
+
118
+ context 'when the response is unsuccessful' do
119
+ let(:response) { NetSuite::Response.new(:success => false, :body => {}) }
120
+
121
+ it 'raises a RecordNotFound exception' do
122
+ expect(NetSuite::Actions::Get).to receive(:call).with([NetSuite::Records::VendorBill, external_id: 'some id'], {}).and_return(response)
123
+ expect {
124
+ NetSuite::Records::VendorBill.get(external_id: 'some id')
125
+ }.to raise_error(NetSuite::RecordNotFound,
126
+ /NetSuite::Records::VendorBill with OPTIONS=(.*) could not be found/)
127
+ end
128
+ end
129
+ end
130
+
131
+ describe '.initialize' do
132
+ context 'when the request is successful' do
133
+ it 'returns an initialized vendor bill from the vendor entity' do
134
+ expect(NetSuite::Actions::Initialize).to receive(:call).with([NetSuite::Records::VendorBill, vendor], {}).and_return(response)
135
+ bill = NetSuite::Records::VendorBill.initialize(vendor)
136
+ expect(bill).to be_kind_of(NetSuite::Records::VendorBill)
137
+ end
138
+ end
139
+
140
+ context 'when the response is unsuccessful' do
141
+ let(:response) { NetSuite::Response.new(:success => false, :body => {}) }
142
+
143
+ it 'raises a InitializationError exception' do
144
+ expect(NetSuite::Actions::Initialize).to receive(:call).with([NetSuite::Records::VendorBill, vendor], {}).and_return(response)
145
+ expect {
146
+ NetSuite::Records::VendorBill.initialize(vendor)
147
+ }.to raise_error(NetSuite::InitializationError,
148
+ /NetSuite::Records::VendorBill.initialize with .+ failed./)
149
+ end
150
+ end
151
+ end
152
+
153
+ describe '#add' do
154
+ context 'when the response is successful' do
155
+ it 'returns true' do
156
+ expect(NetSuite::Actions::Add).to receive(:call).with([bill], {}).and_return(response)
157
+ expect(bill.add).to be_truthy
158
+ expect(bill.internal_id).to eq('1')
159
+ end
160
+ end
161
+
162
+ context 'when the response is unsuccessful' do
163
+ let(:response) { NetSuite::Response.new(:success => false, :body => {}) }
164
+ it 'returns false' do
165
+ expect(NetSuite::Actions::Add).to receive(:call).with([bill], {}).and_return(response)
166
+ expect(bill.add).to be_falsey
167
+ end
168
+ end
169
+ end
170
+
171
+ describe '#delete' do
172
+ context 'when the response is successful' do
173
+ it 'returns true' do
174
+ expect(NetSuite::Actions::Delete).to receive(:call).with([bill], {}).and_return(response)
175
+ expect(bill.delete).to be_truthy
176
+ end
177
+ end
178
+
179
+ context 'when the response is unsuccessful' do
180
+ let(:response) { NetSuite::Response.new(:success => false, :body => {}) }
181
+ it 'returns false' do
182
+ expect(NetSuite::Actions::Delete).to receive(:call).with([bill], {}).and_return(response)
183
+ expect(bill.delete).to be_falsey
184
+ end
185
+ end
186
+ end
187
+ end