mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-06 14:05:20 +02:00
More lint fixes
This commit is contained in:
parent
6affb16768
commit
9c49b69f35
1 changed files with 30 additions and 30 deletions
|
@ -20,7 +20,7 @@ class Account::ActivityFeedDataTest < ActiveSupport::TestCase
|
|||
|
||||
activities = feed_data.entries_by_date
|
||||
day2_activity = find_activity_for_date(activities, @test_period_start + 1.day)
|
||||
|
||||
|
||||
assert_not_nil day2_activity
|
||||
trend = day2_activity.balance_trend
|
||||
assert_equal 1100, trend.current.amount.to_i # End of day 2
|
||||
|
@ -35,7 +35,7 @@ class Account::ActivityFeedDataTest < ActiveSupport::TestCase
|
|||
|
||||
activities = feed_data.entries_by_date
|
||||
day1_activity = find_activity_for_date(activities, @test_period_start)
|
||||
|
||||
|
||||
assert_not_nil day1_activity
|
||||
trend = day1_activity.balance_trend
|
||||
assert_equal 1000, trend.current.amount.to_i # End of first day
|
||||
|
@ -50,7 +50,7 @@ class Account::ActivityFeedDataTest < ActiveSupport::TestCase
|
|||
feed_data = Account::ActivityFeedData.new(@checking, entries)
|
||||
|
||||
activities = feed_data.entries_by_date
|
||||
|
||||
|
||||
# When day 2 balance is missing, both start and end use day 1 balance
|
||||
day2_activity = find_activity_for_date(activities, @test_period_start + 1.day)
|
||||
assert_not_nil day2_activity
|
||||
|
@ -70,7 +70,7 @@ class Account::ActivityFeedDataTest < ActiveSupport::TestCase
|
|||
activities = feed_data.entries_by_date
|
||||
# Use first day which has a transaction
|
||||
day1_activity = find_activity_for_date(activities, @test_period_start)
|
||||
|
||||
|
||||
assert_not_nil day1_activity
|
||||
trend = day1_activity.balance_trend
|
||||
assert_equal 0, trend.current.amount.to_i # Fallback to 0
|
||||
|
@ -85,16 +85,16 @@ class Account::ActivityFeedDataTest < ActiveSupport::TestCase
|
|||
|
||||
activities = feed_data.entries_by_date
|
||||
day3_activity = find_activity_for_date(activities, @test_period_start + 2.days)
|
||||
|
||||
|
||||
assert_not_nil day3_activity
|
||||
|
||||
|
||||
# Cash trend for day 3 (after foreign currency transaction)
|
||||
cash_trend = day3_activity.cash_balance_trend
|
||||
assert_equal 400, cash_trend.current.amount.to_i # End of day 3 cash balance
|
||||
assert_equal 500, cash_trend.previous.amount.to_i # End of day 2 cash balance
|
||||
assert_equal(-100, cash_trend.value.amount.to_i)
|
||||
assert_equal "down", cash_trend.direction.to_s
|
||||
|
||||
|
||||
# Holdings trend for day 3 (after trade)
|
||||
holdings_trend = day3_activity.holdings_value_trend
|
||||
assert_equal 1500, holdings_trend.current.amount.to_i # Total balance - cash balance
|
||||
|
@ -108,7 +108,7 @@ class Account::ActivityFeedDataTest < ActiveSupport::TestCase
|
|||
feed_data = Account::ActivityFeedData.new(@checking, entries)
|
||||
|
||||
activities = feed_data.entries_by_date
|
||||
|
||||
|
||||
# Day 2 has the transfer
|
||||
day2_activity = find_activity_for_date(activities, @test_period_start + 1.day)
|
||||
assert_not_nil day2_activity
|
||||
|
@ -126,10 +126,10 @@ class Account::ActivityFeedDataTest < ActiveSupport::TestCase
|
|||
feed_data = Account::ActivityFeedData.new(@investment, entries)
|
||||
|
||||
activities = feed_data.entries_by_date
|
||||
|
||||
|
||||
# Check that we get ActivityDateData objects
|
||||
assert activities.all? { |a| a.is_a?(Account::ActivityFeedData::ActivityDateData) }
|
||||
|
||||
|
||||
# Check that each ActivityDate has the required fields
|
||||
activities.each do |activity|
|
||||
assert_respond_to activity, :date
|
||||
|
@ -144,7 +144,7 @@ class Account::ActivityFeedDataTest < ActiveSupport::TestCase
|
|||
test "handles valuations correctly by summing entry changes" do
|
||||
# Create account with known balances
|
||||
account = @family.accounts.create!(name: "Test Investment", accountable: Investment.new, currency: "USD", balance: 0)
|
||||
|
||||
|
||||
# Day 1: Starting balance
|
||||
account.balances.create!(
|
||||
date: @test_period_start,
|
||||
|
@ -152,7 +152,7 @@ class Account::ActivityFeedDataTest < ActiveSupport::TestCase
|
|||
cash_balance: 1000,
|
||||
currency: "USD"
|
||||
)
|
||||
|
||||
|
||||
# Day 2: Add transactions, trades and a valuation
|
||||
account.balances.create!(
|
||||
date: @test_period_start + 1.day,
|
||||
|
@ -160,7 +160,7 @@ class Account::ActivityFeedDataTest < ActiveSupport::TestCase
|
|||
cash_balance: 1070, # Cash increased by transactions
|
||||
currency: "USD"
|
||||
)
|
||||
|
||||
|
||||
# Create transactions
|
||||
create_transaction(
|
||||
account: account,
|
||||
|
@ -174,7 +174,7 @@ class Account::ActivityFeedDataTest < ActiveSupport::TestCase
|
|||
amount: -20,
|
||||
name: "Interest payment"
|
||||
)
|
||||
|
||||
|
||||
# Create a trade
|
||||
create_trade(
|
||||
securities(:aapl),
|
||||
|
@ -183,28 +183,28 @@ class Account::ActivityFeedDataTest < ActiveSupport::TestCase
|
|||
date: @test_period_start + 1.day,
|
||||
price: 150 # 5 * 150 = 750
|
||||
)
|
||||
|
||||
|
||||
# Create valuation
|
||||
create_valuation(
|
||||
account: account,
|
||||
date: @test_period_start + 1.day,
|
||||
amount: 8500
|
||||
)
|
||||
|
||||
|
||||
entries = account.entries.includes(:entryable).to_a
|
||||
feed_data = Account::ActivityFeedData.new(account, entries)
|
||||
|
||||
|
||||
activities = feed_data.entries_by_date
|
||||
day2_activity = find_activity_for_date(activities, @test_period_start + 1.day)
|
||||
|
||||
|
||||
assert_not_nil day2_activity
|
||||
|
||||
|
||||
# Cash change should be $70 (50 + 20 from transactions only, not trades)
|
||||
assert_equal 70, day2_activity.cash_balance_trend.value.amount.to_i
|
||||
|
||||
|
||||
# Holdings change should be 750 (from the trade)
|
||||
assert_equal 750, day2_activity.holdings_value_trend.value.amount.to_i
|
||||
|
||||
|
||||
# Total balance change
|
||||
assert_in_delta 1178.44, day2_activity.balance_trend.value.amount.to_f, 0.01
|
||||
end
|
||||
|
@ -212,7 +212,7 @@ class Account::ActivityFeedDataTest < ActiveSupport::TestCase
|
|||
test "normalizes multi-currency entries on valuation days" do
|
||||
# Create EUR account
|
||||
eur_account = @family.accounts.create!(name: "EUR Investment", accountable: Investment.new, currency: "EUR", balance: 0)
|
||||
|
||||
|
||||
# Day 1: Starting balance
|
||||
eur_account.balances.create!(
|
||||
date: @test_period_start,
|
||||
|
@ -220,7 +220,7 @@ class Account::ActivityFeedDataTest < ActiveSupport::TestCase
|
|||
cash_balance: 500,
|
||||
currency: "EUR"
|
||||
)
|
||||
|
||||
|
||||
# Day 2: Multi-currency transactions and valuation
|
||||
eur_account.balances.create!(
|
||||
date: @test_period_start + 1.day,
|
||||
|
@ -228,7 +228,7 @@ class Account::ActivityFeedDataTest < ActiveSupport::TestCase
|
|||
cash_balance: 600,
|
||||
currency: "EUR"
|
||||
)
|
||||
|
||||
|
||||
# Create USD transaction (should be converted to EUR)
|
||||
create_transaction(
|
||||
account: eur_account,
|
||||
|
@ -237,7 +237,7 @@ class Account::ActivityFeedDataTest < ActiveSupport::TestCase
|
|||
currency: "USD",
|
||||
name: "USD Payment"
|
||||
)
|
||||
|
||||
|
||||
# Create exchange rate: 1 USD = 0.9 EUR
|
||||
ExchangeRate.create!(
|
||||
date: @test_period_start + 1.day,
|
||||
|
@ -245,22 +245,22 @@ class Account::ActivityFeedDataTest < ActiveSupport::TestCase
|
|||
to_currency: "EUR",
|
||||
rate: 0.9
|
||||
)
|
||||
|
||||
|
||||
# Create valuation
|
||||
create_valuation(
|
||||
account: eur_account,
|
||||
date: @test_period_start + 1.day,
|
||||
amount: 2000
|
||||
)
|
||||
|
||||
|
||||
entries = eur_account.entries.includes(:entryable).to_a
|
||||
feed_data = Account::ActivityFeedData.new(eur_account, entries)
|
||||
|
||||
|
||||
activities = feed_data.entries_by_date
|
||||
day2_activity = find_activity_for_date(activities, @test_period_start + 1.day)
|
||||
|
||||
|
||||
assert_not_nil day2_activity
|
||||
|
||||
|
||||
# Cash change should be 90 EUR (100 USD * 0.9)
|
||||
# The transaction is -100 USD, which becomes +100 when inverted, then 100 * 0.9 = 90 EUR
|
||||
assert_equal 90, day2_activity.cash_balance_trend.value.amount.to_i
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue