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:
LPW
2026-01-22 14:52:49 -05:00
committed by GitHub
parent 179552657c
commit a83f70425f
52 changed files with 4417 additions and 25 deletions

View File

@@ -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