mirror of
https://github.com/we-promise/sure.git
synced 2026-04-07 14:31:25 +00:00
* Feat(CoinStats): Scaffold implementation, not yet functional * Feat(CoinStats): Implement crypto wallet balance and transactions * Feat(CoinStats): Add tests, Minor improvements * Feat(CoinStats): Utilize bulk fetch API endpoints * Feat(CoinStats): Migrate strings to i8n * Feat(CoinStats): Fix error handling in wallet link modal * Feat(CoinStats): Implement hourly provider sync job * Feat(CoinStats): Generate docstrings * Fix(CoinStats): Validate API Key on provider update * Fix(Providers): Safely handle race condition in merchance creation * Fix(CoinStats): Don't catch system signals in account processor * Fix(CoinStats): Preload before iterating accounts * Fix(CoinStats): Add no opener / referrer to API dashboard link * Fix(CoinStats): Use strict matching for symbols * Fix(CoinStats): Remove dead code in transactions importer * Fix(CoinStats): Avoid transaction fallback ID collisions * Fix(CoinStats): Improve Blockchains fetch error handling * Fix(CoinStats): Enforce NOT NULL constraint for API Key schema * Fix(CoinStats): Migrate sync status strings to i8n * Fix(CoinStats): Use class name rather than hardcoded string * Fix(CoinStats): Use account currency rather than hardcoded USD * Fix(CoinStats): Migrate from standalone to Provider class * Fix(CoinStats): Fix test failures due to string changes
178 lines
4.7 KiB
Ruby
178 lines
4.7 KiB
Ruby
require "test_helper"
|
|
|
|
class AccountProviderTest < ActiveSupport::TestCase
|
|
setup do
|
|
@account = accounts(:depository)
|
|
@family = families(:dylan_family)
|
|
|
|
# Create provider items
|
|
@plaid_item = PlaidItem.create!(
|
|
family: @family,
|
|
plaid_id: "test_plaid_item",
|
|
access_token: "test_token",
|
|
name: "Test Bank"
|
|
)
|
|
|
|
@simplefin_item = SimplefinItem.create!(
|
|
family: @family,
|
|
name: "Test SimpleFin Bank",
|
|
access_url: "https://example.com/access"
|
|
)
|
|
|
|
# Create provider accounts
|
|
@plaid_account = PlaidAccount.create!(
|
|
plaid_item: @plaid_item,
|
|
name: "Plaid Checking",
|
|
plaid_id: "plaid_123",
|
|
plaid_type: "depository",
|
|
currency: "USD",
|
|
current_balance: 1000
|
|
)
|
|
|
|
@simplefin_account = SimplefinAccount.create!(
|
|
simplefin_item: @simplefin_item,
|
|
name: "SimpleFin Checking",
|
|
account_id: "sf_123",
|
|
account_type: "checking",
|
|
currency: "USD",
|
|
current_balance: 2000
|
|
)
|
|
end
|
|
|
|
test "allows an account to have multiple different provider types" do
|
|
# Should be able to link both Plaid and SimpleFin to same account
|
|
plaid_provider = AccountProvider.create!(
|
|
account: @account,
|
|
provider: @plaid_account
|
|
)
|
|
|
|
simplefin_provider = AccountProvider.create!(
|
|
account: @account,
|
|
provider: @simplefin_account
|
|
)
|
|
|
|
assert_equal 2, @account.account_providers.count
|
|
assert_includes @account.account_providers, plaid_provider
|
|
assert_includes @account.account_providers, simplefin_provider
|
|
end
|
|
|
|
test "prevents duplicate provider type for same account" do
|
|
# Create first PlaidAccount link
|
|
AccountProvider.create!(
|
|
account: @account,
|
|
provider: @plaid_account
|
|
)
|
|
|
|
# Create another PlaidAccount
|
|
another_plaid_account = PlaidAccount.create!(
|
|
plaid_item: @plaid_item,
|
|
name: "Another Plaid Account",
|
|
plaid_id: "plaid_456",
|
|
plaid_type: "savings",
|
|
currency: "USD",
|
|
current_balance: 5000
|
|
)
|
|
|
|
# Should not be able to link another PlaidAccount to same account
|
|
duplicate_provider = AccountProvider.new(
|
|
account: @account,
|
|
provider: another_plaid_account
|
|
)
|
|
|
|
assert_not duplicate_provider.valid?
|
|
assert_includes duplicate_provider.errors[:account_id], "has already been taken"
|
|
end
|
|
|
|
test "prevents same provider account from linking to multiple accounts" do
|
|
# Link provider to first account
|
|
AccountProvider.create!(
|
|
account: @account,
|
|
provider: @plaid_account
|
|
)
|
|
|
|
# Try to link same provider to another account
|
|
another_account = accounts(:investment)
|
|
|
|
duplicate_link = AccountProvider.new(
|
|
account: another_account,
|
|
provider: @plaid_account
|
|
)
|
|
|
|
assert_not duplicate_link.valid?
|
|
assert_includes duplicate_link.errors[:provider_id], "has already been taken"
|
|
end
|
|
|
|
test "adapter method returns correct adapter" do
|
|
provider = AccountProvider.create!(
|
|
account: @account,
|
|
provider: @plaid_account
|
|
)
|
|
|
|
adapter = provider.adapter
|
|
|
|
assert_kind_of Provider::PlaidAdapter, adapter
|
|
assert_equal "plaid", adapter.provider_name
|
|
assert_equal @account, adapter.account
|
|
end
|
|
|
|
test "provider_name delegates to adapter" do
|
|
plaid_provider = AccountProvider.create!(
|
|
account: @account,
|
|
provider: @plaid_account
|
|
)
|
|
|
|
simplefin_provider = AccountProvider.create!(
|
|
account: accounts(:investment),
|
|
provider: @simplefin_account
|
|
)
|
|
|
|
assert_equal "plaid", plaid_provider.provider_name
|
|
assert_equal "simplefin", simplefin_provider.provider_name
|
|
end
|
|
|
|
test "destroying account_provider does not destroy non-coinstats provider accounts" do
|
|
provider = AccountProvider.create!(
|
|
account: @account,
|
|
provider: @plaid_account
|
|
)
|
|
|
|
plaid_account_id = @plaid_account.id
|
|
|
|
assert PlaidAccount.exists?(plaid_account_id)
|
|
|
|
provider.destroy!
|
|
|
|
# Non-CoinStats provider accounts should remain (can enter "needs setup" state)
|
|
assert PlaidAccount.exists?(plaid_account_id)
|
|
end
|
|
|
|
test "destroying account_provider destroys coinstats provider account" do
|
|
coinstats_item = CoinstatsItem.create!(
|
|
family: @family,
|
|
name: "Test CoinStats",
|
|
api_key: "test_key"
|
|
)
|
|
|
|
coinstats_account = CoinstatsAccount.create!(
|
|
coinstats_item: coinstats_item,
|
|
name: "Test Wallet",
|
|
currency: "USD",
|
|
current_balance: 1000
|
|
)
|
|
|
|
provider = AccountProvider.create!(
|
|
account: @account,
|
|
provider: coinstats_account
|
|
)
|
|
|
|
coinstats_account_id = coinstats_account.id
|
|
|
|
assert CoinstatsAccount.exists?(coinstats_account_id)
|
|
|
|
provider.destroy!
|
|
|
|
# CoinStats provider accounts should be destroyed to avoid orphaned records
|
|
assert_not CoinstatsAccount.exists?(coinstats_account_id)
|
|
end
|
|
end
|