Skip to content

Commit

Permalink
dont crash if suitetalk returns empty <platformCore:searchRowList/> (#…
Browse files Browse the repository at this point in the history
…574)

* dont crash if suitetalk returns empty <platformCore:searchRowList/>

* test for empty search_row_list as well
  • Loading branch information
ericcj committed Mar 26, 2023
1 parent 33a5659 commit a220f69
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/netsuite/support/search_result.rb
Expand Up @@ -48,7 +48,8 @@ def initialize(response, result_class, credentials)
end
elsif response.body.has_key? :search_row_list
# advanced search results
record_list = response.body[:search_row_list][:search_row]
record_list = response.body[:search_row_list]
record_list = record_list ? record_list[:search_row] : []
record_list = [record_list] unless record_list.is_a?(Array)

record_list.each do |record|
Expand Down
17 changes: 17 additions & 0 deletions spec/netsuite/support/search_result_spec.rb
Expand Up @@ -22,6 +22,23 @@
results = described_class.new(response, NetSuite::Actions::Search, {}).results
expect(results).to eq []
end

it 'returns empty search_row_list' do
response_body = {
:status => {:@is_success=>"true"},
:total_records => "242258",
:page_size => "10",
:total_pages => "24226",
:page_index => "99",
:search_id => "WEBSERVICES_4132604_SB1_051620191060155623420663266_336cbf12",
:search_row_list => nil,
:"@xmlns:platform_core" => "urn:core_2016_2.platform.webservices.netsuite.com"
}
response = NetSuite::Response.new(body: response_body)

results = described_class.new(response, NetSuite::Actions::Search, {}).results
expect(results).to eq []
end
end

it 'handles a recordList with a single element' do
Expand Down

0 comments on commit a220f69

Please sign in to comment.