mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-06 05:55:21 +02:00
Migrate valuations controller to new reconciliation methods
This commit is contained in:
parent
25f0c78c47
commit
d80cb9f812
19 changed files with 187 additions and 171 deletions
|
@ -38,7 +38,7 @@ class ValuationsControllerTest < ActionDispatch::IntegrationTest
|
|||
entry: {
|
||||
amount: 20000,
|
||||
currency: "USD",
|
||||
date: Date.current
|
||||
date: @entry.date
|
||||
}
|
||||
}
|
||||
end
|
||||
|
|
|
@ -4,7 +4,7 @@ module EntryableResourceInterfaceTest
|
|||
extend ActiveSupport::Testing::Declarative
|
||||
|
||||
test "shows new form" do
|
||||
get new_polymorphic_url(@entry.entryable)
|
||||
get new_polymorphic_url(@entry.entryable, account_id: @entry.account_id)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
|
|
|
@ -30,6 +30,7 @@ class Account::OverviewFormTest < ActiveSupport::TestCase
|
|||
)
|
||||
|
||||
@account.expects(:update!).with(name: "New Property Name").once
|
||||
@account.expects(:lock_attr!).with(:name).once
|
||||
@account.expects(:sync_later).never # Name change should not trigger sync
|
||||
|
||||
result = form.save
|
||||
|
@ -84,6 +85,7 @@ class Account::OverviewFormTest < ActiveSupport::TestCase
|
|||
|
||||
# Simulate a validation error on opening balance update
|
||||
@account.expects(:update!).with(name: "New Name").once
|
||||
@account.expects(:lock_attr!).with(:name).once
|
||||
@account.expects(:set_or_update_opening_balance!).raises(Account::Reconcileable::InvalidBalanceError.new("Cash balance cannot exceed balance"))
|
||||
@account.expects(:sync_later).never # Should NOT sync if any update fails
|
||||
|
||||
|
|
|
@ -6,16 +6,9 @@ class Account::ReconcileableTest < ActiveSupport::TestCase
|
|||
@family = families(:dylan_family)
|
||||
end
|
||||
|
||||
# Currency updates earn their own method because updating an account currency incurs
|
||||
# side effects like recalculating balances, etc.
|
||||
test "can update the account currency" do
|
||||
@account.update_currency!("EUR")
|
||||
|
||||
assert_equal "EUR", @account.currency
|
||||
assert_equal "EUR", @account.entries.valuations.first.currency
|
||||
end
|
||||
|
||||
# If a user has an opening balance (valuation) for their manual account and has 1+ transactions, the intent of
|
||||
# Scope: Depository Only
|
||||
#
|
||||
# If a user has an opening balance (valuation) for their manual *Depository* account and has 1+ transactions, the intent of
|
||||
# "updating current balance" typically means that their start balance is incorrect. We follow that user intent
|
||||
# by default and find the delta required, and update the opening balance so that the timeline reflects this current balance
|
||||
#
|
||||
|
|
|
@ -31,4 +31,13 @@ class AccountTest < ActiveSupport::TestCase
|
|||
assert_equal "Investments", account.short_subtype_label
|
||||
assert_equal "Investments", account.long_subtype_label
|
||||
end
|
||||
|
||||
# Currency updates earn their own method because updating an account currency incurs
|
||||
# side effects like recalculating balances, etc.
|
||||
test "can update the account currency" do
|
||||
@account.update_currency!("EUR")
|
||||
|
||||
assert_equal "EUR", @account.currency
|
||||
assert_equal "EUR", @account.entries.valuations.first.currency
|
||||
end
|
||||
end
|
||||
|
|
|
@ -23,20 +23,22 @@ class AccountsTest < ApplicationSystemTestCase
|
|||
end
|
||||
|
||||
test "can create property account" do
|
||||
# Step 1: Select property type and enter basic details
|
||||
# Step 1: Enter basic property details
|
||||
click_link "Property"
|
||||
|
||||
account_name = "[system test] Property Account"
|
||||
fill_in "Name*", with: account_name
|
||||
select "Single Family Home", from: "Property type*"
|
||||
fill_in "Year Built (optional)", with: 2005
|
||||
fill_in "Area (optional)", with: 2250
|
||||
fill_in "Name", with: account_name
|
||||
fill_in "account[current_estimated_value]", with: 500000
|
||||
fill_in "account[purchase_price]", with: 450000
|
||||
fill_in "account[purchase_date]", with: "01/15/2020"
|
||||
|
||||
click_button "Next"
|
||||
|
||||
# Step 2: Enter balance information
|
||||
assert_text "Value"
|
||||
fill_in "account[balance]", with: 500000
|
||||
# Step 2: Enter property details
|
||||
assert_text "Property type"
|
||||
select "Single Family Home", from: "Property type"
|
||||
fill_in "Year built", with: 2005
|
||||
fill_in "Area", with: 2250
|
||||
click_button "Next"
|
||||
|
||||
# Step 3: Enter address information
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue