Skip to content

Commit

Permalink
Bugfix: Handle null record from Bambora Batch Bank Report queries (#35)
Browse files Browse the repository at this point in the history
* Bugfix: Handle null record from Bambora Batch Bank Report queries

* Simplify guard method and update help message
  • Loading branch information
erawk authored Apr 14, 2020
1 parent f8927b1 commit f0a2ae5
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 0.1.2 (2020-04-14)

- Fix nil record with Bank Batch Report returns

## 0.1.1 (2020-03-04)

- Upgrade `rake` to `13.0.1`
Expand Down
8 changes: 4 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
bambora-client (0.1.0)
bambora-client (0.1.2)
excon (< 1.0)
faraday (< 1.0)
gyoku (~> 1.0)
Expand All @@ -19,15 +19,15 @@ GEM
crack (0.4.3)
safe_yaml (~> 1.0.0)
diff-lcs (1.3)
excon (0.71.0)
faraday (0.17.1)
excon (0.73.0)
faraday (0.17.3)
multipart-post (>= 1.2, < 3)
gyoku (1.3.1)
builder (>= 2.1.2)
hashdiff (1.0.0)
jaro_winkler (1.5.3)
method_source (0.9.2)
mime-types (3.3)
mime-types (3.3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2019.1009)
multipart-post (2.1.1)
Expand Down
4 changes: 4 additions & 0 deletions lib/bambora/bank/batch_report_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,13 @@ def show(report_data)
private

def add_messages_to_response(response)
# bambora can return null or empty record results, don't decorate with messages
return response if response.dig(:response, :record).nil?

response.dig(:response, :record).map! do |record|
record.merge!(messages: record[:messageId].split(',').map { |id| MESSAGES[id] })
end

response
end

Expand Down
2 changes: 1 addition & 1 deletion lib/bambora/client/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

module Bambora
class Client
VERSION = '0.1.1'
VERSION = '0.1.2'
end
end
32 changes: 32 additions & 0 deletions spec/bambora/bank/batch_report_resource_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,38 @@ module Bank
expect(reports.show(request_data)).to eq expected_response
end
end

context 'with nil records' do
let(:response_body) do
{
response: {
version: '1.0',
code: 1,
message: 'Report generated',
records: {
total: 0,
},
},
}
end

let(:expected_response) do
{
response: {
version: '1.0',
code: 1,
message: 'Report generated',
records: {
total: 0,
},
},
}
end

it 'returns the expected response' do
expect(reports.show(request_data)).to eq expected_response
end
end
end
end
end
Expand Down

0 comments on commit f0a2ae5

Please sign in to comment.