mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-05 05:25:24 +02:00
Multi-Currency Part 2 (#543)
* Support all currencies, handle outside DB * Remove currencies from seed * Fix account balance namespace * Set default currency on authentication * Cache currency instances * Implement multi-currency syncs with tests * Series fallback, passing tests * Fix conflicts * Make value group concrete class that works with currency values * Fix migration conflict * Update tests to expect multi-currency results * Update account list to use group method * Namespace updates * Fetch unknown exchange rates from API * Fix date range bug * Ensure demo data works without external API * Enforce cascades only at DB level
This commit is contained in:
parent
de0cba9fed
commit
110855d077
55 changed files with 1226 additions and 714 deletions
|
@ -8,6 +8,17 @@ class FamilyTest < ActiveSupport::TestCase
|
|||
@family.accounts.each do |account|
|
||||
account.sync
|
||||
end
|
||||
|
||||
# See this Google Sheet for calculations and expected results for dylan_family:
|
||||
# https://docs.google.com/spreadsheets/d/18LN5N-VLq4b49Mq1fNwF7_eBiHSQB46qQduRtdAEN98/edit?usp=sharing
|
||||
@expected_snapshots = CSV.read("test/fixtures/family/expected_snapshots.csv", headers: true).map do |row|
|
||||
{
|
||||
"date" => (Date.current + row["date_offset"].to_i.days).to_date,
|
||||
"net_worth" => row["net_worth"],
|
||||
"assets" => row["assets"],
|
||||
"liabilities" => row["liabilities"]
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
test "should have many users" do
|
||||
|
@ -38,45 +49,37 @@ class FamilyTest < ActiveSupport::TestCase
|
|||
end
|
||||
|
||||
test "should calculate total assets" do
|
||||
assert_equal Money.new(25550), @family.assets_money
|
||||
expected = @expected_snapshots.last["assets"].to_d
|
||||
assert_equal Money.new(expected), @family.assets
|
||||
end
|
||||
|
||||
test "should calculate total liabilities" do
|
||||
assert_equal Money.new(1000), @family.liabilities_money
|
||||
expected = @expected_snapshots.last["liabilities"].to_d
|
||||
assert_equal Money.new(expected), @family.liabilities
|
||||
end
|
||||
|
||||
test "should calculate net worth" do
|
||||
assert_equal Money.new(24550), @family.net_worth_money
|
||||
expected = @expected_snapshots.last["net_worth"].to_d
|
||||
assert_equal Money.new(expected), @family.net_worth
|
||||
end
|
||||
|
||||
test "should calculate snapshot correctly" do
|
||||
# See this Google Sheet for calculations and expected results for dylan_family:
|
||||
# https://docs.google.com/spreadsheets/d/18LN5N-VLq4b49Mq1fNwF7_eBiHSQB46qQduRtdAEN98/edit?usp=sharing
|
||||
expected_snapshots = CSV.read("test/fixtures/family/expected_snapshots.csv", headers: true).map do |row|
|
||||
{
|
||||
"date" => (Date.current + row["date_offset"].to_i.days).to_date,
|
||||
"net_worth" => row["net_worth"],
|
||||
"assets" => row["assets"],
|
||||
"liabilities" => row["liabilities"]
|
||||
}
|
||||
end
|
||||
|
||||
asset_series = @family.snapshot[:asset_series]
|
||||
liability_series = @family.snapshot[:liability_series]
|
||||
net_worth_series = @family.snapshot[:net_worth_series]
|
||||
|
||||
assert_equal expected_snapshots.count, asset_series.values.count
|
||||
assert_equal expected_snapshots.count, liability_series.values.count
|
||||
assert_equal expected_snapshots.count, net_worth_series.values.count
|
||||
assert_equal @expected_snapshots.count, asset_series.values.count
|
||||
assert_equal @expected_snapshots.count, liability_series.values.count
|
||||
assert_equal @expected_snapshots.count, net_worth_series.values.count
|
||||
|
||||
expected_snapshots.each_with_index do |row, index|
|
||||
@expected_snapshots.each_with_index do |row, index|
|
||||
expected_assets = TimeSeries::Value.new(date: row["date"], value: Money.new(row["assets"].to_d))
|
||||
expected_liabilities = TimeSeries::Value.new(date: row["date"], value: Money.new(row["liabilities"].to_d))
|
||||
expected_net_worth = TimeSeries::Value.new(date: row["date"], value: Money.new(row["net_worth"].to_d))
|
||||
|
||||
assert_equal expected_assets, asset_series.values[index]
|
||||
assert_equal expected_liabilities, liability_series.values[index]
|
||||
assert_equal expected_net_worth, net_worth_series.values[index]
|
||||
assert_in_delta expected_assets.value.amount, Money.new(asset_series.values[index].value).amount, 0.01
|
||||
assert_in_delta expected_liabilities.value.amount, Money.new(liability_series.values[index].value).amount, 0.01
|
||||
assert_in_delta expected_net_worth.value.amount, Money.new(net_worth_series.values[index].value).amount, 0.01
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue