From d5d043880a577554dcf9c2788bbfec0246e6fd46 Mon Sep 17 00:00:00 2001 From: Gaetan Craig-Riou Date: Mon, 23 Oct 2023 14:45:15 +1100 Subject: [PATCH] Fix scenario when no shipment available I though that once the shipping method was set it's available on the order, but apparently it's not always the case. At least some of the test scenario have order with no shipment, thus no shipping method set. --- app/controllers/split_checkout_controller.rb | 2 +- spec/controllers/split_checkout_controller_spec.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/app/controllers/split_checkout_controller.rb b/app/controllers/split_checkout_controller.rb index ed41eb1609..17d7f36dbd 100644 --- a/app/controllers/split_checkout_controller.rb +++ b/app/controllers/split_checkout_controller.rb @@ -112,7 +112,7 @@ class SplitCheckoutController < ::BaseController def recalculate_voucher return if @order.voucher_adjustments.empty? - return if @order.shipment.shipping_method.id == params[:shipping_method_id].to_i + return if @order.shipping_method&.id == params[:shipping_method_id].to_i VoucherAdjustmentsService.new(@order).update end diff --git a/spec/controllers/split_checkout_controller_spec.rb b/spec/controllers/split_checkout_controller_spec.rb index c6c24e52b7..e6aee5c82e 100644 --- a/spec/controllers/split_checkout_controller_spec.rb +++ b/spec/controllers/split_checkout_controller_spec.rb @@ -223,6 +223,20 @@ describe SplitCheckoutController, type: :controller do expect(response).to redirect_to checkout_step_path(:payment) end + + context "when no shipments available" do + before do + order.shipments.destroy_all + end + + it "recalculates the voucher adjustment" do + expect(service).to receive(:update) + + put(:update, params:) + + expect(response).to redirect_to checkout_step_path(:payment) + end + end end end end