diff --git a/lib/netsuite/actions/add.rb b/lib/netsuite/actions/add.rb index 4cc352661..8acc99e86 100644 --- a/lib/netsuite/actions/add.rb +++ b/lib/netsuite/actions/add.rb @@ -49,7 +49,11 @@ def success? end def response_body - @response_body ||= response_hash[:base_ref] + @response_body ||= if response_hash[:base_ref].is_a?(Nori::StringIOFile) + { :@internal_id => Nokogiri::XML(@response.to_s).remove_namespaces!.at_xpath('//baseRef')[:internalId] } + else + response_hash[:base_ref] + end end def response_errors diff --git a/spec/netsuite/actions/add_spec.rb b/spec/netsuite/actions/add_spec.rb index c55403c28..2be80d272 100644 --- a/spec/netsuite/actions/add_spec.rb +++ b/spec/netsuite/actions/add_spec.rb @@ -114,4 +114,40 @@ end end + context 'File' do + let(:file) do + NetSuite::Records::File.new(name: 'foo.pdf', content: 'abc123') + end + + context 'when successful' do + before do + savon.expects(:add).with(:message => { + 'platformMsgs:record' => { + :content! => { + 'fileCabinet:name' => 'foo.pdf', + 'fileCabinet:content' => 'abc123', + }, + '@xsi:type' => 'fileCabinet:File' + }, + }).returns(File.read('spec/support/fixtures/add/add_file.xml')) + end + + it 'makes a valid request to the NetSuite API' do + NetSuite::Actions::Add.call([file]) + end + + it 'returns a valid Response object' do + response = NetSuite::Actions::Add.call([file]) + expect(response).to be_kind_of(NetSuite::Response) + expect(response).to be_success + end + + it 'properly extracts internal ID from response' do + file.add + + expect(file.internal_id).to eq('23556') + end + end + end + end diff --git a/spec/support/fixtures/add/add_file.xml b/spec/support/fixtures/add/add_file.xml new file mode 100644 index 000000000..99c9962b5 --- /dev/null +++ b/spec/support/fixtures/add/add_file.xml @@ -0,0 +1,20 @@ + + + + + REDACTED + + + + + + + + false + + + + + + +