From 58dc5242149e804e361bd8afd37992f5dd2aa92e Mon Sep 17 00:00:00 2001 From: Andrzej Krzywda Date: Mon, 11 Dec 2023 14:09:14 +0100 Subject: [PATCH] We no longer verify CannotRemoveZeroQuantityItem constraint It is removed from Ordering as it is one of rare needs to keep items in there. We want to move some of the logic to Pricing later on. --- ecommerce/ordering/lib/ordering/order.rb | 2 -- ecommerce/ordering/test/remove_item_from_basket_test.rb | 9 --------- .../app/controllers/client/orders_controller.rb | 3 --- rails_application/app/controllers/orders_controller.rb | 2 -- 4 files changed, 16 deletions(-) diff --git a/ecommerce/ordering/lib/ordering/order.rb b/ecommerce/ordering/lib/ordering/order.rb index 54fe9f1ac..c36224dbe 100644 --- a/ecommerce/ordering/lib/ordering/order.rb +++ b/ecommerce/ordering/lib/ordering/order.rb @@ -7,7 +7,6 @@ class Order AlreadyConfirmed = Class.new(InvalidState) NotSubmitted = Class.new(InvalidState) OrderHasExpired = Class.new(InvalidState) - CannotRemoveZeroQuantityItem = Class.new(StandardError) def initialize(id) @id = id @@ -70,7 +69,6 @@ def add_item(product_id) def remove_item(product_id) raise AlreadySubmitted unless @state.equal?(:draft) - raise CannotRemoveZeroQuantityItem if @basket.quantity(product_id).zero? apply ItemRemovedFromBasket.new(data: { order_id: @id, product_id: product_id }) end diff --git a/ecommerce/ordering/test/remove_item_from_basket_test.rb b/ecommerce/ordering/test/remove_item_from_basket_test.rb index 4a4865099..2605eec69 100644 --- a/ecommerce/ordering/test/remove_item_from_basket_test.rb +++ b/ecommerce/ordering/test/remove_item_from_basket_test.rb @@ -49,14 +49,5 @@ def test_no_remove_allowed_to_created_order act(RemoveItemFromBasket.new(order_id: aggregate_id, product_id: product_id)) end end - - def test_no_remove_allowed_if_item_quantity_eq_zero - aggregate_id = SecureRandom.uuid - product_id = SecureRandom.uuid - - assert_raises(Order::CannotRemoveZeroQuantityItem) do - act(RemoveItemFromBasket.new(order_id: aggregate_id, product_id: product_id)) - end - end end end diff --git a/rails_application/app/controllers/client/orders_controller.rb b/rails_application/app/controllers/client/orders_controller.rb index a7b255a90..d52fd97ff 100644 --- a/rails_application/app/controllers/client/orders_controller.rb +++ b/rails_application/app/controllers/client/orders_controller.rb @@ -55,9 +55,6 @@ def remove_item product_id: params[:product_id] ) ) - rescue Ordering::Order::CannotRemoveZeroQuantityItem - redirect_to edit_client_order_path(params[:id]), - alert: "Cannot remove the product with 0 quantity" end end diff --git a/rails_application/app/controllers/orders_controller.rb b/rails_application/app/controllers/orders_controller.rb index 75a54c7e3..57d3ee18a 100644 --- a/rails_application/app/controllers/orders_controller.rb +++ b/rails_application/app/controllers/orders_controller.rb @@ -68,8 +68,6 @@ def add_item def remove_item command_bus.(Ordering::RemoveItemFromBasket.new(order_id: params[:id], product_id: params[:product_id])) head :ok - rescue Ordering::Order::CannotRemoveZeroQuantityItem - redirect_to edit_order_path(params[:id]), alert: "Cannot remove the product with 0 quantity" end def create