mirror of
https://github.com/we-promise/sure.git
synced 2026-04-19 12:04:08 +00:00
Add SnapTrade brokerage integration with full trade history support (#737)
* Introduce SnapTrade integration with models, migrations, views, and activity processing logic. * Refactor SnapTrade activities processing: improve activity fetching flow, handle pending states, and update UI elements for enhanced user feedback. * Update Brakeman ignore file to include intentional redirect for SnapTrade OAuth portal. * Refactor SnapTrade models, views, and processing logic: add currency extraction helper, improve pending state handling, optimize migration checks, and enhance user feedback in UI. * Remove encryption for SnapTrade `snaptrade_user_id`, as it is an identifier, not a secret. * Introduce `SnaptradeConnectionCleanupJob` to asynchronously handle SnapTrade connection cleanup and improve i18n for SnapTrade item status messages. * Update SnapTrade encryption: make `snaptrade_user_secret` non-deterministic to enhance security. --------- Signed-off-by: Juan José Mata <juanjo.mata@gmail.com> Co-authored-by: luckyPipewrench <luckypipewrench@proton.me> Co-authored-by: Juan José Mata <juanjo.mata@gmail.com>
This commit is contained in:
@@ -89,14 +89,21 @@ class HoldingTest < ActiveSupport::TestCase
|
||||
assert_equal Money.new(200.00, "USD"), @amzn.avg_cost
|
||||
end
|
||||
|
||||
test "avg_cost treats zero cost_basis as unknown" do
|
||||
test "avg_cost treats zero cost_basis as unknown when not locked" do
|
||||
# Some providers return 0 when they don't have cost basis data
|
||||
# This should be treated as "unknown" (return nil), not as $0 cost
|
||||
@amzn.update!(cost_basis: 0)
|
||||
@amzn.update!(cost_basis: 0, cost_basis_locked: false)
|
||||
|
||||
assert_nil @amzn.avg_cost
|
||||
end
|
||||
|
||||
test "avg_cost returns zero cost_basis when locked (e.g., airdrops)" do
|
||||
# User-set $0 cost basis is valid for airdrops and should be honored
|
||||
@amzn.update!(cost_basis: 0, cost_basis_source: "manual", cost_basis_locked: true)
|
||||
|
||||
assert_equal Money.new(0, "USD"), @amzn.avg_cost
|
||||
end
|
||||
|
||||
test "trend returns nil when cost basis is unknown" do
|
||||
# Without cost basis, we can't calculate unrealized gain/loss
|
||||
assert_nil @amzn.trend
|
||||
|
||||
Reference in New Issue
Block a user