Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
marlena-b committed Sep 16, 2024
1 parent b81b09b commit e2cd710
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
24 changes: 24 additions & 0 deletions rails_application/test/integration/client_orders_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,21 @@ def test_empty_order_cannot_be_submitted
assert_select "#alert", "You can't submit an empty order"
end

def test_current_time_promotion_is_applied
customer_id = register_customer("Customer Shop")
product_id = register_product("Fearless Refactoring", 4, 10)
create_current_time_promotion

login(customer_id)
visit_client_orders

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

assert_select "tr td", "$2.00"
end

private

def submit_order_for_customer(customer_id, order_id)
Expand Down Expand Up @@ -229,4 +244,13 @@ def update_price(product_id, new_price)
def login_as(client_id)
open_session { |sess| sess.post "/login", params: { client_id: client_id } }
end

def create_current_time_promotion(discount: 50, start_time: Time.current - 1.day, end_time: Time.current + 1.day)
post "/time_promotions", params: {
label: "Last Minute",
discount: discount,
start_time: start_time,
end_time: end_time
}
end
end
30 changes: 30 additions & 0 deletions rails_application/test/integration/orders_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,27 @@ def test_order_cannot_be_submitted_with_out_of_stock_product
assert_equal "Order can not be submitted! Fearless Refactoring not available in requested quantity!", flash[:alert]
end

def test_current_time_promotion_is_applied
order_id = SecureRandom.uuid
async_remote_id = register_product("Async Remote", 39, 10)
shopify_id = register_customer("Shopify")

create_current_time_promotion
post "/orders/#{order_id}/add_item?product_id=#{async_remote_id}"

post "/orders",
params: {
"authenticity_token" => "[FILTERED]",
"order_id" => order_id,
"customer_id" => shopify_id,
"commit" => "Submit order"
}
follow_redirect!

assert_select("td", "$19.50")
assert_select("dd", "Submitted")
end

private

def assert_remove_buttons_visible(async_remote_id, fearless_id, order_id)
Expand Down Expand Up @@ -329,4 +350,13 @@ def apply_discount_10_percent(order_id)

post "/orders/#{order_id}/update_discount?amount=10"
end

def create_current_time_promotion(discount: 50, start_time: Time.current - 1.day, end_time: Time.current + 1.day)
post "/time_promotions", params: {
label: "Last Minute",
discount: discount,
start_time: start_time,
end_time: end_time
}
end
end

0 comments on commit e2cd710

Please sign in to comment.