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

Action get_all return errors #423

Open
wants to merge 3 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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ test/tmp
test/version_tmp
tmp
vendor/
/.idea
18 changes: 17 additions & 1 deletion lib/netsuite/actions/get_all.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,33 @@ 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)
base.extend(ClassMethods)
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) }
Expand Down
67 changes: 67 additions & 0 deletions spec/netsuite/actions/get_all_spec.rb
Original file line number Diff line number Diff line change
@@ -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
83 changes: 83 additions & 0 deletions spec/support/fixtures/get_all/get_all_currencies.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?xml version="1.0" encoding="UTF-8"?>
<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_2018_1.platform.webservices.netsuite.com">
<platformMsgs:nsId>WEBSERVICES_TSTDRV1115270_010420194222336661788757021_365d42</platformMsgs:nsId>
</platformMsgs:documentInfo>
</soapenv:Header>
<soapenv:Body>
<getAllResponse xmlns="urn:messages_2018_1.platform.webservices.netsuite.com">
<platformCore:getAllResult xmlns:platformCore="urn:core_2018_1.platform.webservices.netsuite.com">
<platformCore:status isSuccess="true"/>
<platformCore:totalRecords>5</platformCore:totalRecords>
<platformCore:recordList>
<platformCore:record xmlns:listAcct="urn:accounting_2018_1.lists.webservices.netsuite.com" internalId="1" xsi:type="listAcct:Currency">
<listAcct:name>US Dollar</listAcct:name>
<listAcct:symbol>USD</listAcct:symbol>
<listAcct:isBaseCurrency>true</listAcct:isBaseCurrency>
<listAcct:isInactive>false</listAcct:isInactive>
<listAcct:overrideCurrencyFormat>false</listAcct:overrideCurrencyFormat>
<listAcct:displaySymbol>$</listAcct:displaySymbol>
<listAcct:symbolPlacement>_beforeNumber</listAcct:symbolPlacement>
<listAcct:locale>_unitedStatesEnglish</listAcct:locale>
<listAcct:formatSample>$1,234.56</listAcct:formatSample>
<listAcct:exchangeRate>1.0</listAcct:exchangeRate>
<listAcct:currencyPrecision>_two</listAcct:currencyPrecision>
</platformCore:record>
<platformCore:record xmlns:listAcct="urn:accounting_2018_1.lists.webservices.netsuite.com" internalId="2" xsi:type="listAcct:Currency">
<listAcct:name>British pound</listAcct:name>
<listAcct:symbol>GBP</listAcct:symbol>
<listAcct:isBaseCurrency>false</listAcct:isBaseCurrency>
<listAcct:isInactive>false</listAcct:isInactive>
<listAcct:overrideCurrencyFormat>false</listAcct:overrideCurrencyFormat>
<listAcct:displaySymbol>£</listAcct:displaySymbol>
<listAcct:symbolPlacement>_beforeNumber</listAcct:symbolPlacement>
<listAcct:locale>_unitedKingdomEnglish</listAcct:locale>
<listAcct:formatSample>£1,234.56</listAcct:formatSample>
<listAcct:exchangeRate>2.365</listAcct:exchangeRate>
<listAcct:currencyPrecision>_two</listAcct:currencyPrecision>
</platformCore:record>
<platformCore:record xmlns:listAcct="urn:accounting_2018_1.lists.webservices.netsuite.com" internalId="3" xsi:type="listAcct:Currency">
<listAcct:name>Canadian Dollar</listAcct:name>
<listAcct:symbol>CAD</listAcct:symbol>
<listAcct:isBaseCurrency>false</listAcct:isBaseCurrency>
<listAcct:isInactive>false</listAcct:isInactive>
<listAcct:overrideCurrencyFormat>false</listAcct:overrideCurrencyFormat>
<listAcct:displaySymbol>$</listAcct:displaySymbol>
<listAcct:symbolPlacement>_beforeNumber</listAcct:symbolPlacement>
<listAcct:locale>_canadaEnglish</listAcct:locale>
<listAcct:formatSample>$1,234.56</listAcct:formatSample>
<listAcct:exchangeRate>1.559</listAcct:exchangeRate>
<listAcct:currencyPrecision>_two</listAcct:currencyPrecision>
</platformCore:record>
<platformCore:record xmlns:listAcct="urn:accounting_2018_1.lists.webservices.netsuite.com" internalId="4" xsi:type="listAcct:Currency">
<listAcct:name>Euro</listAcct:name>
<listAcct:symbol>EUR</listAcct:symbol>
<listAcct:isBaseCurrency>false</listAcct:isBaseCurrency>
<listAcct:isInactive>false</listAcct:isInactive>
<listAcct:overrideCurrencyFormat>false</listAcct:overrideCurrencyFormat>
<listAcct:displaySymbol>€</listAcct:displaySymbol>
<listAcct:symbolPlacement>_beforeNumber</listAcct:symbolPlacement>
<listAcct:locale>_franceFrenchEuro</listAcct:locale>
<listAcct:formatSample>€1 234,56</listAcct:formatSample>
<listAcct:exchangeRate>1.509</listAcct:exchangeRate>
<listAcct:currencyPrecision>_two</listAcct:currencyPrecision>
</platformCore:record>
<platformCore:record xmlns:listAcct="urn:accounting_2018_1.lists.webservices.netsuite.com" internalId="5" xsi:type="listAcct:Currency">
<listAcct:name>Polish Zloty</listAcct:name>
<listAcct:symbol>PLN</listAcct:symbol>
<listAcct:isBaseCurrency>true</listAcct:isBaseCurrency>
<listAcct:isInactive>false</listAcct:isInactive>
<listAcct:overrideCurrencyFormat>false</listAcct:overrideCurrencyFormat>
<listAcct:displaySymbol>zł</listAcct:displaySymbol>
<listAcct:symbolPlacement>_beforeNumber</listAcct:symbolPlacement>
<listAcct:locale>_polandPolish</listAcct:locale>
<listAcct:formatSample>zł1 234,56</listAcct:formatSample>
<listAcct:exchangeRate>0.27</listAcct:exchangeRate>
<listAcct:currencyPrecision>_two</listAcct:currencyPrecision>
</platformCore:record>
</platformCore:recordList>
</platformCore:getAllResult>
</getAllResponse>
</soapenv:Body>
</soapenv:Envelope>
21 changes: 21 additions & 0 deletions spec/support/fixtures/get_all/get_all_insufficient_permissions.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<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_2018_1.platform.webservices.netsuite.com">
<platformMsgs:nsId>WEBSERVICES_TSTDRV1115270_01042019421775958535724851_3779906</platformMsgs:nsId>
</platformMsgs:documentInfo>
</soapenv:Header>
<soapenv:Body>
<getAllResponse xmlns="urn:messages_2018_1.platform.webservices.netsuite.com">
<platformCore:getAllResult xmlns:platformCore="urn:core_2018_1.platform.webservices.netsuite.com">
<platformCore:status isSuccess="false">
<platformCore:statusDetail type="ERROR">
<platformCore:code>INSUFFICIENT_PERMISSION</platformCore:code>
<platformCore:message>Permission Violation: You need the 'Lists -&gt; Currency' permission to access this page. Please contact your account administrator.</platformCore:message>
</platformCore:statusDetail>
</platformCore:status>
<platformCore:totalRecords>5</platformCore:totalRecords>
</platformCore:getAllResult>
</getAllResponse>
</soapenv:Body>
</soapenv:Envelope>