Skip to content

Commit

Permalink
[WIP] test adding item to order by client when item is out of stock
Browse files Browse the repository at this point in the history
  • Loading branch information
marlena-b authored and andrzejkrzywda committed Jul 31, 2024
1 parent 198efcf commit 684c012
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
47 changes: 47 additions & 0 deletions rails_application/test/integration/client_orders_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,47 @@ def test_adding_the_same_product_twice_bug
as_client_add_item_to_basket_for_order(product_id, order_id)
end

def test_adding_product_which_is_not_available_anymore
customer_1_id = register_customer('Arkency')
customer_2_id = register_customer("Customer Shop")
product_id = register_product("Fearless Refactoring", 4, 10)
Sidekiq::Job.drain_all

supply_product(product_id, 1)
session_1 = login_as(customer_1_id)
session_2 = login_as(customer_2_id)

session_1.get "/client_orders"
session_2.get "/client_orders"

order_1_id = SecureRandom.uuid
session_1.post "/client_orders/#{order_1_id}/add_item?product_id=#{product_id}"

order_2_id = SecureRandom.uuid
session_2.post "/client_orders/#{order_2_id}/add_item?product_id=#{product_id}"

assert session_2.redirect?
assert session_2.response.location.include?("/client_orders/#{order_2_id}/edit")
assert_equal "Product not available in requested quantity!", session_2.flash[:alert]
end

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

supply_product(product_id, 1)
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)

assert_redirected_to "/client_orders/#{order_id}/edit"
assert_equal "Product not available in requested quantity!", flash[:alert]
end

private

def submit_order_for_customer(customer_id, order_id)
Expand Down Expand Up @@ -171,4 +212,10 @@ def update_price(product_id, new_price)
price: new_price,
}
end

def login_as(client_id)
open_session do |sess|
sess.post "/login", params: { client_id: client_id }
end
end
end
4 changes: 4 additions & 0 deletions rails_application/test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ def register_product(name, price, vat_rate)
product_id
end

def supply_product(product_id, quantity)
post "/products/#{product_id}/supplies", params: { quantity: quantity }
end

def update_price(product_id, new_price)
patch "/products/#{product_id}",
params: {
Expand Down

0 comments on commit 684c012

Please sign in to comment.