mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-19 13:19:39 +02:00
Multi-step account forms + clearer balance editing (#2427)
* Initial multi-step property form * Improve form structure, add optional tooltip help icons to form fields * Add basic inline alert component * Clean up and improve property form lifecycle * Implement Account status concept * Lint fixes * Remove whitespace * Balance editing, scope updates for account * Passing tests * Fix brakeman warning * Remove stale columns * data constraint tweaks * Redundant property
This commit is contained in:
parent
ba7e8d3893
commit
662f2c04ce
66 changed files with 1036 additions and 427 deletions
|
@ -81,7 +81,7 @@ end
|
|||
test "should only return active accounts" do
|
||||
# Make one account inactive
|
||||
inactive_account = accounts(:depository)
|
||||
inactive_account.update!(is_active: false)
|
||||
inactive_account.disable!
|
||||
|
||||
access_token = Doorkeeper::AccessToken.create!(
|
||||
application: @oauth_app,
|
||||
|
|
|
@ -8,72 +8,169 @@ class PropertiesControllerTest < ActionDispatch::IntegrationTest
|
|||
@account = accounts(:property)
|
||||
end
|
||||
|
||||
test "creates with property details" do
|
||||
assert_difference -> { Account.count } => 1,
|
||||
-> { Property.count } => 1,
|
||||
-> { Valuation.count } => 2,
|
||||
-> { Entry.count } => 2 do
|
||||
test "creates property in draft status and redirects to balances step" do
|
||||
assert_difference -> { Account.count } => 1 do
|
||||
post properties_path, params: {
|
||||
account: {
|
||||
name: "Property",
|
||||
balance: 500000,
|
||||
currency: "USD",
|
||||
name: "New Property",
|
||||
subtype: "house",
|
||||
accountable_type: "Property",
|
||||
accountable_attributes: {
|
||||
year_built: 2002,
|
||||
area_value: 1000,
|
||||
area_unit: "sqft",
|
||||
address_attributes: {
|
||||
line1: "123 Main St",
|
||||
line2: "Apt 1",
|
||||
locality: "Los Angeles",
|
||||
region: "CA", # ISO3166-2 code
|
||||
country: "US", # ISO3166-1 Alpha-2 code
|
||||
postal_code: "90001"
|
||||
}
|
||||
year_built: 1990,
|
||||
area_value: 1200,
|
||||
area_unit: "sqft"
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
created_account = Account.order(:created_at).last
|
||||
|
||||
assert created_account.accountable.year_built.present?
|
||||
assert created_account.accountable.address.line1.present?
|
||||
|
||||
assert_redirected_to created_account
|
||||
assert_equal "Property account created", flash[:notice]
|
||||
assert_enqueued_with(job: SyncJob)
|
||||
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)
|
||||
end
|
||||
|
||||
test "updates with property details" do
|
||||
test "updates property overview" do
|
||||
assert_no_difference [ "Account.count", "Property.count" ] do
|
||||
patch account_path(@account), params: {
|
||||
patch property_path(@account), params: {
|
||||
account: {
|
||||
name: "Updated Property",
|
||||
balance: 500000,
|
||||
currency: "USD",
|
||||
accountable_type: "Property",
|
||||
accountable_attributes: {
|
||||
id: @account.accountable_id,
|
||||
year_built: 2002,
|
||||
area_value: 1000,
|
||||
area_unit: "sqft",
|
||||
address_attributes: {
|
||||
line1: "123 Main St",
|
||||
line2: "Apt 1",
|
||||
locality: "Los Angeles",
|
||||
region: "CA", # ISO3166-2 code
|
||||
country: "US", # ISO3166-1 Alpha-2 code
|
||||
postal_code: "90001"
|
||||
}
|
||||
}
|
||||
subtype: "condo"
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
assert_redirected_to @account
|
||||
assert_equal "Property account updated", flash[:notice]
|
||||
assert_enqueued_with(job: SyncJob)
|
||||
@account.reload
|
||||
assert_equal "Updated Property", @account.name
|
||||
assert_equal "condo", @account.subtype
|
||||
|
||||
# If account is active, it renders edit view; otherwise redirects to balances
|
||||
if @account.active?
|
||||
assert_response :success
|
||||
else
|
||||
assert_redirected_to balances_property_path(@account)
|
||||
end
|
||||
end
|
||||
|
||||
# Tab view tests
|
||||
test "shows balances tab" do
|
||||
get balances_property_path(@account)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "shows address tab" do
|
||||
get address_property_path(@account)
|
||||
assert_response :success
|
||||
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: {
|
||||
account: {
|
||||
balance: 600000,
|
||||
currency: "EUR"
|
||||
}
|
||||
}
|
||||
|
||||
# If account is active, it renders balances view; otherwise redirects to address
|
||||
if @account.reload.active?
|
||||
assert_response :success
|
||||
else
|
||||
assert_redirected_to address_property_path(@account)
|
||||
end
|
||||
end
|
||||
|
||||
test "updates address tab" do
|
||||
patch update_address_property_path(@account), params: {
|
||||
property: {
|
||||
address_attributes: {
|
||||
line1: "456 New Street",
|
||||
locality: "San Francisco",
|
||||
region: "CA",
|
||||
country: "US",
|
||||
postal_code: "94102"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@account.reload
|
||||
assert_equal "456 New Street", @account.accountable.address.line1
|
||||
assert_equal "San Francisco", @account.accountable.address.locality
|
||||
|
||||
# If account is draft, it activates and redirects; otherwise renders address
|
||||
if @account.draft?
|
||||
assert_redirected_to account_path(@account)
|
||||
else
|
||||
assert_response :success
|
||||
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)
|
||||
|
||||
patch update_address_property_path(@account), params: {
|
||||
property: {
|
||||
address_attributes: {
|
||||
line1: "123 Test St"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert_response :unprocessable_entity
|
||||
end
|
||||
|
||||
test "address update activates draft account" do
|
||||
# Create a draft property account
|
||||
draft_account = Account.create!(
|
||||
family: @user.family,
|
||||
name: "Draft Property",
|
||||
accountable: Property.new,
|
||||
status: "draft",
|
||||
balance: 500000,
|
||||
currency: "USD"
|
||||
)
|
||||
|
||||
assert draft_account.draft?
|
||||
|
||||
patch update_address_property_path(draft_account), params: {
|
||||
property: {
|
||||
address_attributes: {
|
||||
line1: "789 Activate St",
|
||||
locality: "New York",
|
||||
region: "NY",
|
||||
country: "US",
|
||||
postal_code: "10001"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
draft_account.reload
|
||||
assert draft_account.active?
|
||||
assert_redirected_to account_path(draft_account)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -8,35 +8,24 @@ class ValuationsControllerTest < ActionDispatch::IntegrationTest
|
|||
@entry = entries(:valuation)
|
||||
end
|
||||
|
||||
test "error when valuation already exists for date" do
|
||||
assert_no_difference [ "Entry.count", "Valuation.count" ] do
|
||||
post valuations_url(@entry.account), params: {
|
||||
entry: {
|
||||
account_id: @entry.account_id,
|
||||
amount: 19800,
|
||||
date: @entry.date,
|
||||
currency: "USD"
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
assert_response :unprocessable_entity
|
||||
end
|
||||
|
||||
test "creates entry with basic attributes" do
|
||||
account = accounts(:investment)
|
||||
|
||||
assert_difference [ "Entry.count", "Valuation.count" ], 1 do
|
||||
post valuations_url, params: {
|
||||
entry: {
|
||||
name: "New entry",
|
||||
amount: 10000,
|
||||
amount: account.balance + 100,
|
||||
currency: "USD",
|
||||
date: Date.current,
|
||||
account_id: @entry.account_id
|
||||
date: Date.current.to_s,
|
||||
account_id: account.id
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
created_entry = Entry.order(created_at: :desc).first
|
||||
assert_equal "Manual account value update", created_entry.name
|
||||
assert_equal Date.current, created_entry.date
|
||||
assert_equal account.balance + 100, created_entry.amount_money.to_f
|
||||
|
||||
assert_enqueued_with job: SyncJob
|
||||
|
||||
|
@ -47,7 +36,6 @@ class ValuationsControllerTest < ActionDispatch::IntegrationTest
|
|||
assert_no_difference [ "Entry.count", "Valuation.count" ] do
|
||||
patch valuation_url(@entry), params: {
|
||||
entry: {
|
||||
name: "Updated entry",
|
||||
amount: 20000,
|
||||
currency: "USD",
|
||||
date: Date.current
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue