Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def project_price_changes(product_id)
end

def find_border_event(price_changes)
price_changes.reverse.find { |price_change| !recent_event?(price_change) }
price_changes.reverse.find { |price_change| !recent_event?(price_change) && !future_event?(price_change) }
end

def recent_event?(price_change)
Expand Down
16 changes: 16 additions & 0 deletions rails_application/test/public_offer/product_price_changed_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,22 @@ def test_takes_last_event_when_no_events_in_last_30_days
assert_equal 45, Product.find(product_id).lowest_recent_price
end

def test_future_price_not_selected_as_border_event_even_when_lowest
product_id = SecureRandom.uuid
run_command(
ProductCatalog::RegisterProduct.new(
product_id: product_id,
)
)

# Set an old price (will be border event candidate)
set_past_price(product_id, 100, 35.days.ago)
# Set a very low future price that should not be used as border event
set_future_price(product_id, 5, 10.days.from_now)

assert_equal 50, Product.find(product_id).lowest_recent_price
end

private

def prepare_product
Expand Down
Loading