Update order total after removing a voucher

We need to do this to make sure when display the payment method
again.
Plus spec
This commit is contained in:
Gaetan Craig-Riou
2023-07-28 14:52:25 +10:00
parent f35001dacc
commit 33ef8def08
2 changed files with 13 additions and 5 deletions

View File

@@ -14,6 +14,9 @@ class VoucherAdjustmentsController < BaseController
def destroy
@order.voucher_adjustments.find_by(id: params[:id])&.destroy
# Update order to make sure we display the appropriate payment method
@order.update_totals_and_states
update_payment_section
end

View File

@@ -790,7 +790,8 @@ describe "As a consumer, I want to checkout my order" do
describe "removing voucher from order" do
before do
voucher.create_adjustment(voucher.code, order)
add_voucher_to_order(voucher, order)
visit checkout_step_path(:payment)
accept_confirm "Are you sure you want to remove the voucher?" do
@@ -804,6 +805,7 @@ describe "As a consumer, I want to checkout my order" do
expect(page).to have_field "Enter voucher code" # Currently no confirmation msg
end
expect(page).not_to have_content "No payment required"
expect(order.voucher_adjustments.length).to eq(0)
end
@@ -823,7 +825,6 @@ describe "As a consumer, I want to checkout my order" do
end
it "can proceed with payment" do
choose "Payment with Fee"
click_button "Next - Order summary"
# Expect to be on the Order Summary page
expect(page).to have_content "Delivery details"
@@ -1151,9 +1152,7 @@ describe "As a consumer, I want to checkout my order" do
let(:voucher) { create(:voucher, code: 'some_code', enterprise: distributor, amount: 6) }
before do
voucher.create_adjustment(voucher.code, order)
order.update_totals
VoucherAdjustmentsService.new(order).update
add_voucher_to_order(voucher, order)
visit checkout_step_path(:summary)
end
@@ -1207,4 +1206,10 @@ describe "As a consumer, I want to checkout my order" do
end
end
end
def add_voucher_to_order(voucher, order)
voucher.create_adjustment(voucher.code, order)
VoucherAdjustmentsService.new(order).update
order.update_totals_and_states
end
end