mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
add tests
for methods Spree::Order#tax_adjustment_totals and Spree::Adjustment#find_closest_tax_rate_from_included_tax
This commit is contained in:
committed by
Rob Harrington
parent
4a9c17cb28
commit
e854eb0426
@@ -1,3 +1,5 @@
|
||||
require 'spec_helper'
|
||||
|
||||
module Spree
|
||||
describe Adjustment do
|
||||
it "has metadata" do
|
||||
@@ -279,6 +281,21 @@ module Spree
|
||||
adjustment.included_tax.should == 10.00
|
||||
end
|
||||
end
|
||||
|
||||
describe "getting the corresponding tax rate" do
|
||||
let!(:adjustment_with_tax) { create(:adjustment, amount: 50, included_tax: 10) }
|
||||
let!(:adjustment_without_tax) { create(:adjustment, amount: 50, included_tax: 0) }
|
||||
let!(:tax_rate) { create(:tax_rate, calculator: Spree::Calculator::DefaultTax.new, amount: 0.25) }
|
||||
let!(:other_tax_rate) { create(:tax_rate, calculator: Spree::Calculator::DefaultTax.new, amount: 0.3) }
|
||||
|
||||
it "returns nil if there is no included tax" do
|
||||
adjustment_without_tax.find_closest_tax_rate_from_included_tax.should == nil
|
||||
end
|
||||
|
||||
it "returns the most accurate tax rate" do
|
||||
adjustment_with_tax.find_closest_tax_rate_from_included_tax.should == tax_rate
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -276,6 +276,50 @@ describe Spree::Order do
|
||||
end
|
||||
end
|
||||
|
||||
describe "getting a hash of all taxes" do
|
||||
let(:zone) { create(:zone_with_member) }
|
||||
let(:coordinator) { create(:distributor_enterprise, charges_sales_tax: true) }
|
||||
|
||||
let(:tax_rate10) { create(:tax_rate, included_in_price: true, calculator: Spree::Calculator::DefaultTax.new, amount: 0.1, zone: zone) }
|
||||
let(:tax_rate15) { create(:tax_rate, included_in_price: true, calculator: Spree::Calculator::DefaultTax.new, amount: 0.15, zone: zone) }
|
||||
let(:tax_rate20) { create(:tax_rate, included_in_price: true, calculator: Spree::Calculator::DefaultTax.new, amount: 0.2, zone: zone) }
|
||||
let(:tax_category10) { create(:tax_category, tax_rates: [tax_rate10]) }
|
||||
let(:tax_category15) { create(:tax_category, tax_rates: [tax_rate15]) }
|
||||
let(:tax_category20) { create(:tax_category, tax_rates: [tax_rate20]) }
|
||||
|
||||
let(:variant) { create(:variant, product: create(:product, tax_category: tax_category10)) }
|
||||
let(:shipping_method) { create(:shipping_method, calculator: Spree::Calculator::FlatRate.new(preferred_amount: 46.0)) }
|
||||
let(:enterprise_fee) { create(:enterprise_fee, enterprise: coordinator, tax_category: tax_category20, calculator: Spree::Calculator::FlatRate.new(preferred_amount: 48.0)) }
|
||||
|
||||
let(:order_cycle) { create(:simple_order_cycle, coordinator: coordinator, coordinator_fees: [enterprise_fee], distributors: [coordinator], variants: [variant]) }
|
||||
let!(:order) { create(:order, shipping_method: shipping_method, bill_address: create(:address), order_cycle: order_cycle, distributor: coordinator) }
|
||||
let!(:line_item) { create(:line_item, order: order, variant: variant, price: 44.0) }
|
||||
|
||||
before do
|
||||
Spree::Config.shipment_inc_vat = true
|
||||
Spree::Config.shipping_tax_rate = tax_rate15.amount
|
||||
order.create_shipment!
|
||||
Spree::TaxRate.adjust(order)
|
||||
order.reload.update_distribution_charge!
|
||||
end
|
||||
|
||||
it "returns a hash with all 3 taxes" do
|
||||
order.tax_adjustment_totals.size.should == 3
|
||||
end
|
||||
|
||||
it "contains tax on line_item" do
|
||||
order.tax_adjustment_totals[tax_rate10.amount].should == 4.0
|
||||
end
|
||||
|
||||
it "contains tax on shipping_fee" do
|
||||
order.tax_adjustment_totals[tax_rate15.amount].should == 6.0
|
||||
end
|
||||
|
||||
it "contains tax on enterprise_fee" do
|
||||
order.tax_adjustment_totals[tax_rate20.amount].should == 8.0
|
||||
end
|
||||
end
|
||||
|
||||
describe "setting the distributor" do
|
||||
it "sets the distributor when no order cycle is set" do
|
||||
d = create(:distributor_enterprise)
|
||||
|
||||
Reference in New Issue
Block a user