mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-23 07:09:39 +02:00
New Design System + Codebase Refresh (#1823)
Since the very first 0.1.0-alpha.1 release, we've been moving quickly to add new features to the Maybe app. In doing so, some parts of the codebase have become outdated, unnecessary, or overly-complex as a natural result of this feature prioritization. Now that "core" Maybe is complete, we're moving into a second phase of development where we'll be working hard to improve the accuracy of existing features and build additional features on top of "core". This PR is a quick overhaul of the existing codebase aimed to: - Establish the brand new and simplified dashboard view (pictured above) - Establish and move towards the conventions introduced in Cursor rules and project design overview #1788 - Consolidate layouts and improve the performance of layout queries - Organize the core models of the Maybe domain (i.e. Account::Entry, Account::Transaction, etc.) and break out specific traits of each model into dedicated concerns for better readability - Remove stale / dead code from codebase - Remove overly complex code paths in favor of simpler ones
This commit is contained in:
parent
8539ac7dec
commit
d75be2282b
278 changed files with 3428 additions and 4354 deletions
|
@ -13,129 +13,4 @@ class AccountTest < ActiveSupport::TestCase
|
|||
@account.destroy
|
||||
end
|
||||
end
|
||||
|
||||
test "groups accounts by type" do
|
||||
result = @family.accounts.by_group(period: Period.all)
|
||||
assets = result[:assets]
|
||||
liabilities = result[:liabilities]
|
||||
|
||||
assert_equal @family.assets, assets.sum
|
||||
assert_equal @family.liabilities, liabilities.sum
|
||||
|
||||
depositories = assets.children.find { |group| group.name == "Depository" }
|
||||
properties = assets.children.find { |group| group.name == "Property" }
|
||||
vehicles = assets.children.find { |group| group.name == "Vehicle" }
|
||||
investments = assets.children.find { |group| group.name == "Investment" }
|
||||
other_assets = assets.children.find { |group| group.name == "OtherAsset" }
|
||||
|
||||
credits = liabilities.children.find { |group| group.name == "CreditCard" }
|
||||
loans = liabilities.children.find { |group| group.name == "Loan" }
|
||||
other_liabilities = liabilities.children.find { |group| group.name == "OtherLiability" }
|
||||
|
||||
assert_equal 2, depositories.children.count
|
||||
assert_equal 1, properties.children.count
|
||||
assert_equal 1, vehicles.children.count
|
||||
assert_equal 1, investments.children.count
|
||||
assert_equal 1, other_assets.children.count
|
||||
|
||||
assert_equal 1, credits.children.count
|
||||
assert_equal 1, loans.children.count
|
||||
assert_equal 1, other_liabilities.children.count
|
||||
end
|
||||
|
||||
test "generates balance series" do
|
||||
assert_equal 2, @account.series.values.count
|
||||
end
|
||||
|
||||
test "generates balance series with single value if no balances" do
|
||||
@account.balances.delete_all
|
||||
assert_equal 1, @account.series.values.count
|
||||
end
|
||||
|
||||
test "generates balance series in period" do
|
||||
@account.balances.delete_all
|
||||
@account.balances.create! date: 31.days.ago.to_date, balance: 5000, currency: "USD" # out of period range
|
||||
@account.balances.create! date: 30.days.ago.to_date, balance: 5000, currency: "USD" # in range
|
||||
|
||||
assert_equal 1, @account.series(period: Period.last_30_days).values.count
|
||||
end
|
||||
|
||||
test "generates empty series if no balances and no exchange rate" do
|
||||
with_env_overrides SYNTH_API_KEY: nil do
|
||||
assert_equal 0, @account.series(currency: "NZD").values.count
|
||||
end
|
||||
end
|
||||
|
||||
test "auto-matches transfers" do
|
||||
outflow_entry = create_transaction(date: 1.day.ago.to_date, account: @account, amount: 500)
|
||||
inflow_entry = create_transaction(date: Date.current, account: accounts(:credit_card), amount: -500)
|
||||
|
||||
assert_difference -> { Transfer.count } => 1 do
|
||||
@account.auto_match_transfers!
|
||||
end
|
||||
end
|
||||
|
||||
# In this scenario, our matching logic should find 4 potential matches. These matches should be ranked based on
|
||||
# days apart, then de-duplicated so that we aren't auto-matching the same transaction across multiple transfers.
|
||||
test "when 2 options exist, only auto-match one at a time, ranked by days apart" do
|
||||
yesterday_outflow = create_transaction(date: 1.day.ago.to_date, account: @account, amount: 500)
|
||||
yesterday_inflow = create_transaction(date: 1.day.ago.to_date, account: accounts(:credit_card), amount: -500)
|
||||
|
||||
today_outflow = create_transaction(date: Date.current, account: @account, amount: 500)
|
||||
today_inflow = create_transaction(date: Date.current, account: accounts(:credit_card), amount: -500)
|
||||
|
||||
assert_difference -> { Transfer.count } => 2 do
|
||||
@account.auto_match_transfers!
|
||||
end
|
||||
end
|
||||
|
||||
test "does not auto-match any transfers that have been rejected by user already" do
|
||||
outflow = create_transaction(date: Date.current, account: @account, amount: 500)
|
||||
inflow = create_transaction(date: Date.current, account: accounts(:credit_card), amount: -500)
|
||||
|
||||
RejectedTransfer.create!(inflow_transaction_id: inflow.entryable_id, outflow_transaction_id: outflow.entryable_id)
|
||||
|
||||
assert_no_difference -> { Transfer.count } do
|
||||
@account.auto_match_transfers!
|
||||
end
|
||||
end
|
||||
|
||||
test "transfer_match_candidates only matches between active accounts" do
|
||||
active_account = accounts(:depository)
|
||||
another_active_account = accounts(:credit_card)
|
||||
inactive_account = accounts(:investment)
|
||||
inactive_account.update!(is_active: false)
|
||||
|
||||
# Create matching transactions
|
||||
active_inflow = active_account.entries.create!(
|
||||
date: Date.current,
|
||||
amount: -100,
|
||||
currency: "USD",
|
||||
name: "Test transfer",
|
||||
entryable: Account::Transaction.new
|
||||
)
|
||||
|
||||
active_outflow = another_active_account.entries.create!(
|
||||
date: Date.current,
|
||||
amount: 100,
|
||||
currency: "USD",
|
||||
name: "Test transfer",
|
||||
entryable: Account::Transaction.new
|
||||
)
|
||||
|
||||
inactive_outflow = inactive_account.entries.create!(
|
||||
date: Date.current,
|
||||
amount: 100,
|
||||
currency: "USD",
|
||||
name: "Test transfer",
|
||||
entryable: Account::Transaction.new
|
||||
)
|
||||
|
||||
# Should find matches between active accounts
|
||||
candidates = active_account.transfer_match_candidates
|
||||
assert_includes candidates.map(&:outflow_transaction_id), active_outflow.entryable_id
|
||||
|
||||
# Should not match with inactive account
|
||||
assert_not_includes candidates.map(&:outflow_transaction_id), inactive_outflow.entryable_id
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue