Sha256: 2f757680e231bada3708d2323112f6c2ce04b88c0b3823367ad5a828a489ca35

Contents?: true

Size: 1.87 KB

Versions: 6

Compression:

Stored size: 1.87 KB

Contents

require 'spec_helper'

describe NetSuite::Actions::AttachFile do
  before(:all) { savon.mock! }
  after(:all) { savon.unmock! }

  let(:sales_order) { NetSuite::Records::SalesOrder.new(internal_id: 999) }
  let(:file) {  double('file', internal_id: 111) }
  let(:message) do
    {
      'platformCore:attachReference' => {
        '@xsi:type' => 'platformCore:AttachBasicReference',
        'platformCore:attachTo' => {
          '@internalId' => sales_order.internal_id,
          '@type' => 'salesOrder',
          '@xsi:type' => 'platformCore:RecordRef'
        },
        'platformCore:attachedRecord' => {
          '@internalId' => file.internal_id,
          '@type' => 'file',
          '@xsi:type' => 'platformCore:RecordRef'
        }
      }
    }
  end

  before do
    savon.expects(:attach).with(:message => message).returns(envelope)
  end

  context 'when successful' do
    let(:envelope) { File.read('spec/support/fixtures/attach/attach_file_to_sales_order.xml') }

    it 'returns a valid Response object' do
      response = NetSuite::Actions::AttachFile.call([sales_order, file])
      expect(response).to be_kind_of(NetSuite::Response)
      expect(response).to be_success
    end
  end

  context 'when not successful' do
    let(:envelope) { File.read('spec/support/fixtures/attach/attach_file_to_sales_order_error.xml') }

    it 'provides an error method on the object with details about the error' do
      sales_order.attach_file(file)
      error = sales_order.errors.first

      expect(error).to be_kind_of(NetSuite::Error)
      expect(error.type).to eq('ERROR')
      expect(error.code).to eq('INVALID')
      expect(error.message).to eq('Invalid request.')
    end

    it 'provides an error method on the response' do
      response = NetSuite::Actions::AttachFile.call([sales_order, file])
      expect(response.errors.first).to be_kind_of(NetSuite::Error)
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
netsuite-0.9.3 spec/netsuite/actions/attach_file_spec.rb
netsuite-0.9.2 spec/netsuite/actions/attach_file_spec.rb
netsuite-0.9.1 spec/netsuite/actions/attach_file_spec.rb
netsuite-0.9.0 spec/netsuite/actions/attach_file_spec.rb
netsuite-0.8.12 spec/netsuite/actions/attach_file_spec.rb
netsuite-0.8.11 spec/netsuite/actions/attach_file_spec.rb