mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
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:
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user