mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-23 15:19:38 +02:00
49 lines
2.2 KiB
Ruby
49 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
|