mirror of
https://github.com/we-promise/sure.git
synced 2026-04-19 12:04:08 +00:00
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)
This commit is contained in:
@@ -118,37 +118,37 @@ class Account < ApplicationRecord
|
||||
end
|
||||
|
||||
def map_simplefin_type_to_accountable_type(simplefin_type, account_name: nil)
|
||||
# First try to map by explicit type if provided
|
||||
case simplefin_type&.downcase
|
||||
when "checking", "savings"
|
||||
# First try to map by explicit type if provided
|
||||
case simplefin_type&.downcase
|
||||
when "checking", "savings"
|
||||
return "Depository"
|
||||
when "credit", "credit card"
|
||||
return "CreditCard"
|
||||
when "investment", "brokerage"
|
||||
return "Investment"
|
||||
when "loan", "mortgage"
|
||||
return "Loan"
|
||||
end
|
||||
|
||||
# If type is unknown, try to infer from account name
|
||||
if account_name.present?
|
||||
name_lower = account_name.downcase
|
||||
case name_lower
|
||||
when /checking|chk/
|
||||
return "Depository"
|
||||
when "credit", "credit card"
|
||||
when /savings|save/
|
||||
return "Depository"
|
||||
when /credit|card/
|
||||
return "CreditCard"
|
||||
when "investment", "brokerage"
|
||||
when /investment|invest|brokerage|401k|ira/
|
||||
return "Investment"
|
||||
when "loan", "mortgage"
|
||||
when /loan|mortgage|auto|personal/
|
||||
return "Loan"
|
||||
end
|
||||
end
|
||||
|
||||
# If type is unknown, try to infer from account name
|
||||
if account_name.present?
|
||||
name_lower = account_name.downcase
|
||||
case name_lower
|
||||
when /checking|chk/
|
||||
return "Depository"
|
||||
when /savings|save/
|
||||
return "Depository"
|
||||
when /credit|card/
|
||||
return "CreditCard"
|
||||
when /investment|invest|brokerage|401k|ira/
|
||||
return "Investment"
|
||||
when /loan|mortgage|auto|personal/
|
||||
return "Loan"
|
||||
end
|
||||
end
|
||||
|
||||
# Default to OtherAsset if we can't determine type
|
||||
"OtherAsset"
|
||||
# Default to OtherAsset if we can't determine type
|
||||
"OtherAsset"
|
||||
end
|
||||
|
||||
private
|
||||
@@ -164,11 +164,11 @@ class Account < ApplicationRecord
|
||||
|
||||
def build_accountable_attributes_with_subtype(simplefin_account, account_type, subtype)
|
||||
base_attributes = build_accountable_attributes(simplefin_account, account_type)
|
||||
|
||||
|
||||
if subtype.present?
|
||||
base_attributes[:subtype] = subtype
|
||||
end
|
||||
|
||||
|
||||
base_attributes
|
||||
end
|
||||
end
|
||||
|
||||
@@ -7,19 +7,20 @@ class SimplefinAccount < ApplicationRecord
|
||||
validate :has_balance
|
||||
|
||||
def upsert_simplefin_snapshot!(account_snapshot)
|
||||
# Convert to symbol keys or handle both string and symbol keys
|
||||
snapshot = account_snapshot.with_indifferent_access
|
||||
|
||||
# Map SimpleFin field names to our field names
|
||||
assign_attributes(
|
||||
current_balance: parse_balance(account_snapshot[:balance]),
|
||||
available_balance: parse_balance(account_snapshot[:"available-balance"]),
|
||||
currency: parse_currency(account_snapshot[:currency]),
|
||||
account_type: account_snapshot[:type] || "unknown",
|
||||
account_subtype: account_snapshot[:subtype],
|
||||
name: account_snapshot[:name],
|
||||
account_id: account_snapshot[:id],
|
||||
update!(
|
||||
current_balance: parse_balance(snapshot[:balance]),
|
||||
available_balance: parse_balance(snapshot[:"available-balance"]),
|
||||
currency: parse_currency(snapshot[:currency]),
|
||||
account_type: snapshot[:type] || "unknown",
|
||||
account_subtype: snapshot[:subtype],
|
||||
name: snapshot[:name],
|
||||
account_id: snapshot[:id],
|
||||
raw_payload: account_snapshot
|
||||
)
|
||||
|
||||
save!
|
||||
end
|
||||
|
||||
def upsert_simplefin_transactions_snapshot!(transactions_snapshot)
|
||||
|
||||
@@ -4,4 +4,4 @@ module SimplefinItem::Provided
|
||||
def simplefin_provider
|
||||
@simplefin_provider ||= Provider::Simplefin.new
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user