mirror of
https://github.com/we-promise/sure.git
synced 2026-07-25 11:12:13 +00:00
* Add per-account toggle to disable automatic transaction categorization Adds an `enable_category_matcher` boolean (default: true) to accounts so users can opt out of Plaid's automatic category suggestions on a per-account basis. When disabled, newly synced transactions arrive uncategorized so rules or manual assignment take precedence. - New migration adds `enable_category_matcher` column (default true, null: false) - `PlaidEntry::Processor#matched_category` gates the CategoryMatcher call on the account flag - Toggle rendered in the account edit modal for linked accounts (saves via main form submit) - `AccountableResource#account_params` permits the new field - `AccountsController#toggle_category_matcher` action added for potential API use - i18n strings added for label and hint text - Unit test covers the disabled-matcher path Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> * Only show category matcher toggle for Plaid-linked accounts Only PlaidEntry::Processor honors enable_category_matcher, but the toggle rendered for every linked account, silently doing nothing for other providers. Adds Account::Linkable#supports_category_matcher? (covering both the legacy plaid_account_id link and AccountProvider rows) and gates the form toggle on it. The SimpleFIN TODO now also points at this helper so the toggle appears once SimpleFIN matching lands. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> * Add controller tests for category matcher toggle persistence and rendering Covers the two paths flagged in review as untested: the flag persisting through the shared AccountableResource#update action via account_params (both disable and re-enable), and the edit form rendering the toggle only for accounts where supports_category_matcher? is true. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> --------- Signed-off-by: Mike Lloyd <49411532+mike-lloyd03@users.noreply.github.com> Signed-off-by: Juan José Mata <juanjo.mata@gmail.com> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com> Co-authored-by: Juan José Mata <juanjo.mata@gmail.com>
146 lines
4.6 KiB
Ruby
146 lines
4.6 KiB
Ruby
require "test_helper"
|
|
|
|
class Account::LinkableTest < ActiveSupport::TestCase
|
|
setup do
|
|
@family = families(:dylan_family)
|
|
@account = accounts(:depository)
|
|
end
|
|
|
|
test "linked? returns true when account has providers" do
|
|
plaid_account = plaid_accounts(:one)
|
|
AccountProvider.create!(account: @account, provider: plaid_account)
|
|
|
|
assert @account.linked?
|
|
end
|
|
|
|
test "linked? returns false when account has no providers" do
|
|
assert @account.unlinked?
|
|
end
|
|
|
|
test "providers returns all provider adapters" do
|
|
plaid_account = plaid_accounts(:one)
|
|
AccountProvider.create!(account: @account, provider: plaid_account)
|
|
|
|
providers = @account.providers
|
|
assert_equal 1, providers.count
|
|
assert_kind_of Provider::PlaidAdapter, providers.first
|
|
end
|
|
|
|
test "provider_for returns specific provider adapter" do
|
|
plaid_account = plaid_accounts(:one)
|
|
AccountProvider.create!(account: @account, provider: plaid_account)
|
|
|
|
adapter = @account.provider_for("PlaidAccount")
|
|
assert_kind_of Provider::PlaidAdapter, adapter
|
|
end
|
|
|
|
test "linked_to? checks if account is linked to specific provider type" do
|
|
plaid_account = plaid_accounts(:one)
|
|
AccountProvider.create!(account: @account, provider: plaid_account)
|
|
|
|
assert @account.linked_to?("PlaidAccount")
|
|
refute @account.linked_to?("SimplefinAccount")
|
|
end
|
|
|
|
test "supports_category_matcher? returns true for Plaid-linked accounts" do
|
|
plaid_account = plaid_accounts(:one)
|
|
AccountProvider.create!(account: @account, provider: plaid_account)
|
|
|
|
assert @account.supports_category_matcher?
|
|
end
|
|
|
|
test "supports_category_matcher? returns true for legacy plaid_account_id links" do
|
|
plaid_account = plaid_accounts(:one)
|
|
@account.update!(plaid_account: plaid_account)
|
|
|
|
assert @account.supports_category_matcher?
|
|
end
|
|
|
|
test "supports_category_matcher? returns false for unlinked and non-Plaid accounts" do
|
|
refute @account.supports_category_matcher?
|
|
|
|
simplefin_item = SimplefinItem.create!(
|
|
family: @family,
|
|
name: "Test SimpleFin",
|
|
access_url: "https://example.com/access_token"
|
|
)
|
|
simplefin_account = SimplefinAccount.create!(
|
|
simplefin_item: simplefin_item,
|
|
name: "Test Account",
|
|
account_id: "test-acct",
|
|
currency: "USD",
|
|
account_type: "checking",
|
|
current_balance: 0
|
|
)
|
|
@account.update!(simplefin_account: simplefin_account)
|
|
|
|
refute @account.supports_category_matcher?
|
|
end
|
|
|
|
test "can_delete_holdings? returns true for unlinked accounts" do
|
|
assert @account.unlinked?
|
|
assert @account.can_delete_holdings?
|
|
end
|
|
|
|
test "can_delete_holdings? returns false when any provider disallows deletion" do
|
|
plaid_account = plaid_accounts(:one)
|
|
AccountProvider.create!(account: @account, provider: plaid_account)
|
|
|
|
# PlaidAdapter.can_delete_holdings? returns false by default
|
|
refute @account.can_delete_holdings?
|
|
end
|
|
|
|
test "can_delete_holdings? returns true only when all providers allow deletion" do
|
|
plaid_account = plaid_accounts(:one)
|
|
AccountProvider.create!(account: @account, provider: plaid_account)
|
|
|
|
# Stub all providers to return true
|
|
@account.providers.each do |provider|
|
|
provider.stubs(:can_delete_holdings?).returns(true)
|
|
end
|
|
|
|
assert @account.can_delete_holdings?
|
|
end
|
|
|
|
# The `linked` scope mirrors `linked?` at the SQL level. These tests pin
|
|
# all three link types so a future schema or `linked?` change breaks the
|
|
# test instead of silently diverging (e.g. wrong sparkline aggregation).
|
|
test "linked scope matches accounts linked via account_providers" do
|
|
plaid_account = plaid_accounts(:one)
|
|
AccountProvider.create!(account: @account, provider: plaid_account)
|
|
|
|
assert_includes Account.linked, @account
|
|
end
|
|
|
|
test "linked scope matches accounts with legacy plaid_account_id" do
|
|
plaid_account = plaid_accounts(:one)
|
|
@account.update!(plaid_account: plaid_account)
|
|
|
|
assert_includes Account.linked, @account
|
|
end
|
|
|
|
test "linked scope matches accounts with legacy simplefin_account_id" do
|
|
simplefin_item = SimplefinItem.create!(
|
|
family: @family,
|
|
name: "Test SimpleFin",
|
|
access_url: "https://example.com/access_token"
|
|
)
|
|
simplefin_account = SimplefinAccount.create!(
|
|
simplefin_item: simplefin_item,
|
|
name: "Test Account",
|
|
account_id: "test-acct",
|
|
currency: "USD",
|
|
account_type: "checking",
|
|
current_balance: 0
|
|
)
|
|
@account.update!(simplefin_account: simplefin_account)
|
|
|
|
assert_includes Account.linked, @account
|
|
end
|
|
|
|
test "linked scope excludes manual accounts" do
|
|
assert @account.unlinked?
|
|
refute_includes Account.linked, @account
|
|
end
|
|
end
|