mirror of
https://github.com/we-promise/sure.git
synced 2026-09-04 06:11:12 +00:00
* feat(wise): add Wise integration with JAR savings account and activity support - Add WiseItem/WiseAccount models with full sync pipeline (importer, syncer, processor) - Detect income vs expense using targetAccount == recipientId from borderless accounts API - Support JAR (SAVINGS) accounts with totalWorth balance and savings subtype - Fetch JAR activity via profile activities API (INTERBALANCE, BALANCE_CASHBACK, BALANCE_ASSET_FEE) - Route INTERBALANCE activities to both JAR and STANDARD accounts and link as Transfer records - Add provider connection status registration, routes, views, and i18n - Add migration for wise_items and wise_accounts tables - Add tests for WiseAccount, WiseEntry::Processor, WiseActivity::Processor, WiseItem::Importer, and WiseItem#link_jar_transfers! * chore(lint): add ignore to security scan (false positive) * fix(wise): address PR review feedback on activity routing, HTML stripping, rate limiting, and scope extraction - Replace title string matching in activity_for_account? with resource.id vs balance_id comparison to avoid breakage when users rename JAR accounts on Wise - Replace gsub(/<[^>]+>/, "") with ActionController::Base.helpers.strip_tags to safely handle user-controlled HTML-like content - Wrap paginated API calls in with_rate_limit_retry (up to 3 attempts, exponential backoff) to handle 429 responses during fetch_jar_activities and fetch_transfers - Extract WiseAccount.unlinked scope and remove duplicated left_joins query from controller * fix(wise): address PR #2433 review feedback - Wire @wise_items into AccountsController#index so linked accounts appear on /accounts - Fix find_wise_account_for_linking to preserve .active scope via .merge instead of .then - Fix cross-currency incoming transfer amount to use targetValue instead of sourceValue - Add missing select_profiles.session_expired locale key - Add missing account_name interpolation to link_existing_account success notice - Use i18n for profile type labels in profile_display_name - Trigger wise_item.sync_later after account linking in all three linking actions - Isolate fee transaction failure so it no longer aborts the main transfer import - Use bare raise in WiseActivity/WiseEntry processors to preserve original backtrace - Re-raise in WiseItem::Unlinking to prevent silently orphaned Holdings - Fix avatar badge to use design system tokens (bg-container-inset, text-primary) * fix(wise): fix INTERBALANCE routing and encrypt pending token in session * fix(wise): replace hand-rolled buttons/links with DS::Button and DS::Link Address repeated sure-design DS drift findings: migrate all manual Tailwind button_to and link_to calls in Wise views to DS::Button (outline/outline_destructive variants) and DS::Link (secondary variant). Add missing provider_panel.disconnect locale key for the disconnect button text. * fix(wise): use render_provider_panel_error in create instead of missing new template * fix(wise): add missing comma in PROVIDERS array CI failed with a SyntaxError because the questrade entry wasn't comma-terminated before the wise entry. * chore(wise): re-add pipelock:ignore for pending token param Lost when the token source moved from session to an encrypted params field in 0b5dc886, causing the CI secret scanner to flag a false positive. * fix(test): widen random ticker suffix to avoid rare collision flake hex(2) only yields 65536 possible tickers, so create_trade's 4 calls per test run had a small but nonzero chance of colliding on the unique ticker+exchange index. hex(8) makes collisions practically impossible.
116 lines
3.5 KiB
Ruby
116 lines
3.5 KiB
Ruby
require "test_helper"
|
|
|
|
class WiseAccountTest < ActiveSupport::TestCase
|
|
setup do
|
|
@wise_item = wise_items(:one)
|
|
@checking = wise_accounts(:checking)
|
|
@jar = wise_accounts(:jar)
|
|
end
|
|
|
|
# jar?
|
|
|
|
test "jar? returns false for STANDARD balance" do
|
|
@checking.update!(raw_payload: { "type" => "STANDARD" })
|
|
assert_not @checking.jar?
|
|
end
|
|
|
|
test "jar? returns true for SAVINGS balance" do
|
|
@jar.update!(raw_payload: { "type" => "SAVINGS" })
|
|
assert @jar.jar?
|
|
end
|
|
|
|
test "jar? returns false when raw_payload is nil" do
|
|
@checking.update!(raw_payload: nil)
|
|
assert_not @checking.jar?
|
|
end
|
|
|
|
# account_subtype
|
|
|
|
test "account_subtype returns checking for STANDARD account" do
|
|
@checking.update!(raw_payload: { "type" => "STANDARD" })
|
|
assert_equal "checking", @checking.account_subtype
|
|
end
|
|
|
|
test "account_subtype returns savings for JAR account" do
|
|
@jar.update!(raw_payload: { "type" => "SAVINGS" })
|
|
assert_equal "savings", @jar.account_subtype
|
|
end
|
|
|
|
# upsert_wise_snapshot!
|
|
|
|
test "upsert_wise_snapshot! updates balance from STANDARD response" do
|
|
balance_data = {
|
|
"id" => "10000001",
|
|
"amount" => { "value" => 2500.0, "currency" => "EUR" },
|
|
"reservedAmount" => { "value" => 100.0, "currency" => "EUR" },
|
|
"type" => "STANDARD"
|
|
}
|
|
|
|
@checking.upsert_wise_snapshot!(balance_data)
|
|
|
|
assert_equal BigDecimal("2500.0"), @checking.current_balance
|
|
assert_equal BigDecimal("100.0"), @checking.reserved_balance
|
|
assert_equal "EUR", @checking.currency
|
|
assert_equal "STANDARD", @checking.raw_payload["type"]
|
|
end
|
|
|
|
test "upsert_wise_snapshot! uses totalWorth for SAVINGS balance" do
|
|
balance_data = {
|
|
"id" => "10000002",
|
|
"amount" => { "value" => 4000.0, "currency" => "EUR" },
|
|
"totalWorth" => { "value" => 5000.0, "currency" => "EUR" },
|
|
"reservedAmount" => { "value" => 0.0, "currency" => "EUR" },
|
|
"type" => "SAVINGS",
|
|
"name" => "Jar"
|
|
}
|
|
|
|
@jar.update!(name: nil)
|
|
@jar.upsert_wise_snapshot!(balance_data)
|
|
|
|
assert_equal BigDecimal("5000.0"), @jar.current_balance
|
|
assert_equal "Jar", @jar.name
|
|
end
|
|
|
|
test "upsert_wise_snapshot! stores borderless_account_id in raw_payload" do
|
|
balance_data = {
|
|
"id" => "10000001",
|
|
"amount" => { "value" => 1000.0, "currency" => "EUR" },
|
|
"reservedAmount" => { "value" => 0.0, "currency" => "EUR" }
|
|
}
|
|
|
|
@checking.upsert_wise_snapshot!(balance_data, borderless_account_id: 88888001, recipient_id: 99999001)
|
|
|
|
assert_equal 88888001, @checking.raw_payload["borderless_account_id"]
|
|
assert_equal 99999001, @checking.raw_payload["recipient_id"]
|
|
end
|
|
|
|
test "upsert_wise_snapshot! preserves existing name" do
|
|
@checking.update!(name: "My Wise EUR")
|
|
balance_data = {
|
|
"id" => "10000001",
|
|
"amount" => { "value" => 1000.0, "currency" => "EUR" },
|
|
"reservedAmount" => { "value" => 0.0, "currency" => "EUR" },
|
|
"name" => "Jar"
|
|
}
|
|
|
|
@checking.upsert_wise_snapshot!(balance_data)
|
|
|
|
assert_equal "My Wise EUR", @checking.name
|
|
end
|
|
|
|
test "upsert_wise_snapshot! defaults name to Wise JAR currency for new SAVINGS account" do
|
|
@jar.update!(name: nil)
|
|
balance_data = {
|
|
"id" => "10000002",
|
|
"amount" => { "value" => 1000.0, "currency" => "EUR" },
|
|
"totalWorth" => { "value" => 1000.0, "currency" => "EUR" },
|
|
"reservedAmount" => { "value" => 0.0, "currency" => "EUR" },
|
|
"type" => "SAVINGS"
|
|
}
|
|
|
|
@jar.upsert_wise_snapshot!(balance_data)
|
|
|
|
assert_equal "Wise JAR EUR", @jar.name
|
|
end
|
|
end
|