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.
This commit is contained in:
Gaetan Craig-Riou
2023-10-23 14:45:15 +11:00
parent 25af178011
commit d5d043880a
2 changed files with 15 additions and 1 deletions

View File

@@ -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

View File

@@ -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