diff --git a/lib/netsuite/records/item_availability.rb b/lib/netsuite/records/item_availability.rb index ea9cb542f..7d292e6e5 100644 --- a/lib/netsuite/records/item_availability.rb +++ b/lib/netsuite/records/item_availability.rb @@ -30,9 +30,12 @@ def self.get_item_availability(ref_list, credentials={}) return false end if result[:item_availability_list] - result[:item_availability_list][:item_availability].map do |row| - NetSuite::Records::ItemAvailability.new(row) + rows = result[:item_availability_list][:item_availability] + unless rows.respond_to?(:to_ary) + rows = [rows] end + + rows.map{|row| NetSuite::Records::ItemAvailability.new(row) } else [] end diff --git a/spec/netsuite/records/item_availability_spec.rb b/spec/netsuite/records/item_availability_spec.rb index d91beecec..ccfdb9325 100644 --- a/spec/netsuite/records/item_availability_spec.rb +++ b/spec/netsuite/records/item_availability_spec.rb @@ -32,28 +32,46 @@ } let(:result) { NetSuite::Records::ItemAvailability.get_item_availability(inventory_item_ref_list) } - before do - savon.expects(:get_item_availability).with(:message => { - "platformMsgs:itemAvailabilityFilter" => { - "platformCore:item"=>{"platformCore:recordRef"=>[{:@internalId=>57}]} - } - }).returns(File.read('spec/support/fixtures/get_item_availability/get_item_availability.xml')) + context 'with two results' do + before do + savon.expects(:get_item_availability).with(:message => { + "platformMsgs:itemAvailabilityFilter" => { + "platformCore:item"=>{"platformCore:recordRef"=>[{:@internalId=>57}]} + } + }).returns(File.read('spec/support/fixtures/get_item_availability/get_item_availability.xml')) + end + + it 'returns ItemAvailability records' do + expect(result).to be_kind_of(Array) + expect(result).not_to be_empty + expect(result[0]).to be_kind_of(NetSuite::Records::ItemAvailability) + expect(result[0]).to have_attributes( + item: be_kind_of(NetSuite::Records::InventoryItem), + location_id: NetSuite::Records::Location, + quantity_on_hand: '264.0', + on_hand_value_mli: '129.36', + reorder_point: '50.0', + quantity_on_order: '0.0', + quantity_committed: '0.0', + quantity_available: '264.0', + ) + end end - it 'returns ItemAvailability records' do - expect(result).to be_kind_of(Array) - expect(result).not_to be_empty - expect(result[0]).to be_kind_of(NetSuite::Records::ItemAvailability) - expect(result[0]).to have_attributes( - item: be_kind_of(NetSuite::Records::InventoryItem), - location_id: NetSuite::Records::Location, - quantity_on_hand: '264.0', - on_hand_value_mli: '129.36', - reorder_point: '50.0', - quantity_on_order: '0.0', - quantity_committed: '0.0', - quantity_available: '264.0', - ) + context 'single result' do + before do + savon.expects(:get_item_availability).with(:message => { + "platformMsgs:itemAvailabilityFilter" => { + "platformCore:item"=>{"platformCore:recordRef"=>[{:@internalId=>57}]} + } + }).returns(File.read('spec/support/fixtures/get_item_availability/get_item_availability_single_result.xml')) + end + + it 'returns ItemAvailability records' do + expect(result).to be_kind_of(Array) + expect(result.length).to eq(1) + expect(result[0]).to be_kind_of(NetSuite::Records::ItemAvailability) + end end end end diff --git a/spec/support/fixtures/get_item_availability/get_item_availability_single_result.xml b/spec/support/fixtures/get_item_availability/get_item_availability_single_result.xml new file mode 100644 index 000000000..97bf8d8ac --- /dev/null +++ b/spec/support/fixtures/get_item_availability/get_item_availability_single_result.xml @@ -0,0 +1,31 @@ + + + + WEBSERVICES_3868171_122020162073815481885806769_24761121647f + + + + + + + + + + CD-R + + 2020-04-27T08:38:20.000-07:00 + + Warehouse - West Coast + + -1.0 + 0.0 + 50.0 + 0.0 + 0.0 + 0.0 + + + + + +