mirror of
https://github.com/we-promise/sure.git
synced 2026-04-17 11:04:14 +00:00
* - Add tests for `Simplefin::AccountTypeMapper` and `AccountSimplefinCreation` - Implement `Simplefin::AccountTypeMapper` for account type inference with fallback-only logic - Enhance inactive state handling for `SimplefinItem::Importer` - Improve subtype selection handling in views with confidence-based inference * Remove unnecessary `.presence` check for `openai_uri_base` in hostings settings * Refine zero balance detection logic in `SimplefinItem::Importer` and add regression test for missing balances scenario * Enhance account type and subtype inference logic with explicit investment subtype mapping, improved regex handling, and institution-based credit card detection * Refine retirement subtype mapping in `AccountTypeMapper` tests with explicit case-based assertions * Expand `AccountTypeMapper` investment subtype mapping to include `403b` and `tsp` with updated regex definitions * Remove unused `retirement_hint?` method in `AccountTypeMapper` to simplify codebase --------- Co-authored-by: Josh Waldrep <joshua.waldrep5+github@gmail.com>
63 lines
2.5 KiB
Ruby
63 lines
2.5 KiB
Ruby
require "test_helper"
|
|
|
|
class SimplefinItem::ImporterInactiveTest < ActiveSupport::TestCase
|
|
setup do
|
|
@family = families(:dylan_family)
|
|
@item = SimplefinItem.create!(family: @family, name: "SF Conn", access_url: "https://example.com/access")
|
|
@sync = Sync.create!(syncable: @item)
|
|
end
|
|
|
|
def importer
|
|
@importer ||= SimplefinItem::Importer.new(@item, simplefin_provider: mock(), sync: @sync)
|
|
end
|
|
|
|
test "marks inactive when payload indicates closed or hidden" do
|
|
account_data = { id: "a1", name: "Old Checking", balance: 0, currency: "USD", closed: true }
|
|
importer.send(:import_account, account_data)
|
|
|
|
stats = @sync.reload.sync_stats
|
|
assert stats.dig("inactive", "a1"), "should be inactive when closed flag present"
|
|
end
|
|
|
|
test "marks inactive after three consecutive zero runs with no holdings" do
|
|
account_data = { id: "a2", name: "Dormant", balance: 0, "available-balance": 0, currency: "USD" }
|
|
|
|
2.times { importer.send(:import_account, account_data) }
|
|
stats = @sync.reload.sync_stats
|
|
assert_equal 2, stats.dig("zero_runs", "a2"), "should count zero runs"
|
|
assert_equal false, stats.dig("inactive", "a2"), "should not be inactive before threshold"
|
|
|
|
importer.send(:import_account, account_data)
|
|
stats = @sync.reload.sync_stats
|
|
assert_equal true, stats.dig("inactive", "a2"), "should be inactive at threshold"
|
|
end
|
|
|
|
test "resets zero_runs_count and inactive when activity returns" do
|
|
account_data = { id: "a3", name: "Dormant", balance: 0, "available-balance": 0, currency: "USD" }
|
|
3.times { importer.send(:import_account, account_data) }
|
|
stats = @sync.reload.sync_stats
|
|
assert_equal true, stats.dig("inactive", "a3")
|
|
|
|
# Activity returns: non-zero balance or holdings
|
|
active_data = { id: "a3", name: "Dormant", balance: 10, currency: "USD" }
|
|
importer.send(:import_account, active_data)
|
|
stats = @sync.reload.sync_stats
|
|
assert_equal 0, stats.dig("zero_runs", "a3")
|
|
assert_equal false, stats.dig("inactive", "a3")
|
|
end
|
|
end
|
|
|
|
|
|
# Additional regression: no balances present should not increment zero_runs or mark inactive
|
|
class SimplefinItem::ImporterInactiveTest < ActiveSupport::TestCase
|
|
test "does not count zero run when both balances are missing and no holdings" do
|
|
account_data = { id: "a4", name: "Unknown", currency: "USD" } # no balance keys, no holdings
|
|
|
|
importer.send(:import_account, account_data)
|
|
stats = @sync.reload.sync_stats
|
|
|
|
assert_equal 0, stats.dig("zero_runs", "a4").to_i
|
|
assert_equal false, stats.dig("inactive", "a4")
|
|
end
|
|
end
|