netsuite 0.3.3 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/README.md +14 -12
- data/lib/netsuite.rb +16 -2
- data/lib/netsuite/actions/delete_list.rb +104 -0
- data/lib/netsuite/actions/login.rb +26 -1
- data/lib/netsuite/actions/search.rb +7 -3
- data/lib/netsuite/actions/upsert.rb +0 -4
- data/lib/netsuite/configuration.rb +1 -0
- data/lib/netsuite/namespaces/tran_purch.rb +11 -0
- data/lib/netsuite/records/cash_refund.rb +2 -2
- data/lib/netsuite/records/cash_sale.rb +41 -1
- data/lib/netsuite/records/cash_sale_item.rb +40 -0
- data/lib/netsuite/records/cash_sale_item_list.rb +25 -0
- data/lib/netsuite/records/contact.rb +1 -1
- data/lib/netsuite/records/contact_list.rb +1 -4
- data/lib/netsuite/records/credit_memo.rb +1 -1
- data/lib/netsuite/records/credit_memo_apply_list.rb +1 -4
- data/lib/netsuite/records/credit_memo_item.rb +1 -0
- data/lib/netsuite/records/credit_memo_item_list.rb +1 -4
- data/lib/netsuite/records/custom_field_list.rb +3 -0
- data/lib/netsuite/records/customer.rb +8 -8
- data/lib/netsuite/records/customer_payment.rb +1 -1
- data/lib/netsuite/records/customer_payment_apply.rb +1 -1
- data/lib/netsuite/records/customer_payment_apply_list.rb +13 -9
- data/lib/netsuite/records/customer_refund.rb +1 -1
- data/lib/netsuite/records/customer_refund_apply_list.rb +7 -3
- data/lib/netsuite/records/customer_refund_deposit_list.rb +1 -1
- data/lib/netsuite/records/deposit.rb +3 -3
- data/lib/netsuite/records/deposit_payment_list.rb +5 -2
- data/lib/netsuite/records/employee.rb +12 -4
- data/lib/netsuite/records/inventory_assignment.rb +1 -1
- data/lib/netsuite/records/inventory_assignment_list.rb +3 -1
- data/lib/netsuite/records/inventory_detail.rb +3 -3
- data/lib/netsuite/records/inventory_item.rb +4 -0
- data/lib/netsuite/records/invoice.rb +8 -4
- data/lib/netsuite/records/invoice_item_list.rb +4 -21
- data/lib/netsuite/records/job.rb +1 -1
- data/lib/netsuite/records/kit_item.rb +1 -1
- data/lib/netsuite/records/partner.rb +4 -2
- data/lib/netsuite/records/payment_method.rb +1 -1
- data/lib/netsuite/records/promotion_code.rb +1 -1
- data/lib/netsuite/records/rev_rec_template.rb +1 -1
- data/lib/netsuite/records/sales_order.rb +1 -1
- data/lib/netsuite/records/sales_order_item_list.rb +0 -1
- data/lib/netsuite/records/service_sale_item.rb +2 -2
- data/lib/netsuite/records/vendor_bill.rb +45 -0
- data/lib/netsuite/records/vendor_bill_expense.rb +40 -0
- data/lib/netsuite/records/vendor_bill_expense_list.rb +32 -0
- data/lib/netsuite/records/vendor_bill_item.rb +45 -0
- data/lib/netsuite/records/vendor_bill_item_list.rb +32 -0
- data/lib/netsuite/records/vendor_payment.rb +43 -0
- data/lib/netsuite/records/vendor_payment_apply.rb +16 -0
- data/lib/netsuite/records/vendor_payment_apply_list.rb +32 -0
- data/lib/netsuite/support/actions.rb +2 -2
- data/lib/netsuite/support/sublist.rb +13 -0
- data/lib/netsuite/version.rb +1 -1
- data/netsuite.gemspec +1 -1
- data/spec/netsuite/actions/delete_list_spec.rb +86 -0
- data/spec/netsuite/actions/login_spec.rb +21 -0
- data/spec/netsuite/records/cash_refund_spec.rb +1 -1
- data/spec/netsuite/records/cash_sale_item_list_spec.rb +27 -0
- data/spec/netsuite/records/cash_sale_item_spec.rb +23 -0
- data/spec/netsuite/records/credit_memo_apply_list_spec.rb +7 -8
- data/spec/netsuite/records/credit_memo_item_list_spec.rb +6 -8
- data/spec/netsuite/records/customer_payment_apply_list_spec.rb +25 -0
- data/spec/netsuite/records/customer_refund_apply_list_spec.rb +6 -8
- data/spec/netsuite/records/customer_spec.rb +6 -6
- data/spec/netsuite/records/employee_spec.rb +152 -0
- data/spec/netsuite/records/inventory_assignment_list_spec.rb +59 -0
- data/spec/netsuite/records/inventory_assignment_spec.rb +21 -0
- data/spec/netsuite/records/inventory_detail_spec.rb +13 -0
- data/spec/netsuite/records/invoice_spec.rb +3 -3
- data/spec/netsuite/records/job_spec.rb +4 -0
- data/spec/netsuite/records/vendor_bill_expense_list_spec.rb +36 -0
- data/spec/netsuite/records/vendor_bill_expense_spec.rb +72 -0
- data/spec/netsuite/records/vendor_bill_item_list_spec.rb +36 -0
- data/spec/netsuite/records/vendor_bill_item_spec.rb +118 -0
- data/spec/netsuite/records/vendor_bill_spec.rb +187 -0
- data/spec/netsuite/records/vendor_payment_apply_list_spec.rb +25 -0
- data/spec/netsuite/records/vendor_payment_apply_spec.rb +15 -0
- data/spec/netsuite/records/vendor_payment_spec.rb +164 -0
- data/spec/netsuite/support/sublist_spec.rb +6 -0
- data/spec/support/fixtures/delete_list/delete_list_customers.xml +26 -0
- data/spec/support/fixtures/delete_list/delete_list_customers_with_errors.xml +31 -0
- data/spec/support/fixtures/login.xml +35 -0
- metadata +58 -12
@@ -0,0 +1,86 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NetSuite::Actions::DeleteList do
|
4
|
+
before(:all) { savon.mock! }
|
5
|
+
after(:all) { savon.unmock! }
|
6
|
+
|
7
|
+
context 'Customer' do
|
8
|
+
let(:klass) { NetSuite::Records::Customer }
|
9
|
+
let(:customer) do
|
10
|
+
NetSuite::Records::Customer.new(:internal_id => '1', :entity_id => 'Customer', :company_name => 'Customer')
|
11
|
+
end
|
12
|
+
|
13
|
+
context 'without errors' do
|
14
|
+
let(:other_customer) do
|
15
|
+
NetSuite::Records::Customer.new(:internal_id => '2', :entity_id => 'Other_Customer', :company_name => 'Other Customer')
|
16
|
+
end
|
17
|
+
let(:customer_list) { [customer.internal_id, other_customer.internal_id] }
|
18
|
+
|
19
|
+
before do
|
20
|
+
savon.expects(:delete_list).with(:message =>
|
21
|
+
{
|
22
|
+
:baseRef =>
|
23
|
+
[
|
24
|
+
{
|
25
|
+
'@internalId' => customer.internal_id,
|
26
|
+
'@type' => 'customer',
|
27
|
+
'@xsi:type' => 'platformCore:RecordRef'
|
28
|
+
},
|
29
|
+
{
|
30
|
+
'@internalId' => other_customer.internal_id,
|
31
|
+
'@type' => 'customer',
|
32
|
+
'@xsi:type' => 'platformCore:RecordRef'
|
33
|
+
}
|
34
|
+
]
|
35
|
+
}
|
36
|
+
).returns(File.read('spec/support/fixtures/delete_list/delete_list_customers.xml'))
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'makes a valid request to the NetSuite API' do
|
40
|
+
NetSuite::Actions::DeleteList.call([klass, :list => customer_list])
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'returns a valid Response object' do
|
44
|
+
response = NetSuite::Actions::DeleteList.call([klass, :list => customer_list])
|
45
|
+
|
46
|
+
expect(response).to be_kind_of(NetSuite::Response)
|
47
|
+
expect(response).to be_success
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'with errors' do
|
52
|
+
let(:customer_with_error) do
|
53
|
+
NetSuite::Records::Customer.new(:internal_id => 'bad_id', :entity_id => 'Erroneous_Customer', :company_name => 'Erroneous Customer')
|
54
|
+
end
|
55
|
+
let(:customer_list_with_error) { [customer.internal_id, customer_with_error.internal_id] }
|
56
|
+
|
57
|
+
before do
|
58
|
+
savon.expects(:delete_list).with(:message =>
|
59
|
+
{
|
60
|
+
:baseRef =>
|
61
|
+
[
|
62
|
+
{
|
63
|
+
'@internalId' => customer.internal_id,
|
64
|
+
'@type' => 'customer',
|
65
|
+
'@xsi:type' => 'platformCore:RecordRef'
|
66
|
+
},
|
67
|
+
{
|
68
|
+
'@internalId' => customer_with_error.internal_id,
|
69
|
+
'@type' => 'customer',
|
70
|
+
'@xsi:type' => 'platformCore:RecordRef'
|
71
|
+
}
|
72
|
+
]
|
73
|
+
}
|
74
|
+
).returns(File.read('spec/support/fixtures/delete_list/delete_list_customers_with_errors.xml'))
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'constructs error objects' do
|
78
|
+
response = NetSuite::Actions::DeleteList.call([klass, :list => customer_list_with_error])
|
79
|
+
expect(response.errors.keys).to match_array(customer_with_error.internal_id)
|
80
|
+
expect(response.errors[customer_with_error.internal_id].first.code).to eq('USER_EXCEPTION')
|
81
|
+
expect(response.errors[customer_with_error.internal_id].first.message).to eq('Invalid record: type=event,id=100015,scompid=TSTDRV96')
|
82
|
+
expect(response.errors[customer_with_error.internal_id].first.type).to eq('ERROR')
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NetSuite::Actions::Login do
|
4
|
+
before { savon.mock! }
|
5
|
+
after { savon.unmock! }
|
6
|
+
|
7
|
+
it 'properly executes a login call' do
|
8
|
+
message = {"platformMsgs:passport"=>{"platformCore:email"=>"email", "platformCore:password"=>"password", "platformCore:account"=>"1234", "platformCore:role"=>234}}
|
9
|
+
|
10
|
+
savon.expects(:login).with(:message => message).returns(File.read('spec/support/fixtures/login.xml'))
|
11
|
+
|
12
|
+
result = NetSuite::Actions::Login.call({
|
13
|
+
email: 'email',
|
14
|
+
password: 'password',
|
15
|
+
role: 234
|
16
|
+
})
|
17
|
+
|
18
|
+
expect(result.success?).to eq(true)
|
19
|
+
expect(result.body[:user_id]).to_not be_nil
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NetSuite::Records::CashSaleItemList do
|
4
|
+
let(:list) { NetSuite::Records::CashSaleItemList.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::CashSaleItem.new(
|
13
|
+
:amount => 10
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'can represent itself as a SOAP record' do
|
18
|
+
record = {
|
19
|
+
'tranSales:item' => [{
|
20
|
+
'tranSales:amount' => 10
|
21
|
+
}]
|
22
|
+
}
|
23
|
+
expect(list.to_record).to eql(record)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NetSuite::Records::CashSaleItem do
|
4
|
+
let(:item) { NetSuite::Records::CashSaleItem.new }
|
5
|
+
|
6
|
+
it 'has all the right fields' do
|
7
|
+
[
|
8
|
+
:amount
|
9
|
+
].each do |field|
|
10
|
+
expect(item).to have_field(field)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it 'has all the right record refs' do
|
15
|
+
[
|
16
|
+
:item, :klass
|
17
|
+
].each do |record_ref|
|
18
|
+
expect(item).to have_record_ref(record_ref)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
@@ -15,14 +15,13 @@ describe NetSuite::Records::CreditMemoApplyList do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'can represent itself as a SOAP record' do
|
18
|
-
record =
|
19
|
-
{
|
20
|
-
'tranCust:
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
expect(list.to_record).to eql(record)
|
18
|
+
record = {
|
19
|
+
'tranCust:apply' => [{
|
20
|
+
'tranCust:job' => 'something'
|
21
|
+
}]
|
22
|
+
}
|
23
|
+
|
24
|
+
expect(list.to_record.should).to eq(record)
|
26
25
|
end
|
27
26
|
end
|
28
27
|
end
|
@@ -15,14 +15,12 @@ describe NetSuite::Records::CreditMemoItemList do
|
|
15
15
|
end
|
16
16
|
|
17
17
|
it 'can represent itself as a SOAP record' do
|
18
|
-
record =
|
19
|
-
{
|
20
|
-
'tranCust:
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
]
|
25
|
-
expect(list.to_record).to eql(record)
|
18
|
+
record = {
|
19
|
+
'tranCust:item' => [{
|
20
|
+
'tranCust:rate' => 10
|
21
|
+
}]
|
22
|
+
}
|
23
|
+
list.to_record.should eql(record)
|
26
24
|
end
|
27
25
|
end
|
28
26
|
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NetSuite::Records::CustomerPaymentApplyList do
|
4
|
+
let(:list) { NetSuite::Records::CustomerPaymentApplyList.new }
|
5
|
+
let(:apply) { NetSuite::Records::CustomerPaymentApply.new }
|
6
|
+
|
7
|
+
it 'can have applies be added to it' do
|
8
|
+
list.applies << apply
|
9
|
+
apply_list = list.applies
|
10
|
+
expect(apply_list).to be_kind_of(Array)
|
11
|
+
expect(apply_list.length).to eql(1)
|
12
|
+
apply_list.each { |i| expect(i).to be_kind_of(NetSuite::Records::CustomerPaymentApply) }
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#to_record' do
|
16
|
+
it 'can represent itself as a SOAP record' do
|
17
|
+
record = {
|
18
|
+
'tranCust:apply' => [{},{}]
|
19
|
+
}
|
20
|
+
list.applies.concat([apply,apply])
|
21
|
+
expect(list.to_record).to eql(record)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
@@ -13,14 +13,12 @@ describe NetSuite::Records::CustomerRefundApplyList do
|
|
13
13
|
end
|
14
14
|
|
15
15
|
it 'can represent itself as a SOAP record' do
|
16
|
-
record =
|
17
|
-
{
|
18
|
-
'tranCust:
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
]
|
23
|
-
expect(list.to_record).to eql(record)
|
16
|
+
record = {
|
17
|
+
'tranCust:apply' => [{
|
18
|
+
'tranCust:amount' => 10
|
19
|
+
}]
|
20
|
+
}
|
21
|
+
list.to_record.should eql(record)
|
24
22
|
end
|
25
23
|
end
|
26
24
|
|
@@ -5,20 +5,20 @@ describe NetSuite::Records::Customer do
|
|
5
5
|
|
6
6
|
it 'has all the right fields' do
|
7
7
|
[
|
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
11
|
:consol_unbilled_orders, :contrib_pct, :credit_cards_list, :credit_hold_override, :credit_limit,
|
12
|
-
:
|
12
|
+
:currency_list, :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,
|
15
15
|
:group_pricing_list, :home_phone, :image, :is_budget_approved, :is_inactive, :is_person, :item_pricing_list, :keywords,
|
16
16
|
:language, :last_modified_date, :last_name, :last_page_visited, :last_visit, :middle_name, :mobile_phone,
|
17
|
-
:opening_balance, :opening_balance_account, :opening_balance_date, :overdue_balance, :
|
17
|
+
:opening_balance, :opening_balance_account, :opening_balance_date, :overdue_balance, :partners_list,
|
18
18
|
:password, :password2, :phone, :phonetic_name, :pref_cc_processor,:print_on_check_as,
|
19
19
|
:print_transactions, :referrer, :reminder_days, :representing_subsidiary, :require_pwd_change, :resale_number,
|
20
|
-
:sales_group, :sales_readiness, :
|
21
|
-
:stage, :start_date, :subscriptions_list, :sync_partner_teams, :tax_exempt, :tax_item, :taxable,
|
20
|
+
:sales_group, :sales_readiness, :sales_team_list, :salutation, :send_email, :ship_complete, :shipping_item,
|
21
|
+
:stage, :start_date, :subscriptions_list, :sync_partner_teams, :tax_exempt, :tax_item, :taxable,
|
22
22
|
:territory, :third_party_acct, :third_party_country, :third_party_zipcode, :title, :unbilled_orders, :url,
|
23
23
|
:vat_reg_number, :visits, :web_lead
|
24
24
|
].each do |field|
|
@@ -28,7 +28,7 @@ describe NetSuite::Records::Customer do
|
|
28
28
|
|
29
29
|
it 'has the right record_refs' do
|
30
30
|
[
|
31
|
-
:custom_form, :entity_status, :partner
|
31
|
+
:access_role, :currency, :custom_form, :entity_status, :partner, :sales_rep, :terms, :parent
|
32
32
|
].each do |record_ref|
|
33
33
|
expect(customer).to have_record_ref(record_ref)
|
34
34
|
end
|
@@ -0,0 +1,152 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe NetSuite::Records::Employee do
|
4
|
+
let(:employee) { NetSuite::Records::Employee.new }
|
5
|
+
|
6
|
+
it 'has all the right fields' do
|
7
|
+
[
|
8
|
+
:account_number, :alien_number, :approval_limit, :bill_pay, :birth_date,
|
9
|
+
:comments, :date_created, :direct_deposit, :eligible_for_commission,
|
10
|
+
:email, :employee_status, :employee_type, :entity_id, :expense_limit,
|
11
|
+
:fax, :first_name, :hire_date, :home_phone, :is_inactive, :is_job_resource,
|
12
|
+
:job_description, :labor_cost, :last_modified_date, :last_name, :middle_name,
|
13
|
+
:mobile_phone, :next_review_date, :office_phone, :pay_frequency, :phone,
|
14
|
+
:phonetic_name, :purchase_order_approval_limit, :purchase_order_approver,
|
15
|
+
:purchase_order_limit, :release_date, :resident_status, :salutation,
|
16
|
+
:social_security_number, :title, :visa_exp_date, :visa_type
|
17
|
+
].each do |field|
|
18
|
+
expect(employee).to have_field(field)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'has all the right record refs' do
|
23
|
+
[
|
24
|
+
:location
|
25
|
+
].each do |record_ref|
|
26
|
+
expect(employee).to have_record_ref(record_ref)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe '#roles_list' do
|
31
|
+
it 'can be set from attributes'
|
32
|
+
it 'can be set from a RoleList object'
|
33
|
+
end
|
34
|
+
|
35
|
+
describe '.get' do
|
36
|
+
context 'when the response is successful' do
|
37
|
+
let(:response) { NetSuite::Response.new(:success => true, :body => { :account_number => 7 }) }
|
38
|
+
|
39
|
+
it 'returns an Employee instance populated with the data from the response object' do
|
40
|
+
expect(NetSuite::Actions::Get).to receive(:call).with([NetSuite::Records::Employee, { :external_id => 1 }], {}).and_return(response)
|
41
|
+
employee = NetSuite::Records::Employee.get(:external_id => 1)
|
42
|
+
expect(employee).to be_kind_of(NetSuite::Records::Employee)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'when the response is unsuccessful' do
|
47
|
+
let(:response) { NetSuite::Response.new(:success => false, :body => {}) }
|
48
|
+
|
49
|
+
it 'raises a RecordNotFound exception' do
|
50
|
+
expect(NetSuite::Actions::Get).to receive(:call).with([NetSuite::Records::Employee, { :external_id => 1 }], {}).and_return(response)
|
51
|
+
expect {
|
52
|
+
NetSuite::Records::Employee.get(:external_id => 1)
|
53
|
+
}.to raise_error(NetSuite::RecordNotFound,
|
54
|
+
/NetSuite::Records::Employee with OPTIONS=(.*) could not be found/)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '#add' do
|
60
|
+
let(:employee) { NetSuite::Records::Employee.new(:email => 'dale.cooper@example.com') }
|
61
|
+
|
62
|
+
context 'when the response is successful' do
|
63
|
+
let(:response) { NetSuite::Response.new(:success => true, :body => { :internal_id => '1' }) }
|
64
|
+
|
65
|
+
it 'returns true' do
|
66
|
+
expect(NetSuite::Actions::Add).to receive(:call).
|
67
|
+
with([employee], {}).
|
68
|
+
and_return(response)
|
69
|
+
expect(employee.add).to be_truthy
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'when the response is unsuccessful' do
|
74
|
+
let(:response) { NetSuite::Response.new(:success => false, :body => {}) }
|
75
|
+
|
76
|
+
it 'returns false' do
|
77
|
+
expect(NetSuite::Actions::Add).to receive(:call).
|
78
|
+
with([employee], {}).
|
79
|
+
and_return(response)
|
80
|
+
expect(employee.add).to be_falsey
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe '#delete' do
|
86
|
+
context 'when the response is successful' do
|
87
|
+
let(:response) { NetSuite::Response.new(:success => true, :body => { :internal_id => '1' }) }
|
88
|
+
|
89
|
+
it 'returns true' do
|
90
|
+
expect(NetSuite::Actions::Delete).to receive(:call).
|
91
|
+
with([employee], {}).
|
92
|
+
and_return(response)
|
93
|
+
expect(employee.delete).to be_truthy
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
context 'when the response is unsuccessful' do
|
98
|
+
let(:response) { NetSuite::Response.new(:success => false, :body => {}) }
|
99
|
+
|
100
|
+
it 'returns false' do
|
101
|
+
expect(NetSuite::Actions::Delete).to receive(:call).
|
102
|
+
with([employee], {}).
|
103
|
+
and_return(response)
|
104
|
+
expect(employee.delete).to be_falsey
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
|
109
|
+
describe '.update' do
|
110
|
+
context 'when the response is successful' do
|
111
|
+
let(:response) { NetSuite::Response.new(:success => true, :body => { :email => 'leland.palmer@example.com' }) }
|
112
|
+
|
113
|
+
it 'returns true' do
|
114
|
+
expect(NetSuite::Actions::Update).to receive(:call).with([NetSuite::Records::Employee, { :internal_id => 1, :email => 'leland.palmer@example.com' }], {}).and_return(response)
|
115
|
+
employee = NetSuite::Records::Employee.new(:internal_id => 1)
|
116
|
+
expect(employee.update(:email => 'leland.palmer@example.com')).to be_truthy
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context 'when the response is unsuccessful' do
|
121
|
+
let(:response) { NetSuite::Response.new(:success => false, :body => {}) }
|
122
|
+
|
123
|
+
it 'raises a RecordNotFound exception' do
|
124
|
+
expect(NetSuite::Actions::Update).to receive(:call).with([NetSuite::Records::Employee, { :internal_id => 1, :account_number => 7 }], {}).and_return(response)
|
125
|
+
employee = NetSuite::Records::Employee.new(:internal_id => 1)
|
126
|
+
expect(employee.update(:account_number => 7)).to be_falsey
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe '#to_record' do
|
132
|
+
let(:employee) { NetSuite::Records::Employee.new(:email => 'bob@example.com') }
|
133
|
+
|
134
|
+
it 'returns a hash of attributes that can be used in a SOAP request' do
|
135
|
+
expect(employee.to_record).to eql({ 'listEmp:email' => 'bob@example.com' })
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
describe '#record_type' do
|
140
|
+
it 'returns a string type for the record to be used in a SOAP request' do
|
141
|
+
expect(employee.record_type).to eql('listEmp:Employee')
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'has the right record_refs' do
|
146
|
+
[
|
147
|
+
:currency, :department, :location, :subsidiary
|
148
|
+
].each do |record_ref|
|
149
|
+
expect(employee).to have_record_ref(record_ref)
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|