From 45f4a062636beb2211fa2f5a40842a63dd20f8af Mon Sep 17 00:00:00 2001 From: cyrillefr Date: Mon, 4 Mar 2024 21:04:31 +0100 Subject: [PATCH] [BO Orders] Update Ent. fees on item qty decreasing --- app/controllers/api/v0/shipments_controller.rb | 2 ++ .../api/v0/shipments_controller_spec.rb | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/app/controllers/api/v0/shipments_controller.rb b/app/controllers/api/v0/shipments_controller.rb index d742f2c29e..cfa01a6d0a 100644 --- a/app/controllers/api/v0/shipments_controller.rb +++ b/app/controllers/api/v0/shipments_controller.rb @@ -85,6 +85,8 @@ module Api @order.contents.remove(variant, quantity, @shipment, restock_item) @shipment.reload if @shipment.persisted? + @order.recreate_all_fees! + render json: @shipment, serializer: Api::ShipmentSerializer, status: :ok end diff --git a/spec/controllers/api/v0/shipments_controller_spec.rb b/spec/controllers/api/v0/shipments_controller_spec.rb index 9ade418913..2c167587e2 100644 --- a/spec/controllers/api/v0/shipments_controller_spec.rb +++ b/spec/controllers/api/v0/shipments_controller_spec.rb @@ -367,13 +367,17 @@ describe Api::V0::ShipmentsController, type: :controller do instance_double(Spree::Order, number: "123", distributor: variant.product.supplier) } let(:contents) { instance_double(Spree::OrderContents) } + let(:fee_order_shipment) { + instance_double(Spree::Shipment) + } before do allow(Spree::Order).to receive(:find_by!) { fee_order } - allow(controller).to receive(:find_and_update_shipment) {} allow(controller).to receive(:refuse_changing_cancelled_orders) {} allow(fee_order).to receive(:contents) { contents } - allow(contents).to receive(:add) {} + allow(contents).to receive_messages(add: {}, remove: {}) + allow(fee_order).to receive_message_chain(:shipments, :find_by!) { fee_order_shipment } + allow(fee_order_shipment).to receive_messages(update: nil, reload: nil, persisted?: nil) allow(fee_order).to receive(:recreate_all_fees!) end @@ -382,6 +386,12 @@ describe Api::V0::ShipmentsController, type: :controller do spree_put :add, params expect(fee_order).to have_received(:recreate_all_fees!) end + + it "recalculates fees for the line item when qty is decreased" do + params[:order_id] = fee_order.number + spree_put :remove, params + expect(fee_order).to have_received(:recreate_all_fees!) + end end end