mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-11 23:17:48 +00:00
Refactor, add OrderManagement::Order::Updater#update_voucher
Move the logic to update a voucher and associated order to `OrderManagement`
This commit is contained in:
committed by
Rachel Arnould
parent
0569b30e0d
commit
12cf62c2ff
@@ -70,8 +70,7 @@ module Spree
|
||||
@order.recreate_all_fees! # Enterprise fees on line items and on the order itself
|
||||
|
||||
# Re apply the voucher
|
||||
VoucherAdjustmentsService.new(@order).update
|
||||
@order.update_totals_and_states
|
||||
OrderManagement::Order::Updater.new(@order).update_voucher
|
||||
|
||||
if @order.complete?
|
||||
@order.update_payment_fees!
|
||||
|
||||
@@ -72,8 +72,7 @@ class VoucherAdjustmentsController < BaseController
|
||||
# calculate_voucher_adjustment
|
||||
clear_payments
|
||||
|
||||
VoucherAdjustmentsService.new(@order).update
|
||||
@order.update_totals_and_states
|
||||
OrderManagement::Order::Updater.new(@order).update_voucher
|
||||
|
||||
true
|
||||
end
|
||||
|
||||
@@ -161,6 +161,11 @@ module OrderManagement
|
||||
persist_totals
|
||||
end
|
||||
|
||||
def update_voucher
|
||||
VoucherAdjustmentsService.new(order).update
|
||||
update_totals_and_states
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def cancel_payments_requiring_auth
|
||||
|
||||
@@ -460,6 +460,26 @@ module OrderManagement
|
||||
end
|
||||
end
|
||||
|
||||
describe "#update_voucher" do
|
||||
let(:voucher_service) { instance_double(VoucherAdjustmentsService) }
|
||||
|
||||
it "calls VoucherAdjustmentsService" do
|
||||
expect(VoucherAdjustmentsService).to receive(:new).and_return(voucher_service)
|
||||
expect(voucher_service).to receive(:update)
|
||||
|
||||
updater.update_voucher
|
||||
end
|
||||
|
||||
it "calls update_totals_and_states" do
|
||||
allow(VoucherAdjustmentsService).to receive(:new).and_return(voucher_service)
|
||||
allow(voucher_service).to receive(:update)
|
||||
|
||||
expect(updater).to receive(:update_totals_and_states)
|
||||
|
||||
updater.update_voucher
|
||||
end
|
||||
end
|
||||
|
||||
def update_order_quantity(order)
|
||||
order.line_items.first.update_attribute(:quantity, 2)
|
||||
end
|
||||
|
||||
@@ -507,8 +507,7 @@ RSpec.describe CheckoutController, type: :controller do
|
||||
before do
|
||||
# Adding voucher to the order
|
||||
vine_voucher.create_adjustment(vine_voucher.code, order)
|
||||
VoucherAdjustmentsService.new(order).update
|
||||
order.update_totals_and_states
|
||||
OrderManagement::Order::Updater.new(order).update_voucher
|
||||
|
||||
allow(Vine::VoucherRedeemerService).to receive(:new).and_return(vine_voucher_redeemer)
|
||||
end
|
||||
|
||||
@@ -272,8 +272,7 @@ RSpec.describe "Reporting::Reports::SalesTax::SalesTaxTotalsByOrder" do
|
||||
def add_voucher(order, voucher)
|
||||
# Add voucher to the order
|
||||
voucher.create_adjustment(voucher.code, order)
|
||||
VoucherAdjustmentsService.new(order).update
|
||||
order.update_totals_and_states
|
||||
OrderManagement::Order::Updater.new(order).update_voucher
|
||||
|
||||
Orders::WorkflowService.new(order).complete!
|
||||
end
|
||||
|
||||
@@ -366,7 +366,6 @@ RSpec.describe Spree::Admin::PaymentsController, type: :request do
|
||||
|
||||
def add_voucher_to_order(voucher, order)
|
||||
voucher.create_adjustment(voucher.code, order)
|
||||
VoucherAdjustmentsService.new(order).update
|
||||
order.update_totals_and_states
|
||||
OrderManagement::Order::Updater.new(order).update_voucher
|
||||
end
|
||||
end
|
||||
|
||||
@@ -261,8 +261,7 @@ RSpec.describe Vine::VoucherRedeemerService, feature: :connected_apps do
|
||||
|
||||
def add_voucher(voucher)
|
||||
voucher.create_adjustment(voucher.code, order)
|
||||
VoucherAdjustmentsService.new(order).update
|
||||
order.update_totals_and_states
|
||||
OrderManagement::Order::Updater.new(order).update_voucher
|
||||
end
|
||||
|
||||
def mock_api_response(success:, data: nil, status: 200)
|
||||
|
||||
@@ -154,8 +154,6 @@ RSpec.describe "Revenues By Hub Reports" do
|
||||
order.update_shipping_fees!
|
||||
order.update_order!
|
||||
|
||||
VoucherAdjustmentsService.new(order).update
|
||||
|
||||
order.update_totals_and_states
|
||||
OrderManagement::Order::Updater.new(order).update_voucher
|
||||
end
|
||||
end
|
||||
|
||||
@@ -383,7 +383,6 @@ RSpec.describe "As a consumer, I want to checkout my order" do
|
||||
|
||||
def add_voucher_to_order(voucher, order)
|
||||
voucher.create_adjustment(voucher.code, order)
|
||||
VoucherAdjustmentsService.new(order).update
|
||||
order.update_totals_and_states
|
||||
OrderManagement::Order::Updater.new(order).update_voucher
|
||||
end
|
||||
end
|
||||
|
||||
@@ -479,8 +479,7 @@ RSpec.describe "As a consumer, I want to checkout my order" do
|
||||
|
||||
def add_voucher_to_order(voucher, order)
|
||||
voucher.create_adjustment(voucher.code, order)
|
||||
VoucherAdjustmentsService.new(order).update
|
||||
order.update_totals_and_states
|
||||
OrderManagement::Order::Updater.new(order).update_voucher
|
||||
end
|
||||
|
||||
def set_up_order(balance, state)
|
||||
|
||||
Reference in New Issue
Block a user