1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-30 02:29:39 +02:00
Maybe/test/models/account/syncable_test.rb
Zach Gollwitzer dbf575c02a
Basic Account Balance Sync Algorithm (#501)
* Sketch out sync interface

* Add basic account sync algorithm

* Update logic for final balance in series

* Remove start_date concept

* Clean up tests

* Improve clarity of test

* Update app/models/account.rb

Co-authored-by: Rob Zolkos <rob@zolkos.com>
Signed-off-by: Zach Gollwitzer <zach.gollwitzer@gmail.com>

* Update app/models/transaction.rb

Co-authored-by: Rob Zolkos <rob@zolkos.com>
Signed-off-by: Zach Gollwitzer <zach.gollwitzer@gmail.com>

* Update app/models/valuation.rb

Co-authored-by: Rob Zolkos <rob@zolkos.com>
Signed-off-by: Zach Gollwitzer <zach.gollwitzer@gmail.com>

* Re-organize code, simplify job interface

* Consolidate balance calculations

* More cleanup

---------

Signed-off-by: Zach Gollwitzer <zach.gollwitzer@gmail.com>
Co-authored-by: Rob Zolkos <rob@zolkos.com>
2024-02-29 08:32:52 -05:00

32 lines
1.1 KiB
Ruby

require "test_helper"
class Account::SyncableTest < ActiveSupport::TestCase
test "account has no balances until synced" do
account = accounts(:savings_with_valuation_overrides)
account.accountable = account_depositories(:savings)
assert_equal 0, account.balances.count
end
test "account has balances after syncing" do
account = accounts(:savings_with_valuation_overrides)
account.accountable = account_depositories(:savings)
account.sync
assert_equal 31, account.balances.count
end
test "stale balances are purged after syncing" do
account = accounts(:savings_with_valuation_overrides)
account.accountable = account_depositories(:savings)
# Create old, stale balances that should be purged (since they are before account start date)
account.balances.create!(date: 1.year.ago, balance: 1000)
account.balances.create!(date: 2.years.ago, balance: 2000)
account.balances.create!(date: 3.years.ago, balance: 3000)
account.sync
assert_equal 31, account.balances.count
end
end