Skip to content

Commit

Permalink
Merge pull request #62 from customink/drinks/bugfix-total_tax
Browse files Browse the repository at this point in the history
[Bug] Quotation Fallback Response raises ArgumentError when line items are empty
  • Loading branch information
drinks authored Jul 7, 2020
2 parents 2b288be + 31c9813 commit 96edb96
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@

This file tracks all the changes (https://keepachangelog.com/en/1.0.0/) made to the client. This allows parsers such as Dependabot to provide a clean overview in pull requests.

## [v0.9.2] - 2020-07-06
## [v0.9.2] - 2020-07-07

#### Added

- Quotation, Invoice and DistributeTax payloads now accept a `:tax_only_adjustment` param to make tax adjustments that need not be correlated with a total cost adjustment

#### Changed

- Fix a bug with fallback quotation responses where an empty set of line items would raise `ArgumentError`

## [v0.9.1] - 2020-03-24

#### Added
Expand Down
2 changes: 1 addition & 1 deletion lib/vertex_client/responses/quotation_fallback.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def subtotal
end

def total_tax
@total_tax ||= line_items.sum(&:total_tax).round(2, :half_even)
@total_tax ||= line_items.sum(&:total_tax).to_d.round(2, :half_even)
end

def total
Expand Down
10 changes: 10 additions & 0 deletions test/responses/quotation_fallback_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,23 @@
it 'is the sum of price from line_items' do
assert_equal 135.5, response.subtotal.to_f
end

it 'handles empty quotes' do
working_quote_params[:line_items] = []
assert_equal 0.0, response.subtotal.to_f
end
end

describe 'total_tax' do
describe 'for US customer' do
it 'is the sum of total_tax from line_items' do
assert_equal 8.66, response.total_tax.to_f
end

it 'handles empty quotes' do
working_quote_params[:line_items] = []
assert_equal 0.0, response.total_tax.to_f
end
end

describe 'for EU customer' do
Expand Down

0 comments on commit 96edb96

Please sign in to comment.