mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user