Skip to content

Commit

Permalink
Fix for Adding the product twice crash
Browse files Browse the repository at this point in the history
Apparently, this area of availability was never covered with tests. Recent changes in 14101a1 introduced a simple bug with column name. This commit fixes this and adds one test to show this.
  • Loading branch information
andrzejkrzywda committed Jul 19, 2024
1 parent b2e70e8 commit ec93d4d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def edit

def add_item
read_model = ClientOrders::OrderLine.where(order_uid: params[:id], product_id: params[:product_id]).first
unless Availability.approximately_available?(params[:product_id], (read_model&.quantity || 0) + 1)
unless Availability.approximately_available?(params[:product_id], (read_model&.product_quantity || 0) + 1)
redirect_to edit_client_order_path(params[:id]),
alert: "Product not available in requested quantity!" and return
end
Expand Down
13 changes: 13 additions & 0 deletions rails_application/test/integration/client_orders_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,19 @@ def test_paid_orders_summary
assert_orders_summary("$11.00")
end

def test_adding_the_same_product_twice_bug
customer_id = register_customer("Customer Shop")
product_id = register_product("Fearless Refactoring", 4, 10)
Sidekiq::Job.drain_all

login(customer_id)
visit_client_orders

order_id = SecureRandom.uuid
as_client_add_item_to_basket_for_order(product_id, order_id)
as_client_add_item_to_basket_for_order(product_id, order_id)
end

private

def submit_order_for_customer(customer_id, order_id)
Expand Down

0 comments on commit ec93d4d

Please sign in to comment.