diff --git a/lib/bambora/v1/reports/merchants.rb b/lib/bambora/v1/reports/merchants.rb index f313deb..b7626ee 100644 --- a/lib/bambora/v1/reports/merchants.rb +++ b/lib/bambora/v1/reports/merchants.rb @@ -16,6 +16,8 @@ def self.get(merchant_id, options = {}) raise InvalidAuthenticationError, response end + raise InvalidRequestError, response if response == { Message: 'The request is invalid.' } + response end diff --git a/spec/bambora/v1/reports/merchants_spec.rb b/spec/bambora/v1/reports/merchants_spec.rb index b70658a..1cdead8 100644 --- a/spec/bambora/v1/reports/merchants_spec.rb +++ b/spec/bambora/v1/reports/merchants_spec.rb @@ -34,7 +34,37 @@ end end - context 'when the API request is authenticated' do + context 'when the API request is invalid' do + it 'raises Bambora::InvalidRequestError' do + WebMock + .stub_request(:get, 'https://api.na.bambora.com/v1/reports/merchants/372110001') + .with( + headers: { + 'Authorization' => 'Passcode MzcyMTEwMDAwOjI4ODQwQ0VCOUg5RDNERkMyNEE0NDVCNzQ2MUZEOEZH', + 'Content-Type' => 'application/json', + }, + ) + .to_return( + headers: { + 'Content-Type' => 'application/json', + }, + body: { + Message: 'The request is invalid.', + }.to_json, + ) + + credentials = Bambora::Credentials.new( + merchant_id: '372110000', + reporting_passcode: '28840CEB9H9D3DFC24A445B7461FD8FG', + ) + + expect { described_class.get(372_110_001, credentials: credentials) }.to( + raise_error(Bambora::InvalidRequestError), + ) + end + end + + context 'when 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')