Add test to cover weight calculation bug #3072

This commit is contained in:
luisramos0
2018-12-24 00:06:55 +00:00
parent 38ff99717a
commit 2893f1c141

View File

@@ -48,7 +48,7 @@ feature "full-page cart", js: true do
end
describe "admin and handling flat fees" do
context 'when there are fees' do
context "when there are fees" do
let(:handling_fee) { create(:enterprise_fee, calculator: Spree::Calculator::FlatRate.new(preferred_amount: 1),
enterprise: order_cycle.coordinator, fee_type: 'admin') }
@@ -58,7 +58,7 @@ feature "full-page cart", js: true do
visit spree.cart_path
end
it 'shows admin and handlings row' do
it "shows admin and handlings row" do
expect(page).to have_selector('#cart-detail')
expect(page).to have_content('Admin & Handling')
expect(page).to have_selector '.cart-item-price', text: with_currency(0.86)
@@ -68,13 +68,13 @@ feature "full-page cart", js: true do
end
end
context 'when there are no admin and handling fees' do
context "when there are no admin and handling fees" do
before do
add_product_to_cart order, product_fee, quantity: 2
visit spree.cart_path
end
it 'hides admin and handlings row' do
it "hides admin and handlings row" do
expect(page).to have_selector('#cart-detail')
expect(page).to have_no_content('Admin & Handling')
expect(page).to have_selector '.cart-item-price', text: with_currency(0.86)
@@ -83,6 +83,33 @@ feature "full-page cart", js: true do
end
end
describe "admin weight calculated fees" do
context "order with 2 line items" do
let(:admin_fee) { create(:enterprise_fee, calculator: Calculator::Weight.new(preferred_per_kg: 1),
enterprise: order_cycle.coordinator, fee_type: 'admin') }
before do
product_fee.variants.first.update_attributes(unit_value: '2000.0')
product_tax.variants.first.update_attributes(unit_value: '5000.0')
add_enterprise_fee admin_fee
cart_service = CartService.new(order)
cart_service.populate(variants: { product_fee.variants.first.id => 3, product_tax.variants.first.id => 3 })
order.update_distribution_charge!
visit spree.cart_path
end
it "shows the correct weight calculations" do
expect(page).to have_selector('#cart-detail')
expect(page).to have_selector '.cart-item-price', text: with_currency(2.86) # price + 1 * 2kg
expect(page).to have_selector '.cart-item-price', text: with_currency(115.0) # price + 1 * 5kg
expect(page).to have_selector '.order-total.grand-total', text: with_currency(353.58) # above * 3 items
end
end
end
describe "tax" do
before do
add_enterprise_fee enterprise_fee