From 2893f1c141baf5c5d41e2c163c28244ce2f5f7df Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Mon, 24 Dec 2018 00:06:55 +0000 Subject: [PATCH] Add test to cover weight calculation bug #3072 --- spec/features/consumer/shopping/cart_spec.rb | 35 +++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/spec/features/consumer/shopping/cart_spec.rb b/spec/features/consumer/shopping/cart_spec.rb index a319043c27..5790034fbf 100644 --- a/spec/features/consumer/shopping/cart_spec.rb +++ b/spec/features/consumer/shopping/cart_spec.rb @@ -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