Skip to content

Commit

Permalink
Tests for mutating records inside AddList
Browse files Browse the repository at this point in the history
  • Loading branch information
aom committed Mar 8, 2019
1 parent 68400c0 commit a366534
Showing 1 changed file with 69 additions and 0 deletions.
69 changes: 69 additions & 0 deletions spec/netsuite/actions/add_list_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,19 @@
expect(response).to be_kind_of(NetSuite::Response)
expect(response).to be_success
end

it 'returns array of records when called as Record static method' do
records = NetSuite::Records::Customer.add_list(customers)
records.each do |record|
expect(record).to be_instance_of(NetSuite::Records::Customer)
expect(record.internal_id).not_to be nil
end
end

it 'mutates records with internal_id when called as Record static method' do
NetSuite::Records::Customer.add_list(customers)
expect(customers[0].internal_id).to eq "974"
end
end

context 'two customers' do
Expand Down Expand Up @@ -71,6 +84,62 @@
expect(response).to be_kind_of(NetSuite::Response)
expect(response).to be_success
end

it 'returns array of records when called as Record static method' do
records = NetSuite::Records::Customer.add_list(customers)
records.each do |record|
expect(record).to be_instance_of(NetSuite::Records::Customer)
expect(record.internal_id).not_to be nil
end
end

it 'mutates records with internal_id when called as Record static method' do
NetSuite::Records::Customer.add_list(customers)
expect(customers[0].internal_id).to eq "970"
expect(customers[1].internal_id).to eq "974"
end
end

context 'one customer without external id' do
let(:customers) do
[
NetSuite::Records::Customer.new(entity_id: 'Target', company_name: 'Target')
]
end

before do
savon.expects(:add_list).with(:message =>
{
'record' => [{
'listRel:entityId' => 'Target',
'listRel:companyName' => 'Target',
'@xsi:type' => 'listRel:Customer'
}]
}).returns(File.read('spec/support/fixtures/add_list/add_list_one_customer_without_external_id.xml'))
end

it 'makes a valid request to the NetSuite API' do
NetSuite::Actions::AddList.call(customers)
end

it 'returns a valid Response object' do
response = NetSuite::Actions::AddList.call(customers)
expect(response).to be_kind_of(NetSuite::Response)
expect(response).to be_success
end

it 'returns array of records when called as Record static method' do
records = NetSuite::Records::Customer.add_list(customers)
records.each do |record|
expect(record).to be_instance_of(NetSuite::Records::Customer)
expect(record.internal_id).to be nil
end
end

it 'does not mutate records if external_id was not used' do
NetSuite::Records::Customer.add_list(customers)
expect(customers.first.internal_id).to be nil
end
end
end

Expand Down

0 comments on commit a366534

Please sign in to comment.