mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-11 03:40:20 +00:00
Per review, remove customer when no existing customer
This commit is contained in:
@@ -21,7 +21,7 @@ module Orders
|
||||
def reset_other!(current_user, current_customer)
|
||||
reset_user(current_user)
|
||||
reset_order_cycle(current_customer)
|
||||
order.customer = current_customer if current_customer.present?
|
||||
order.customer = current_customer
|
||||
order.save!
|
||||
end
|
||||
|
||||
|
||||
@@ -29,6 +29,19 @@ RSpec.describe EnterprisesController do
|
||||
expect(controller.current_order.order_cycle).to be_nil
|
||||
end
|
||||
|
||||
context "when the order is linked to a customer" do
|
||||
it "removes the customer" do
|
||||
# Make sure the order is linked to a customer
|
||||
customer = create(:customer)
|
||||
order.customer = customer
|
||||
order.save!
|
||||
|
||||
expect do
|
||||
get :shop, params: { id: distributor }
|
||||
end.to change { controller.current_order.customer }.to(nil)
|
||||
end
|
||||
end
|
||||
|
||||
context "when user is logged in" do
|
||||
before { allow(controller).to receive(:spree_current_user) { user } }
|
||||
|
||||
|
||||
@@ -70,10 +70,10 @@ RSpec.describe Orders::CartResetService do
|
||||
end
|
||||
|
||||
context "when customer is missing" do
|
||||
it "does not reset the customer" do
|
||||
it "removes the customer" do
|
||||
expect do
|
||||
described_class.new(order, distributor.id.to_s).reset_other!(nil, nil)
|
||||
end.not_to change { order.customer }
|
||||
end.to change { order.customer }.to(nil)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user