diff --git a/.gitignore b/.gitignore
index 2c5ef592f..ffd824377 100644
--- a/.gitignore
+++ b/.gitignore
@@ -16,3 +16,4 @@ test/tmp
test/version_tmp
tmp
vendor/
+/.idea
diff --git a/lib/netsuite/actions/get_all.rb b/lib/netsuite/actions/get_all.rb
index dddf32dbd..6aad74c1c 100644
--- a/lib/netsuite/actions/get_all.rb
+++ b/lib/netsuite/actions/get_all.rb
@@ -49,6 +49,20 @@ def response_hash
@response_hash ||= @response.body[:get_all_response][:get_all_result]
end
+ def response_errors
+ if response_hash.dig(:status, :status_detail)
+ @response_errors ||= errors
+ end
+ end
+
+ def errors
+ error_obj = response_hash[:status][:status_detail]
+ error_obj = [error_obj] if error_obj.class == Hash
+ error_obj.map do |error|
+ NetSuite::Error.new(error)
+ end
+ end
+
module Support
def self.included(base)
@@ -56,10 +70,12 @@ def self.included(base)
end
module ClassMethods
+ attr_reader :errors
+
def get_all(credentials = {})
response = NetSuite::Actions::GetAll.call([self], credentials)
- # TODO expose errors to the user
+ @errors = response.errors
if response.success?
response.body.map { |attr| new(attr) }
diff --git a/spec/netsuite/actions/get_all_spec.rb b/spec/netsuite/actions/get_all_spec.rb
new file mode 100644
index 000000000..efcf6e422
--- /dev/null
+++ b/spec/netsuite/actions/get_all_spec.rb
@@ -0,0 +1,67 @@
+require 'spec_helper'
+
+describe NetSuite::Actions::GetAll do
+ before(:all) { savon.mock! }
+ after(:all) { savon.unmock! }
+
+ describe 'Currency' do
+ context 'retrieving all' do
+ let(:message) { { record: [ { record_type: "currency" } ] } }
+ let(:currency) { NetSuite::Records::Currency }
+ let(:response) { currency.get_all({}) }
+
+ context 'when successful' do
+ before do
+ savon.expects(:get_all).with(message: message).returns(
+ File.read('spec/support/fixtures/get_all/get_all_currencies.xml')
+ )
+ end
+
+ it 'makes a valid request to the NetSuite API' do
+ NetSuite::Actions::GetAll.call([NetSuite::Records::Currency])
+ end
+
+ it 'returns a valid Response object' do
+ response = NetSuite::Actions::GetAll.call([NetSuite::Records::Currency])
+ expect(response).to be_kind_of(NetSuite::Response)
+ end
+
+ it 'returns valid currency list' do
+ expect(response).to be_kind_of(Array)
+ expect(response.count).to eq(5)
+
+ usd = response.first
+ expect(usd).to be_kind_of(NetSuite::Records::Currency)
+ expect(usd.attributes[:name]).to eq('US Dollar')
+ end
+ end
+
+ context 'when insufficient permissions' do
+ before do
+ savon.expects(:get_all).with(message: message).returns(
+ File.read('spec/support/fixtures/get_all/get_all_insufficient_permissions.xml')
+ )
+ end
+
+ it 'provides an error method on the object with details about the error' do
+ response
+ error = currency.errors.first
+
+ expect(error).to be_kind_of(NetSuite::Error)
+ expect(error.type).to eq('ERROR')
+ expect(error.code).to eq('INSUFFICIENT_PERMISSION')
+ expect(error.message).to eq(
+ "Permission Violation: You need the 'Lists -> Currency' permission to access this page. Please contact your account administrator."
+ )
+ end
+
+ it 'provides an error method on the response' do
+ response
+
+ expect(currency.errors.first).to be_kind_of(NetSuite::Error)
+ expect(response).to eq(false)
+ end
+ end
+ end
+ end
+end
diff --git a/spec/support/fixtures/get_all/get_all_currencies.xml b/spec/support/fixtures/get_all/get_all_currencies.xml
new file mode 100644
index 000000000..e013ff53f
--- /dev/null
+++ b/spec/support/fixtures/get_all/get_all_currencies.xml
@@ -0,0 +1,83 @@
+
+
+
+
+ WEBSERVICES_TSTDRV1115270_010420194222336661788757021_365d42
+
+
+
+
+
+
+ 5
+
+
+ US Dollar
+ USD
+ true
+ false
+ false
+ $
+ _beforeNumber
+ _unitedStatesEnglish
+ $1,234.56
+ 1.0
+ _two
+
+
+ British pound
+ GBP
+ false
+ false
+ false
+ £
+ _beforeNumber
+ _unitedKingdomEnglish
+ £1,234.56
+ 2.365
+ _two
+
+
+ Canadian Dollar
+ CAD
+ false
+ false
+ false
+ $
+ _beforeNumber
+ _canadaEnglish
+ $1,234.56
+ 1.559
+ _two
+
+
+ Euro
+ EUR
+ false
+ false
+ false
+ €
+ _beforeNumber
+ _franceFrenchEuro
+ €1 234,56
+ 1.509
+ _two
+
+
+ Polish Zloty
+ PLN
+ true
+ false
+ false
+ zł
+ _beforeNumber
+ _polandPolish
+ zł1 234,56
+ 0.27
+ _two
+
+
+
+
+
+
diff --git a/spec/support/fixtures/get_all/get_all_insufficient_permissions.xml b/spec/support/fixtures/get_all/get_all_insufficient_permissions.xml
new file mode 100644
index 000000000..efb3c7456
--- /dev/null
+++ b/spec/support/fixtures/get_all/get_all_insufficient_permissions.xml
@@ -0,0 +1,21 @@
+
+
+
+
+ WEBSERVICES_TSTDRV1115270_01042019421775958535724851_3779906
+
+
+
+
+
+
+
+ INSUFFICIENT_PERMISSION
+ Permission Violation: You need the 'Lists -> Currency' permission to access this page. Please contact your account administrator.
+
+
+ 5
+
+
+
+