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

Enable endpoint as a configuration option to bypass NS WSDL issues #473

Merged
merged 2 commits into from
Mar 4, 2021
Merged
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
13 changes: 13 additions & 0 deletions lib/netsuite/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def attributes
def connection(params={}, credentials={})
client = Savon.client({
wsdl: cached_wsdl || wsdl,
endpoint: endpoint,
read_timeout: read_timeout,
open_timeout: open_timeout,
namespaces: namespaces,
Expand Down Expand Up @@ -94,6 +95,18 @@ def api_version=(version)
attributes[:api_version] = version
end

def endpoint=(endpoint)
attributes[:endpoint] = endpoint
end

def endpoint(endpoint=nil)
if endpoint
self.endpoint = endpoint
else
attributes[:endpoint]
end
end

def sandbox=(flag)
if attributes[:sandbox] != flag
attributes[:wsdl] = nil
Expand Down
32 changes: 32 additions & 0 deletions spec/netsuite/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,12 @@
end

describe '#connection' do
EXAMPLE_ENDPOINT = 'https://1023.suitetalk.api.netsuite.com/services/NetSuitePort_2020_2'
before(:each) do
# reset clears out the password info
config.email 'me@example.com'
config.password 'me@example.com'
config.endpoint EXAMPLE_ENDPOINT
config.account 1023
config.wsdl "my_wsdl"
config.api_version "2012_2"
Expand All @@ -57,6 +59,19 @@

expect(config).to have_received(:cached_wsdl)
end

it 'sets the endpoint on the Savon client' do
# this is ugly/brittle, but it's hard to see how else to test this
savon_configs = config.connection.globals.instance_eval {@options}
expect(savon_configs.fetch(:endpoint)).to eq(EXAMPLE_ENDPOINT)
end

it 'handles a nil endpoint' do
config.endpoint = nil
# this is ugly/brittle, but it's hard to see how else to test this
savon_configs = config.connection.globals.instance_eval {@options}
expect(savon_configs.fetch(:endpoint)).to eq(nil)
end
end

describe '#wsdl' do
Expand Down Expand Up @@ -166,6 +181,23 @@
end
end

describe '#endpoint' do
it 'can be set with endpoint=' do
config.endpoint = 42
expect(config.endpoint).to eq(42)
end

it 'can be set with just endpoint(value)' do
config.endpoint(42)
expect(config.endpoint).to eq(42)
end

it 'supports nil endpoints' do
config.endpoint = nil
expect(config.endpoint).to eq(nil)
end
end

describe '#auth_header' do
context 'when doing user authentication' do
before do
Expand Down