mirror of
https://github.com/we-promise/sure.git
synced 2026-04-07 14:31:25 +00:00
* Add HTTParty gem for SimpleFin API integration - Add HTTParty gem for making HTTP requests to SimpleFin API - Required for SimpleFin protocol implementation * Add SimpleFin database schema - Create simplefin_items table for SimpleFin connections - Create simplefin_accounts table for account metadata - Add simplefin_account_id to accounts table for linking - Add external_id to transactions for deduplication - Enable encrypted storage of SimpleFin access URLs * Implement SimpleFin API client and data models - Add SimplefinItem model with sync capabilities and encryption - Add SimplefinAccount model for account data mapping - Implement Provider::Simplefin API client with token exchange - Add SimpleFin protocol support with proper error handling - Include sync jobs, importers, and processors for data flow - Add family SimpleFin connectivity mixin * Update core models for SimpleFin integration - Add SimpleFin account creation methods to Account model - Implement intelligent account type mapping from names - Add SimpleFin linkable functionality to Account - Include SimpleFin items in Family model associations - Support account creation with user-selected types * Add SimpleFin controllers and routing - Create SimplefinItemsController with CRUD operations - Add account setup flow with user type selection - Include sync management and error handling - Update AccountsController to display SimpleFin items - Add routes for SimpleFin item management and setup * Add SimpleFin user interface components - Create SimpleFin connection management views - Add account setup modal with type selection - Include connection form with token input and instructions - Update accounts index to display SimpleFin items - Add SimpleFin option to account method selector - Include SimpleFin in settings navigation * Add user account type selection workflow - Add pending_account_setup field to SimpleFin items - Enable pausing sync for user account type selection - Allow users to choose account types during import - Prevent automatic account creation until user confirms * Add tests for SimpleFin integration - Add SimplefinItem model tests with fixtures - Add SimplefinAccount model tests - Add SimplefinItemsController tests - Include test coverage for sync and account creation * Fix account show page for SimpleFin accounts - Update sync button routing to handle SimpleFin accounts - Add SimpleFin item sync path alongside existing Plaid support - Prevent NoMethodError when viewing SimpleFin-linked accounts - Support proper sync routing for Plaid, SimpleFin, and manual accounts * Complete subtype selection for SimpleFin accounts - Add subtype database columns to all accountable models - Create Stimulus controller for dynamic subtype dropdown interaction - Add delegation from Account to accountable subtype for clean API access - Update SimpleFin account setup form with working subtype selection - Fix account display to show proper subtype labels instead of generic "Cash" Users can now select both account type and subtype during SimpleFin import, and the selected subtypes are properly saved and displayed in the UI. * Fix dark mode compatibility for SimpleFin UI components - Replace hardcoded colors with design system tokens throughout SimpleFin views - Fix method selector hover states to use bg-surface instead of bg-gray-50 - Update SimpleFin form to use styled_form_with and standard form patterns - Replace custom button styling with design system button components - Fix info boxes and containers to use bg-surface and border-primary - Replace hardcoded green/blue colors with text-primary, text-secondary, text-link - Remove custom text area styling to allow form builder defaults (dark mode support) All SimpleFin components now properly adapt to both light and dark themes with correct contrast and visibility. * Fix SimpleFin integration bugs and improve code quality - Fix upsert method to handle string/symbol keys with indifferent access - Add missing show route and view for SimpleFin items - Fix test fixtures to use correct user references - Update test data to match real-world JSON format (string keys, BigDecimal) - Apply code formatting and linting fixes (rubocop, erb_lint) - Ensure all SimpleFin tests pass (16/16 passing) * Remove SimpleFin demo file with outdated setup token * Update SimpleFin User-Agent to use Sure Finance branding * Remove unused SimpleFin account type mapping logic - Remove map_simplefin_type_to_accountable_type method (no longer needed) - Remove create_from_simplefin_account method (manual setup only) - Simplify account type selection UI to not pre-select defaults - Update processor to log error if account missing (safety check) - All account creation now goes through manual user selection flow * Gate SimpleFin option behind US region check SimpleFin is primarily for North American financial institutions, so only show the option when US banking connections are available. * Refactor SimpleFin controller to use model method - Move SimpleFin item creation logic from controller to Family#create_simplefin_item! - Remove duplication between controller and model - Simplify controller to focus on web request/response handling - Remove unused simplefin_provider method - Follow Rails best practices for fat models, skinny controllers * Fix critical data integrity issue in SimpleFin date parsing - Remove fallback to Date.current when transaction dates fail to parse - Raise ArgumentError instead to ensure data integrity - Log detailed error messages for debugging - Skip transactions with invalid dates rather than using incorrect dates - Prevents hard-to-debug issues with balances and financial reports * Address all Gemini code review feedback for SimpleFin integration - Remove debug console.log statements from JavaScript controller - Consolidate duplicate SimpleFin account creation methods into single method - Refactor SimplefinItemsController to reduce complexity with helper methods - Fix HTTParty thread-safety by moving SSL options to class level - Remove redundant HTTParty options from individual requests - Add proper error logging for invalid currency URIs - Extract sync button path logic to AccountsHelper#sync_path_for method - DRY up repeated subtype dropdown code with reusable partial and data structure All SimpleFin tests passing (16/16). Code quality improvements maintain backward compatibility while following Rails best practices. * Fix tests for subtype delegation to accountable models The subtype attribute was moved from Account to individual accountable models to enable users to select specific subtypes during SimpleFin account import. This change allows for better account categorization and more precise display of account types (e.g., "HSA" instead of generic "Cash"). However, tests and the PlaidAccount processor weren't updated to work with the new delegation pattern. This commit fixes: - PlaidAccount::Processor now sets subtype on accountable and uses enrichable pattern to respect user locks - PropertiesController updated to handle subtype via accountable_attributes - Test fixtures corrected to set subtype on accountable models not Account - Tests updated to work with the delegated subtype pattern All originally failing tests now pass: - PropertiesControllerTest#test_updates_property_overview - PlaidAccount::ProcessorTest (2 failing tests) - AccountTest#test_gets_short/long_subtype_label * Fix trailing whitespace (rubocop auto-fix) * Add option to "skip" adding an account * Revert "Gate SimpleFin option behind US region check" This reverts commit43b339940b. * Fix SimpleFin transaction syncing and clean up debug logging - Fix transaction creation to use Entry/entryable pattern instead of creating Transaction directly - Handle both string and symbol keys in transaction data using with_indifferent_access - Fix amount parsing to use BigDecimal instead of converting to cents - Use plaid_id field for external ID storage to prevent duplicates - Remove excessive debug logging while keeping essential error logging SimpleFin transaction sync now works correctly, creating proper Entry records with accurate dollar amounts and preventing duplicate transactions. * Not sure how skipping worked for me the first time * Fix SimpleFin new account setup flow and UI dark mode issues - Fix accounts showing as 'unknown' by displaying proper account type from Account model - Fix new accounts in existing connections not triggering setup flow with correct query - Fix dark mode colors throughout SimpleFin views using design system tokens - Improve UI logic to show existing accounts alongside new account setup prompt - Remove balance attribute error when creating CreditCard accounts - Simplify CreditCard subtype selection (auto-default to credit_card) * Fix linter issues (trailing whitespace and ERB formatting) * Remove SimpleFin button from create accounts view SimpleFin doesn't work like Plaid - no need for separate connection creation for new accounts, just refresh existing connection. * Add missing SimpleFin attributes and fix balance attribute error - Add balance_date field to SimpleFin accounts to capture balance timestamp from protocol - Enhanced build_simplefin_accountable_attributes to set available_credit for CreditCard accounts - Fixed model mismatch where balance was being set on accountable models instead of Account model - Updated tests to verify balance_date parsing functionality This addresses the balance attribute error from commit6681537band ensures we're capturing all available SimpleFin protocol data properly. * Store all SimpleFin protocol fields in JSONB following existing patterns * Fix SimpleFin API date parameter format and improve error handling - Change date parameters from string format to Unix timestamps as required by SimpleFin API - Add better error handling for 400 Bad Request responses - Add more detailed error logging for debugging failed API calls This fixes the issue where SimpleFin was only returning recent transactions instead of historical data when start_date was provided. * Implement comprehensive historical transaction sync for SimpleFin - Add start_date parameter to SimpleFin API calls for historical data - Use 100-year lookback for first sync to capture all available history - Use 7-day buffer for incremental syncs to catch late-posting transactions - Fix transaction storage to prevent data loss during account updates - Remove verbose logging for cleaner output This ensures users get all their historical transactions on first sync, not just recent ones. * Fix SimpleFin transaction sign convention to match Maybe's format - Negate SimpleFin amounts to convert from banking convention to Maybe's format - SimpleFin: expenses negative, income positive (banking convention) - Maybe: expenses positive, income negative (internal convention) - Improve date parsing to handle multiple date formats (Unix timestamps, strings, Date objects) This fixes the issue where expenses showed as negative in the UI instead of positive. * Add SimpleFin account association and fix balance handling for liabilities - Add belongs_to :simplefin_account association to Account model - Fix balance handling for credit cards and loans (use absolute value) - SimpleFin returns negative balances for liabilities, but Maybe expects positive This enables displaying organization names and ensures correct balance display. * Display organization names throughout SimpleFin interface - Show institution names under SimpleFin connection titles - Display organization names next to account names (e.g., "360 Checking • Capital One") - Add organization info to all SimpleFin account displays: - Account setup page - SimpleFin item details page - Regular account lists for SimpleFin accounts - Use org_data from SimpleFin accounts with fallback to institution_name This improves account identification by showing which financial institution each account belongs to throughout the SimpleFin workflow. * Fix SimpleFin UI styling to match design system - Replace custom styles with DS components (DS::FilledIcon, DS::Link, DS::Button) - Use proper design system tokens instead of hardcoded colors - Fix form select styling to match design system patterns - Update empty states to use consistent styling - Ensure all SimpleFin views follow the app's design system This makes the SimpleFin interface consistent with the rest of the app. --------- Signed-off-by: Juan José Mata <juanjo.mata@gmail.com> Co-authored-by: Juan José Mata <juanjo.mata@gmail.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
85 lines
2.9 KiB
Ruby
85 lines
2.9 KiB
Ruby
require "test_helper"
|
|
|
|
class SimplefinAccountTest < ActiveSupport::TestCase
|
|
setup do
|
|
@family = families(:dylan_family)
|
|
@simplefin_item = SimplefinItem.create!(
|
|
family: @family,
|
|
name: "Test SimpleFin Connection",
|
|
access_url: "https://example.com/access_token"
|
|
)
|
|
@simplefin_account = SimplefinAccount.create!(
|
|
simplefin_item: @simplefin_item,
|
|
name: "Test Checking Account",
|
|
account_id: "test_checking_123",
|
|
currency: "USD",
|
|
account_type: "checking",
|
|
current_balance: 1500.50
|
|
)
|
|
end
|
|
|
|
test "belongs to simplefin_item" do
|
|
assert_equal @simplefin_item, @simplefin_account.simplefin_item
|
|
end
|
|
|
|
test "validates presence of required fields" do
|
|
account = SimplefinAccount.new
|
|
refute account.valid?
|
|
|
|
assert_includes account.errors[:name], "can't be blank"
|
|
assert_includes account.errors[:account_type], "can't be blank"
|
|
assert_includes account.errors[:currency], "can't be blank"
|
|
end
|
|
|
|
test "validates balance presence" do
|
|
account = SimplefinAccount.new(
|
|
simplefin_item: @simplefin_item,
|
|
name: "No Balance Account",
|
|
account_id: "no_balance_123",
|
|
currency: "USD",
|
|
account_type: "checking"
|
|
)
|
|
|
|
refute account.valid?
|
|
assert_includes account.errors[:base], "SimpleFin account must have either current or available balance"
|
|
end
|
|
|
|
test "can upsert snapshot data" do
|
|
balance_date = "2024-01-15T10:30:00Z"
|
|
snapshot = {
|
|
"balance" => 2000.0,
|
|
"available-balance" => 1800.0,
|
|
"balance-date" => balance_date,
|
|
"currency" => "USD",
|
|
"type" => "savings",
|
|
"subtype" => "savings",
|
|
"name" => "Updated Savings Account",
|
|
"id" => "updated_123",
|
|
"extra" => { "account_number_last_4" => "1234" },
|
|
"org" => { "domain" => "testbank.com", "name" => "Test Bank" }
|
|
}
|
|
|
|
@simplefin_account.upsert_simplefin_snapshot!(snapshot)
|
|
|
|
assert_equal BigDecimal("2000.0"), @simplefin_account.current_balance
|
|
assert_equal BigDecimal("1800.0"), @simplefin_account.available_balance
|
|
assert_equal Time.parse(balance_date), @simplefin_account.balance_date
|
|
assert_equal "savings", @simplefin_account.account_type
|
|
assert_equal "Updated Savings Account", @simplefin_account.name
|
|
assert_equal({ "account_number_last_4" => "1234" }, @simplefin_account.extra)
|
|
assert_equal({ "domain" => "testbank.com", "name" => "Test Bank" }, @simplefin_account.org_data)
|
|
assert_equal snapshot, @simplefin_account.raw_payload
|
|
end
|
|
|
|
test "can upsert transactions" do
|
|
transactions = [
|
|
{ "id" => "txn_1", "amount" => -50.00, "description" => "Coffee Shop", "posted" => "2024-01-01" },
|
|
{ "id" => "txn_2", "amount" => 1000.00, "description" => "Paycheck", "posted" => "2024-01-02" }
|
|
]
|
|
|
|
@simplefin_account.upsert_simplefin_transactions_snapshot!(transactions)
|
|
|
|
assert_equal transactions, @simplefin_account.raw_transactions_payload
|
|
end
|
|
end
|