1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-19 13:19:39 +02:00
Maybe/test/models/income_statement_test.rb
Zach Gollwitzer d75be2282b
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
2025-02-21 11:57:59 -05:00

48 lines
2.2 KiB
Ruby

require "test_helper"
class IncomeStatementTest < ActiveSupport::TestCase
include Account::EntriesTestHelper
setup do
@family = families(:empty)
@income_category = @family.categories.create! name: "Income", classification: "income"
@food_category = @family.categories.create! name: "Food", classification: "expense"
@shopping_category = @family.categories.create! name: "Shopping", classification: "expense", parent: @food_category
@checking_account = @family.accounts.create! name: "Checking", currency: @family.currency, balance: 5000, accountable: Depository.new
@credit_card_account = @family.accounts.create! name: "Credit Card", currency: @family.currency, balance: 1000, accountable: CreditCard.new
create_transaction(account: @checking_account, amount: -1000, category: @food_category)
create_transaction(account: @checking_account, amount: 200, category: @shopping_category)
create_transaction(account: @credit_card_account, amount: 300, category: @food_category)
create_transaction(account: @credit_card_account, amount: 400, category: @shopping_category)
end
test "calculates totals for transactions" do
income_statement = IncomeStatement.new(@family)
assert_equal Money.new(1000, @family.currency), income_statement.totals.income_money
assert_equal Money.new(200 + 300 + 400, @family.currency), income_statement.totals.expense_money
assert_equal 4, income_statement.totals.transactions_count
end
test "calculates expenses for a period" do
income_statement = IncomeStatement.new(@family)
assert_equal 200 + 300 + 400, income_statement.expense_totals(period: Period.last_30_days).total
end
test "calculates income for a period" do
income_statement = IncomeStatement.new(@family)
assert_equal 1000, income_statement.income_totals(period: Period.last_30_days).total
end
test "calculates median expense" do
income_statement = IncomeStatement.new(@family)
assert_equal 200 + 300 + 400, income_statement.expense_totals(period: Period.last_30_days).total
end
test "calculates median income" do
income_statement = IncomeStatement.new(@family)
assert_equal 1000, income_statement.income_totals(period: Period.last_30_days).total
end
end