1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-24 07:39:39 +02:00
Maybe/test/controllers/loans_controller_test.rb
Zach Gollwitzer c1d98fe73b
Some checks are pending
Publish Docker image / ci (push) Waiting to run
Publish Docker image / Build docker image (push) Blocked by required conditions
Start and end balance anchors for historical account balances (#2455)
* Add kind field to valuation

* Fix schema conflict

* Add kind to valuation

* Scaffold opening balance manager

* Opening balance manager implementation

* Update account import to use opening balance manager + tests

* Update account to use opening balance manager

* Fix test assertions, usage of current balance manager

* Lint fixes

* Add Opening Balance manager, add tests to forward calculator

* Add credit card to "all cash" designation

* Simplify valuation model

* Add current balance manager with tests

* Add current balance logic to reverse calculator and plaid sync

* Tweaks to initial calc logic

* Ledger testing helper, tweak assertions for reverse calculator

* Update test assertions

* Extract balance transformer, simplify calculators

* Algo simplifications

* Final tweaks to calculators

* Cleanup

* Fix error, propagate sync errors up to parent

* Update migration script, valuation naming
2025-07-15 11:42:41 -04:00

79 lines
2.3 KiB
Ruby

require "test_helper"
class LoansControllerTest < ActionDispatch::IntegrationTest
include AccountableResourceInterfaceTest
setup do
sign_in @user = users(:family_admin)
@account = accounts(:loan)
end
test "creates with loan details" do
assert_difference -> { Account.count } => 1,
-> { Loan.count } => 1,
-> { Valuation.count } => 1,
-> { Entry.count } => 1 do
post loans_path, params: {
account: {
name: "New Loan",
balance: 50000,
currency: "USD",
accountable_type: "Loan",
accountable_attributes: {
interest_rate: 5.5,
term_months: 60,
rate_type: "fixed",
initial_balance: 50000
}
}
}
end
created_account = Account.order(:created_at).last
assert_equal "New Loan", created_account.name
assert_equal 50000, created_account.balance
assert_equal "USD", created_account.currency
assert_equal 5.5, created_account.accountable.interest_rate
assert_equal 60, created_account.accountable.term_months
assert_equal "fixed", created_account.accountable.rate_type
assert_equal 50000, created_account.accountable.initial_balance
assert_redirected_to created_account
assert_equal "Loan account created", flash[:notice]
assert_enqueued_with(job: SyncJob)
end
test "updates with loan details" do
assert_no_difference [ "Account.count", "Loan.count" ] do
patch account_path(@account), params: {
account: {
name: "Updated Loan",
balance: 45000,
currency: "USD",
accountable_type: "Loan",
accountable_attributes: {
id: @account.accountable_id,
interest_rate: 4.5,
term_months: 48,
rate_type: "fixed",
initial_balance: 48000
}
}
}
end
@account.reload
assert_equal "Updated Loan", @account.name
assert_equal 45000, @account.balance
assert_equal 4.5, @account.accountable.interest_rate
assert_equal 48, @account.accountable.term_months
assert_equal "fixed", @account.accountable.rate_type
assert_equal 48000, @account.accountable.initial_balance
assert_redirected_to @account
assert_equal "Loan account updated", flash[:notice]
assert_enqueued_with(job: SyncJob)
end
end