mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-29 18:19:39 +02:00
Update properties controller to use new creational and update balance methods
This commit is contained in:
parent
d459ebdad8
commit
25f0c78c47
17 changed files with 500 additions and 144 deletions
|
@ -8,18 +8,15 @@ class PropertiesControllerTest < ActionDispatch::IntegrationTest
|
|||
@account = accounts(:property)
|
||||
end
|
||||
|
||||
test "creates property in draft status and redirects to balances step" do
|
||||
test "creates property in draft status with initial balance information and redirects to details step" do
|
||||
assert_difference -> { Account.count } => 1 do
|
||||
post properties_path, params: {
|
||||
account: {
|
||||
name: "New Property",
|
||||
subtype: "house",
|
||||
accountable_type: "Property",
|
||||
accountable_attributes: {
|
||||
year_built: 1990,
|
||||
area_value: 1200,
|
||||
area_unit: "sqft"
|
||||
}
|
||||
purchase_price: "250000",
|
||||
purchase_date: "2023-01-01",
|
||||
current_estimated_value: "300000",
|
||||
currency: "USD"
|
||||
}
|
||||
}
|
||||
end
|
||||
|
@ -27,38 +24,47 @@ class PropertiesControllerTest < ActionDispatch::IntegrationTest
|
|||
created_account = Account.order(:created_at).last
|
||||
assert created_account.accountable.is_a?(Property)
|
||||
assert_equal "draft", created_account.status
|
||||
assert_equal 0, created_account.balance
|
||||
assert_equal 1990, created_account.accountable.year_built
|
||||
assert_equal 1200, created_account.accountable.area_value
|
||||
assert_equal "sqft", created_account.accountable.area_unit
|
||||
assert_redirected_to balances_property_path(created_account)
|
||||
assert_equal "New Property", created_account.name
|
||||
assert_equal 300_000, created_account.balance
|
||||
assert_equal 0, created_account.cash_balance
|
||||
assert_equal "USD", created_account.currency
|
||||
|
||||
# Check opening balance was set
|
||||
opening_valuation = created_account.valuations.opening_anchor.first
|
||||
assert_not_nil opening_valuation
|
||||
assert_equal 250_000, opening_valuation.balance
|
||||
assert_equal Date.parse("2023-01-01"), opening_valuation.entry.date
|
||||
|
||||
assert_redirected_to details_property_path(created_account)
|
||||
end
|
||||
|
||||
test "updates property overview" do
|
||||
test "updates property overview with balance information" do
|
||||
assert_no_difference [ "Account.count", "Property.count" ] do
|
||||
patch property_path(@account), params: {
|
||||
account: {
|
||||
name: "Updated Property",
|
||||
subtype: "condo"
|
||||
current_estimated_value: "350000",
|
||||
currency: "USD"
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
@account.reload
|
||||
assert_equal "Updated Property", @account.name
|
||||
assert_equal "condo", @account.subtype
|
||||
assert_equal 350_000, @account.balance
|
||||
assert_equal 0, @account.cash_balance
|
||||
|
||||
# If account is active, it renders edit view; otherwise redirects to balances
|
||||
# If account is active, it renders edit view; otherwise redirects to details
|
||||
if @account.active?
|
||||
assert_response :success
|
||||
else
|
||||
assert_redirected_to balances_property_path(@account)
|
||||
assert_redirected_to details_property_path(@account)
|
||||
end
|
||||
end
|
||||
|
||||
# Tab view tests
|
||||
test "shows balances tab" do
|
||||
get balances_property_path(@account)
|
||||
test "shows details tab" do
|
||||
get details_property_path(@account)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
|
@ -68,22 +74,26 @@ class PropertiesControllerTest < ActionDispatch::IntegrationTest
|
|||
end
|
||||
|
||||
# Tab update tests
|
||||
test "updates balances tab" do
|
||||
original_balance = @account.balance
|
||||
|
||||
# Mock the update_balance method to return a successful result
|
||||
Account::BalanceUpdater::Result.any_instance.stubs(:success?).returns(true)
|
||||
Account::BalanceUpdater::Result.any_instance.stubs(:updated?).returns(true)
|
||||
|
||||
patch update_balances_property_path(@account), params: {
|
||||
test "updates property details" do
|
||||
patch update_details_property_path(@account), params: {
|
||||
account: {
|
||||
balance: 600000,
|
||||
currency: "EUR"
|
||||
subtype: "condo",
|
||||
accountable_attributes: {
|
||||
year_built: 2005,
|
||||
area_value: 1500,
|
||||
area_unit: "sqft"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# If account is active, it renders balances view; otherwise redirects to address
|
||||
if @account.reload.active?
|
||||
@account.reload
|
||||
assert_equal "condo", @account.subtype
|
||||
assert_equal 2005, @account.accountable.year_built
|
||||
assert_equal 1500, @account.accountable.area_value
|
||||
assert_equal "sqft", @account.accountable.area_unit
|
||||
|
||||
# If account is active, it renders details view; otherwise redirects to address
|
||||
if @account.active?
|
||||
assert_response :success
|
||||
else
|
||||
assert_redirected_to address_property_path(@account)
|
||||
|
@ -115,20 +125,6 @@ class PropertiesControllerTest < ActionDispatch::IntegrationTest
|
|||
end
|
||||
end
|
||||
|
||||
test "balances update handles validation errors" do
|
||||
# Mock update_balance to return a failure result
|
||||
Account::BalanceUpdater::Result.any_instance.stubs(:success?).returns(false)
|
||||
Account::BalanceUpdater::Result.any_instance.stubs(:error_message).returns("Invalid balance")
|
||||
|
||||
patch update_balances_property_path(@account), params: {
|
||||
account: {
|
||||
balance: 600000,
|
||||
currency: "EUR"
|
||||
}
|
||||
}
|
||||
|
||||
assert_response :unprocessable_entity
|
||||
end
|
||||
|
||||
test "address update handles validation errors" do
|
||||
Property.any_instance.stubs(:update).returns(false)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue