Update enterprise fee tax adjustment specs

This commit is contained in:
Matt-Yorkley
2021-03-07 22:07:41 +00:00
parent 510f74f654
commit a1438bdb3d

View File

@@ -333,35 +333,34 @@ module Spree
let(:order_cycle) { create(:simple_order_cycle, coordinator: coordinator, coordinator_fees: [enterprise_fee], distributors: [coordinator], variants: [variant]) }
let(:line_item) { create(:line_item, variant: variant) }
let(:order) { create(:order, line_items: [line_item], order_cycle: order_cycle, distributor: coordinator) }
let(:adjustment) { order.all_adjustments.reload.enterprise_fee.first }
let(:fee) { order.all_adjustments.reload.enterprise_fee.first }
let(:fee_tax) { fee.adjustments.tax.first }
context "when enterprise fees have a fixed tax_category" do
before do
order.reload.recreate_all_fees!
order.recreate_all_fees!
end
context "when enterprise fees are taxed per-order" do
let(:enterprise_fee) { create(:enterprise_fee, enterprise: coordinator, tax_category: fee_tax_category, calculator: ::Calculator::FlatRate.new(preferred_amount: 50.0)) }
describe "when the tax rate includes the tax in the price" do
it "records the tax on the enterprise fee adjustments" do
it "records the correct amount in a tax adjustment" do
# The fee is $50, tax is 10%, and the fee is inclusive of tax
# Therefore, the included tax should be 0.1/1.1 * 50 = $4.55
expect(adjustment.included_tax).to eq(4.55)
expect(fee_tax.amount).to eq(4.55)
end
end
describe "when the tax rate does not include the tax in the price" do
before do
fee_tax_rate.update_attribute :included_in_price, false
order.reload.create_tax_charge! # Updating line_item or order has the same effect
order.recreate_all_fees!
end
it "records the tax on TaxRate adjustment on the order" do
expect(adjustment.included_tax).to eq(0)
expect(order.adjustments.tax.first.amount).to eq(5.0)
it "records the correct amount in a tax adjustment" do
expect(fee_tax.amount).to eq(5.0)
end
end
@@ -373,7 +372,7 @@ module Spree
end
it "records no tax as charged" do
expect(adjustment.included_tax).to eq(0)
expect(fee_tax).to be_nil
end
end
end
@@ -382,21 +381,19 @@ module Spree
let(:enterprise_fee) { create(:enterprise_fee, enterprise: coordinator, tax_category: fee_tax_category, calculator: ::Calculator::PerItem.new(preferred_amount: 50.0)) }
describe "when the tax rate includes the tax in the price" do
it "records the tax on the enterprise fee adjustments" do
expect(adjustment.included_tax).to eq(4.55)
it "records the correct amount in a tax adjustment" do
expect(fee_tax.amount).to eq(4.55)
end
end
describe "when the tax rate does not include the tax in the price" do
before do
fee_tax_rate.update_attribute :included_in_price, false
order.reload.create_tax_charge! # Updating line_item or order has the same effect
order.recreate_all_fees!
end
it "records the tax on TaxRate adjustment on the order" do
expect(adjustment.included_tax).to eq(0)
expect(order.adjustments.tax.first.amount).to eq(5.0)
it "records the correct amount in a tax adjustment" do
expect(fee_tax.amount).to eq(5.0)
end
end
end
@@ -410,8 +407,6 @@ module Spree
before do
variant.product.update_attribute(:tax_category_id, product_tax_category.id)
order.create_tax_charge! # Updating line_item or order has the same effect
order.recreate_all_fees!
end
@@ -423,7 +418,7 @@ module Spree
# EnterpriseFee tax category is nil and inheritance only applies to per item fees
# so tax on the enterprise_fee adjustment will be 0
# Tax on line item is: 0.2/1.2 x $10 = $1.67
expect(adjustment.included_tax).to eq(0.0)
expect(fee_tax).to be_nil
expect(line_item.adjustments.tax.first.amount).to eq(1.67)
end
end
@@ -431,7 +426,6 @@ module Spree
describe "when the tax rate does not include the tax in the price" do
before do
product_tax_rate.update_attribute :included_in_price, false
order.reload.create_tax_charge! # Updating line_item or order has the same effect
order.reload.recreate_all_fees!
end
@@ -439,8 +433,7 @@ module Spree
# EnterpriseFee tax category is nil and inheritance only applies to per item fees
# so total tax on the order is only that which applies to the line_item itself
# ie. $10 x 0.2 = $2.0
expect(adjustment.included_tax).to eq(0)
expect(order.adjustments.tax.first.amount).to eq(2.0)
expect(fee_tax).to be_nil
end
end
end
@@ -449,11 +442,11 @@ module Spree
let(:enterprise_fee) { create(:enterprise_fee, enterprise: coordinator, inherits_tax_category: true, calculator: ::Calculator::PerItem.new(preferred_amount: 50.0)) }
describe "when the tax rate includes the tax in the price" do
it "records the tax on the enterprise fee adjustments" do
it "records the correct amount in a tax adjustment" do
# Applying product tax rate of 0.2 to enterprise fee of $50
# gives tax on fee of 0.2/1.2 x $50 = $8.33
# Tax on line item is: 0.2/1.2 x $10 = $1.67
expect(adjustment.included_tax).to eq(8.33)
expect(fee_tax.amount).to eq(8.33)
expect(line_item.adjustments.tax.first.amount).to eq(1.67)
end
end
@@ -461,16 +454,15 @@ module Spree
describe "when the tax rate does not include the tax in the price" do
before do
product_tax_rate.update_attribute :included_in_price, false
order.reload.create_tax_charge! # Updating line_item or order has the same effect
order.recreate_all_fees!
end
it "records the tax on TaxRate adjustment on the order" do
it "records the correct amount in a tax adjustment" do
# EnterpriseFee inherits tax_category from product so total tax on
# the order is that which applies to the line item itself, plus the
# same rate applied to the fee of $50. ie. ($10 + $50) x 0.2 = $12.0
expect(adjustment.included_tax).to eq(0)
expect(order.adjustments.tax.first.amount).to eq(12.0)
expect(fee_tax.amount).to eq(10.0)
expect(order.all_adjustments.tax.sum(:amount)).to eq(12.0)
end
end
end