Skip to content

Commit

Permalink
Raise an error for .get when passing the wrong argument
Browse files Browse the repository at this point in the history
  • Loading branch information
harrylewis committed Mar 8, 2024
1 parent 7dd7b1c commit 4443230
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 3 deletions.
2 changes: 2 additions & 0 deletions lib/bambora/v1/reports/merchants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class Merchants
def self.get(merchant_id, options = {})
credentials = options[:credentials]

raise ArgumentError, "#{self}.get takes a string argument" unless merchant_id.is_a?(Integer)

response =
Bambora::Rest::JSONClient
.new(base_url: 'https://api.na.bambora.com', merchant_id: credentials.merchant_id)
Expand Down
84 changes: 81 additions & 3 deletions spec/bambora/v1/reports/merchants_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,85 @@

RSpec.describe Bambora::V1::Reports::Merchants do
describe '.get' do
context 'when the API request is not authenticated' do
context 'when passing nil' do
it 'raises ArgumentError' do
credentials = Bambora::Credentials.new(
merchant_id: '372110000',
reporting_passcode: '28840CEB9H9D3DFC24A445B7461FD8FG',
)

expect { described_class.get(nil, credentials: credentials) }.to(
raise_error(ArgumentError),
)
end
end

context 'when passing a boolean' do
it 'raises ArgumentError' do
credentials = Bambora::Credentials.new(
merchant_id: '372110000',
reporting_passcode: '28840CEB9H9D3DFC24A445B7461FD8FG',
)

expect { described_class.get(true, credentials: credentials) }.to(
raise_error(ArgumentError),
)
end
end

context 'when passing a symbol' do
it 'raises ArgumentError' do
credentials = Bambora::Credentials.new(
merchant_id: '372110000',
reporting_passcode: '28840CEB9H9D3DFC24A445B7461FD8FG',
)

expect { described_class.get(:symbol, credentials: credentials) }.to(
raise_error(ArgumentError),
)
end
end

context 'when passing a number (float)' do
it 'raises ArgumentError' do
credentials = Bambora::Credentials.new(
merchant_id: '372110000',
reporting_passcode: '28840CEB9H9D3DFC24A445B7461FD8FG',
)

expect { described_class.get(1.0, credentials: credentials) }.to(
raise_error(ArgumentError),
)
end
end

context 'when passing an array' do
it 'raises ArgumentError' do
credentials = Bambora::Credentials.new(
merchant_id: '372110000',
reporting_passcode: '28840CEB9H9D3DFC24A445B7461FD8FG',
)

expect { described_class.get([], credentials: credentials) }.to(
raise_error(ArgumentError),
)
end
end

context 'when passing a hash' do
it 'raises ArgumentError' do
credentials = Bambora::Credentials.new(
merchant_id: '372110000',
reporting_passcode: '28840CEB9H9D3DFC24A445B7461FD8FG',
)

expect { described_class.get({}, credentials: credentials) }.to(
raise_error(ArgumentError),
)
end
end

context 'when passing a number (integer), but the API request is not authenticated' do
it 'raises Bambora::InvalidAuthenticationError' do
WebMock
.stub_request(:get, 'https://api.na.bambora.com/v1/reports/merchants/372110001')
Expand Down Expand Up @@ -34,7 +112,7 @@
end
end

context 'when the API request is invalid' do
context 'when passing a number (integer), but the API request is invalid' do
it 'raises Bambora::InvalidRequestError' do
WebMock
.stub_request(:get, 'https://api.na.bambora.com/v1/reports/merchants/372110001')
Expand Down Expand Up @@ -64,7 +142,7 @@
end
end

context 'when the API request is authenticated and valid' do
context 'when passing a number (integer), the API request is authenticated and valid' do
it 'returns merchant data for the merchant' do
WebMock
.stub_request(:get, 'https://api.na.bambora.com/v1/reports/merchants/372110001')
Expand Down

0 comments on commit 4443230

Please sign in to comment.