mirror of
https://github.com/we-promise/sure.git
synced 2026-04-19 12:04:08 +00:00
fix: allow refreshes from the same source for cost basis updates (#917)
* fix: allow refreshes from the same source for cost basis updates * test: update cost basis priority expectations
This commit is contained in:
committed by
GitHub
parent
6779951194
commit
b88734fb5e
@@ -75,4 +75,22 @@ class Holding::MaterializerTest < ActiveSupport::TestCase
|
||||
assert_equal BigDecimal("180.00"), holding.cost_basis,
|
||||
"Trade-derived cost_basis should override provider cost_basis when available"
|
||||
end
|
||||
|
||||
test "recalculates calculated cost_basis when new trades are added" do
|
||||
date = Date.current
|
||||
|
||||
create_trade(@aapl, account: @account, qty: 1, price: 3000, date: date)
|
||||
Holding::Materializer.new(@account, strategy: :forward).materialize_holdings
|
||||
|
||||
holding = @account.holdings.find_by!(security: @aapl, date: date, currency: "USD")
|
||||
assert_equal "calculated", holding.cost_basis_source
|
||||
assert_equal BigDecimal("3000.0"), holding.cost_basis
|
||||
|
||||
create_trade(@aapl, account: @account, qty: 1, price: 2500, date: date)
|
||||
Holding::Materializer.new(@account, strategy: :forward).materialize_holdings
|
||||
|
||||
holding.reload
|
||||
assert_equal "calculated", holding.cost_basis_source
|
||||
assert_equal BigDecimal("2750.0"), holding.cost_basis
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user