mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-28 01:53:25 +00:00
Add test coverage to recalculating fees and taxes on completed orders
This commit is contained in:
@@ -77,7 +77,9 @@ describe Spree::Admin::OrdersController, type: :controller do
|
||||
let(:user) { create(:admin_user) }
|
||||
let(:variant1) { create(:variant) }
|
||||
let(:variant2) { create(:variant) }
|
||||
let(:distributor) { create(:distributor_enterprise, allow_order_changes: true) }
|
||||
let(:distributor) {
|
||||
create(:distributor_enterprise, allow_order_changes: true, charges_sales_tax: true)
|
||||
}
|
||||
let(:order_cycle) { create(:simple_order_cycle, distributors: [distributor]) }
|
||||
let(:enterprise_fee) { create(:enterprise_fee, calculator: build(:calculator_per_item) ) }
|
||||
let!(:exchange) { create(:exchange, incoming: true, sender: variant1.product.supplier, receiver: order_cycle.coordinator, variants: [variant1, variant2], enterprise_fees: [enterprise_fee]) }
|
||||
@@ -140,6 +142,74 @@ describe Spree::Admin::OrdersController, type: :controller do
|
||||
expect(order.adjustment_total).to eq 0
|
||||
end
|
||||
end
|
||||
|
||||
context "with taxes on enterprise fees" do
|
||||
let(:zone) { create(:zone_with_member) }
|
||||
let(:tax_included) { true }
|
||||
let(:tax_rate) {
|
||||
create(:tax_rate, amount: 0.25, included_in_price: tax_included, zone: zone)
|
||||
}
|
||||
let!(:enterprise_fee) {
|
||||
create(:enterprise_fee, tax_category: tax_rate.tax_category, amount: 1)
|
||||
}
|
||||
|
||||
before do
|
||||
allow(order).to receive(:tax_zone) { zone }
|
||||
end
|
||||
|
||||
context "with included taxes" do
|
||||
it "taxes fees correctly" do
|
||||
spree_put :update, { id: order.number }
|
||||
order.reload
|
||||
|
||||
expect(order.all_adjustments.tax.count).to eq 2
|
||||
expect(order.enterprise_fee_tax).to eq 0.4
|
||||
|
||||
expect(order.included_tax_total).to eq 0.4
|
||||
expect(order.additional_tax_total).to eq 0
|
||||
end
|
||||
end
|
||||
|
||||
context "with added taxes" do
|
||||
let(:tax_included) { false }
|
||||
|
||||
it "taxes fees correctly" do
|
||||
spree_put :update, { id: order.number }
|
||||
order.reload
|
||||
|
||||
expect(order.all_adjustments.tax.count).to eq 2
|
||||
expect(order.enterprise_fee_tax).to eq 0.5
|
||||
|
||||
expect(order.included_tax_total).to eq 0
|
||||
expect(order.additional_tax_total).to eq 0.5
|
||||
end
|
||||
|
||||
context "when the order has legacy taxes" do
|
||||
let(:legacy_tax_adjustment) {
|
||||
create(:adjustment, amount: 0.5, included: false, originator: tax_rate,
|
||||
order: order, adjustable: order, state: "closed")
|
||||
}
|
||||
|
||||
before do
|
||||
order.all_adjustments.tax.delete_all
|
||||
order.adjustments << legacy_tax_adjustment
|
||||
end
|
||||
|
||||
it "removes legacy tax adjustments before recalculating tax" do
|
||||
expect(order.all_adjustments.tax.count).to eq 1
|
||||
expect(order.all_adjustments.tax).to include legacy_tax_adjustment
|
||||
expect(order.additional_tax_total).to eq 0.5
|
||||
|
||||
spree_put :update, { id: order.number }
|
||||
order.reload
|
||||
|
||||
expect(order.all_adjustments.tax.count).to eq 2
|
||||
expect(order.all_adjustments.tax).to_not include legacy_tax_adjustment
|
||||
expect(order.additional_tax_total).to eq 0.5
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user