mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-19 13:19:39 +02:00
Fix parent category sums in budget (#1894)
This commit is contained in:
parent
0dea36ec7d
commit
f5ff5332d5
5 changed files with 104 additions and 30 deletions
|
@ -8,15 +8,15 @@ class IncomeStatementTest < ActiveSupport::TestCase
|
|||
|
||||
@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
|
||||
@groceries_category = @family.categories.create! name: "Groceries", 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)
|
||||
create_transaction(account: @checking_account, amount: -1000, category: @income_category)
|
||||
create_transaction(account: @checking_account, amount: 200, category: @groceries_category)
|
||||
create_transaction(account: @credit_card_account, amount: 300, category: @groceries_category)
|
||||
create_transaction(account: @credit_card_account, amount: 400, category: @groceries_category)
|
||||
end
|
||||
|
||||
test "calculates totals for transactions" do
|
||||
|
@ -28,12 +28,23 @@ class IncomeStatementTest < ActiveSupport::TestCase
|
|||
|
||||
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
|
||||
expense_totals = income_statement.expense_totals(period: Period.last_30_days)
|
||||
|
||||
expected_total_expense = 200 + 300 + 400
|
||||
|
||||
assert_equal expected_total_expense, expense_totals.total
|
||||
assert_equal expected_total_expense, expense_totals.category_totals.find { |ct| ct.category.id == @groceries_category.id }.total
|
||||
assert_equal expected_total_expense, expense_totals.category_totals.find { |ct| ct.category.id == @food_category.id }.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
|
||||
income_totals = income_statement.income_totals(period: Period.last_30_days)
|
||||
|
||||
expected_total_income = 1000
|
||||
|
||||
assert_equal expected_total_income, income_totals.total
|
||||
assert_equal expected_total_income, income_totals.category_totals.find { |ct| ct.category.id == @income_category.id }.total
|
||||
end
|
||||
|
||||
test "calculates median expense" do
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue