Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle single result in get_item_availability #614

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions lib/netsuite/records/item_availability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,13 @@ 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)
# TODO: switch to Array.wrap when support for Ruby < 3.0 is dropped
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
Expand Down
58 changes: 38 additions & 20 deletions spec/netsuite/records/item_availability_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
<platformMsgs:documentInfo xmlns:platformMsgs="urn:messages_2016_2.platform.webservices.netsuite.com">
<platformMsgs:nsId>WEBSERVICES_3868171_122020162073815481885806769_24761121647f</platformMsgs:nsId>
</platformMsgs:documentInfo>
</soapenv:Header>
<soapenv:Body>
<getItemAvailabilityResponse xmlns="urn:messages_2016_2.platform.webservices.netsuite.com">
<platformCore:getItemAvailabilityResult xmlns:platformCore="urn:core_2016_2.platform.webservices.netsuite.com">
<platformCore:status isSuccess="true"/>
<platformCore:itemAvailabilityList>
<platformCore:itemAvailability>
<platformCore:item internalId="57" type="inventoryItem">
<platformCore:name>CD-R</platformCore:name>
</platformCore:item>
<platformCore:lastQtyAvailableChange>2020-04-27T08:38:20.000-07:00</platformCore:lastQtyAvailableChange>
<platformCore:locationId internalId="2" type="location">
<platformCore:name>Warehouse - West Coast</platformCore:name>
</platformCore:locationId>
<platformCore:quantityOnHand>-1.0</platformCore:quantityOnHand>
<platformCore:onHandValueMli>0.0</platformCore:onHandValueMli>
<platformCore:reorderPoint>50.0</platformCore:reorderPoint>
<platformCore:quantityOnOrder>0.0</platformCore:quantityOnOrder>
<platformCore:quantityCommitted>0.0</platformCore:quantityCommitted>
<platformCore:quantityAvailable>0.0</platformCore:quantityAvailable>
</platformCore:itemAvailability>
</platformCore:itemAvailabilityList>
</platformCore:getItemAvailabilityResult>
</getItemAvailabilityResponse>
</soapenv:Body>
</soapenv:Envelope>
Loading