diff --git a/spec/netsuite/actions/add_list_spec.rb b/spec/netsuite/actions/add_list_spec.rb index a6dc65ce7..722361a28 100644 --- a/spec/netsuite/actions/add_list_spec.rb +++ b/spec/netsuite/actions/add_list_spec.rb @@ -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 @@ -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