Skip to content

Commit 89380f0

Browse files
Fix future prices issue in PublicOffer::Product lowest price calculation
Co-authored-by: andrzejkrzywda <[email protected]>
1 parent 4d1cdea commit 89380f0

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

rails_application/app/read_models/public_offer/register_lowest_price.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def project_price_changes(product_id)
4141
end
4242

4343
def find_border_event(price_changes)
44-
price_changes.reverse.find { |price_change| !recent_event?(price_change) }
44+
price_changes.reverse.find { |price_change| !recent_event?(price_change) && !future_event?(price_change) }
4545
end
4646

4747
def recent_event?(price_change)

rails_application/test/public_offer/product_price_changed_test.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,22 @@ def test_takes_last_event_when_no_events_in_last_30_days
9595
assert_equal 45, Product.find(product_id).lowest_recent_price
9696
end
9797

98+
def test_future_price_not_selected_as_border_event_even_when_lowest
99+
product_id = SecureRandom.uuid
100+
run_command(
101+
ProductCatalog::RegisterProduct.new(
102+
product_id: product_id,
103+
)
104+
)
105+
106+
# Set an old price (will be border event candidate)
107+
set_past_price(product_id, 100, 35.days.ago)
108+
# Set a very low future price that should not be used as border event
109+
set_future_price(product_id, 5, 10.days.from_now)
110+
111+
assert_equal 50, Product.find(product_id).lowest_recent_price
112+
end
113+
98114
private
99115

100116
def prepare_product

0 commit comments

Comments
 (0)