mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Ensure TaxRateFinder returns an array if the given adjustment has no tax
This commit is contained in:
@@ -6,15 +6,12 @@
|
||||
class TaxRateFinder
|
||||
# @return [Array<Spree::TaxRate>]
|
||||
def self.tax_rates_of(adjustment)
|
||||
new.tax_rates(
|
||||
adjustment.originator,
|
||||
adjustment.adjustable
|
||||
)
|
||||
new.tax_rates(adjustment.originator, adjustment.adjustable)
|
||||
end
|
||||
|
||||
# @return [Array<Spree::TaxRate>]
|
||||
def tax_rates(originator, adjustable)
|
||||
find_associated_tax_rate(originator, adjustable)
|
||||
find_associated_tax_rate(originator, adjustable) || []
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
@@ -5,7 +5,9 @@ require 'spec_helper'
|
||||
describe TaxRateFinder do
|
||||
describe "getting the corresponding tax rate" do
|
||||
let(:amount) { BigDecimal(120) }
|
||||
let(:tax_rate) { create_rate(0.2) }
|
||||
let(:tax_rate) {
|
||||
create(:tax_rate, amount: 0.2, calculator: Calculator::DefaultTax.new, zone: zone)
|
||||
}
|
||||
let(:tax_category) { create(:tax_category, tax_rates: [tax_rate]) }
|
||||
let(:zone) { create(:zone_with_member) }
|
||||
let(:shipment) { create(:shipment) }
|
||||
@@ -13,35 +15,36 @@ describe TaxRateFinder do
|
||||
let(:enterprise_fee) { create(:enterprise_fee, tax_category: tax_category) }
|
||||
let(:order) { create(:order_with_taxes, zone: zone) }
|
||||
|
||||
subject { TaxRateFinder.new }
|
||||
|
||||
it "finds the tax rate of a shipping fee" do
|
||||
rates = TaxRateFinder.new.tax_rates(tax_rate, shipment)
|
||||
rates = subject.tax_rates(tax_rate, shipment)
|
||||
expect(rates).to eq [tax_rate]
|
||||
end
|
||||
|
||||
it "deals with soft-deleted tax rates" do
|
||||
tax_rate.destroy
|
||||
rates = TaxRateFinder.new.tax_rates(tax_rate, shipment)
|
||||
rates = subject.tax_rates(tax_rate, shipment)
|
||||
expect(rates).to eq [tax_rate]
|
||||
end
|
||||
|
||||
it "finds the tax rate of an enterprise fee" do
|
||||
rates = TaxRateFinder.new.tax_rates(enterprise_fee, order)
|
||||
rates = subject.tax_rates(enterprise_fee, order)
|
||||
expect(rates).to eq [tax_rate]
|
||||
end
|
||||
|
||||
it "deals with a soft-deleted line item" do
|
||||
line_item.destroy
|
||||
rates = TaxRateFinder.new.tax_rates(enterprise_fee, line_item)
|
||||
rates = subject.tax_rates(enterprise_fee, line_item)
|
||||
expect(rates).to eq [tax_rate]
|
||||
end
|
||||
|
||||
def create_rate(amount)
|
||||
create(
|
||||
:tax_rate,
|
||||
amount: amount,
|
||||
calculator: Calculator::DefaultTax.new,
|
||||
zone: zone
|
||||
)
|
||||
context "when the given adjustment has no associated tax" do
|
||||
let(:adjustment) { create(:adjustment) }
|
||||
|
||||
it "returns an empty array" do
|
||||
expect(subject.tax_rates(adjustment.originator, adjustment.adjustable)).to eq []
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user