Skip to content

Commit

Permalink
We no longer verify CannotRemoveZeroQuantityItem constraint
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
andrzejkrzywda committed Dec 11, 2023
1 parent 642e218 commit 58dc524
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 16 deletions.
2 changes: 0 additions & 2 deletions ecommerce/ordering/lib/ordering/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
9 changes: 0 additions & 9 deletions ecommerce/ordering/test/remove_item_from_basket_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 0 additions & 3 deletions rails_application/app/controllers/client/orders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions rails_application/app/controllers/orders_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 58dc524

Please sign in to comment.