Skip to content

Commit

Permalink
Raise error for invalid request
Browse files Browse the repository at this point in the history
  • Loading branch information
harrylewis committed Mar 8, 2024
1 parent 03b1f5c commit 76c488c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/bambora/v1/reports/merchants.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
32 changes: 31 additions & 1 deletion spec/bambora/v1/reports/merchants_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit 76c488c

Please sign in to comment.