From 55dc262bc224bbf2a12228094e72d9a6c41b7337 Mon Sep 17 00:00:00 2001 From: marlena-b Date: Fri, 6 Sep 2024 14:55:07 +0200 Subject: [PATCH 1/2] Fix time promotions bug --- ecommerce/pricing/lib/pricing/promotions_calendar.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/ecommerce/pricing/lib/pricing/promotions_calendar.rb b/ecommerce/pricing/lib/pricing/promotions_calendar.rb index 817d9aca..70b61e5e 100644 --- a/ecommerce/pricing/lib/pricing/promotions_calendar.rb +++ b/ecommerce/pricing/lib/pricing/promotions_calendar.rb @@ -45,9 +45,8 @@ def initialize(start_time, end_time, discount) end def running?(timestamp) - (@start_time...@end_time).include?(timestamp) + (@start_time...@end_time).cover?(timestamp) end - end end end From 85466a6b3ac298f2e5728bf8091cb36e1af5efbb Mon Sep 17 00:00:00 2001 From: marlena-b Date: Mon, 16 Sep 2024 12:03:43 +0200 Subject: [PATCH 2/2] Add test --- .../test/integration/client_orders_test.rb | 24 +++++++++++++++ .../test/integration/orders_test.rb | 30 +++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/rails_application/test/integration/client_orders_test.rb b/rails_application/test/integration/client_orders_test.rb index 5d2d5405..7cc46162 100644 --- a/rails_application/test/integration/client_orders_test.rb +++ b/rails_application/test/integration/client_orders_test.rb @@ -187,6 +187,21 @@ def test_shows_out_of_stock_badge assert_select "td span", "out of stock" 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) @@ -248,4 +263,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 diff --git a/rails_application/test/integration/orders_test.rb b/rails_application/test/integration/orders_test.rb index 1c231e1f..1297df43 100644 --- a/rails_application/test/integration/orders_test.rb +++ b/rails_application/test/integration/orders_test.rb @@ -246,6 +246,27 @@ def test_shows_out_of_stock_badge assert_select "td span", "0" 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) @@ -356,4 +377,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