Add test coverage to #create_tax_charge! with legacy taxes

This commit is contained in:
Matt-Yorkley
2021-05-24 22:15:44 +01:00
parent 9e1d8ab369
commit e21ef3f182

View File

@@ -113,5 +113,60 @@ module Spree
end
end
end
describe "#create_tax_charge!" do
context "handling legacy taxes" do
let(:order) { create(:order) }
let(:zone) { create(:zone_with_member) }
let(:tax_rate20) {
create(:tax_rate, amount: 0.20, included_in_price: false, zone: zone)
}
let(:tax_rate30) {
create(:tax_rate, amount: 0.30, included_in_price: false, zone: zone)
}
let!(:variant) {
create(:variant, tax_category: tax_rate20.tax_category, price: 10)
}
let!(:line_item) {
create(:line_item, variant: variant, order: order, quantity: 2)
}
let!(:shipping_method) {
create(:shipping_method, tax_category: tax_rate30.tax_category)
}
let!(:shipment) {
create(:shipment_with, :shipping_method, order: order, cost: 50,
shipping_method: shipping_method)
}
before do
shipment.update_columns(cost: 20.0)
order.reload
allow(order).to receive(:completed_at) { Time.zone.now }
allow(order).to receive(:tax_zone) { zone }
end
context "when the order has legacy taxes" do
let!(:legacy_tax_adjustment) {
create(:adjustment, order: order, adjustable: order, included: false,
label: "legacy", originator_type: "Spree::TaxRate")
}
it "removes any legacy tax adjustments on order" do
order.create_tax_charge!
expect(order.reload.adjustments).to_not include legacy_tax_adjustment
end
it "re-applies taxes on individual items" do
order.create_tax_charge!
expect(order.all_adjustments.tax.count).to eq 2
expect(line_item.adjustments.tax.first.amount).to eq 4
expect(shipment.adjustments.tax.first.amount).to eq 6
end
end
end
end
end
end