1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-24 15:49:39 +02:00

Account Activity View + Account Forms (#1406)
Some checks are pending
Publish Docker image / ci (push) Waiting to run
Publish Docker image / Build docker image (push) Blocked by required conditions

* Remove balance mode, sketch out refactor

* Activity view checkpoint

* Entry partials, checkpoint

* Finish txn partial

* Give entries context when editing for different turbo responses

* Calculate change of balance for each entry

* Account tabs consolidation

* Translations, linting, brakeman updates

* Account actions concern

* Finalize forms, get account system tests passing

* Get tests passing

* Lint, rubocop, schema updates

* Improve routing and stream responses

* Fix broken routes

* Add import option for adding accounts

* Fix system test

* Fix test specificity

* Fix sparklines

* Improve account redirects
This commit is contained in:
Zach Gollwitzer 2024-11-04 20:27:31 -05:00 committed by GitHub
parent 12e4f1067d
commit 65db49273c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
216 changed files with 2043 additions and 1620 deletions

View file

@ -32,7 +32,7 @@ class Account::TradesControllerTest < ActionDispatch::IntegrationTest
}
end
assert_redirected_to account_path(@entry.account)
assert_redirected_to @entry.account
end
test "creates withdrawal entry" do
@ -51,7 +51,7 @@ class Account::TradesControllerTest < ActionDispatch::IntegrationTest
}
end
assert_redirected_to account_path(@entry.account)
assert_redirected_to @entry.account
end
test "deposit and withdrawal has optional transfer account" do
@ -71,7 +71,7 @@ class Account::TradesControllerTest < ActionDispatch::IntegrationTest
assert created_entry.amount.positive?
assert created_entry.marked_as_transfer
assert_redirected_to account_path(@entry.account)
assert_redirected_to @entry.account
end
test "creates interest entry" do
@ -88,7 +88,7 @@ class Account::TradesControllerTest < ActionDispatch::IntegrationTest
created_entry = Account::Entry.order(created_at: :desc).first
assert created_entry.amount.negative?
assert_redirected_to account_path(@entry.account)
assert_redirected_to @entry.account
end
test "creates trade buy entry" do
@ -110,7 +110,7 @@ class Account::TradesControllerTest < ActionDispatch::IntegrationTest
assert created_entry.account_trade.qty.positive?
assert_equal "Transaction created successfully.", flash[:notice]
assert_enqueued_with job: AccountSyncJob
assert_redirected_to account_path(@entry.account)
assert_redirected_to @entry.account
end
test "creates trade sell entry" do
@ -133,6 +133,6 @@ class Account::TradesControllerTest < ActionDispatch::IntegrationTest
assert created_entry.account_trade.qty.negative?
assert_equal "Transaction created successfully.", flash[:notice]
assert_enqueued_with job: AccountSyncJob
assert_redirected_to account_path(@entry.account)
assert_redirected_to @entry.account
end
end

View file

@ -26,7 +26,7 @@ class Account::TransfersControllerTest < ActionDispatch::IntegrationTest
end
test "can destroy transfer" do
assert_difference -> { Account::Transfer.count } => -1, -> { Account::Transaction.count } => 0 do
assert_difference -> { Account::Transfer.count } => -1, -> { Account::Transaction.count } => -2 do
delete account_transfer_url(account_transfers(:one))
end
end

View file

@ -45,6 +45,6 @@ class Account::ValuationsControllerTest < ActionDispatch::IntegrationTest
end
assert_equal "Date has already been taken", flash[:alert]
assert_redirected_to account_path(@entry.account)
assert_redirected_to @entry.account
end
end

View file

@ -20,11 +20,6 @@ class AccountsControllerTest < ActionDispatch::IntegrationTest
assert_response :ok
end
test "show" do
get account_path(@account)
assert_response :ok
end
test "can sync an account" do
post sync_account_path(@account)
assert_response :no_content
@ -35,86 +30,4 @@ class AccountsControllerTest < ActionDispatch::IntegrationTest
assert_redirected_to accounts_url
assert_equal "Successfully queued accounts for syncing.", flash[:notice]
end
test "should update account" do
patch account_url(@account), params: {
account: {
name: "Updated name",
is_active: "0",
institution_id: institutions(:chase).id
}
}
assert_redirected_to account_url(@account)
assert_enqueued_with job: AccountSyncJob
assert_equal "Account updated", flash[:notice]
end
test "updates account balance by creating new valuation" do
assert_difference [ "Account::Entry.count", "Account::Valuation.count" ], 1 do
patch account_url(@account), params: {
account: {
balance: 10000
}
}
end
assert_redirected_to account_url(@account)
assert_enqueued_with job: AccountSyncJob
assert_equal "Account updated", flash[:notice]
end
test "updates account balance by editing existing valuation for today" do
@account.entries.create! date: Date.current, amount: 6000, currency: "USD", entryable: Account::Valuation.new
assert_no_difference [ "Account::Entry.count", "Account::Valuation.count" ] do
patch account_url(@account), params: {
account: {
balance: 10000
}
}
end
assert_redirected_to account_url(@account)
assert_enqueued_with job: AccountSyncJob
assert_equal "Account updated", flash[:notice]
end
test "should create an account" do
assert_difference [ "Account.count", "Account::Valuation.count", "Account::Entry.count" ], 1 do
post accounts_path, params: {
account: {
name: "Test",
accountable_type: "Depository",
balance: 200,
currency: "USD",
subtype: "checking",
institution_id: institutions(:chase).id
}
}
assert_equal "New account created successfully", flash[:notice]
assert_redirected_to account_url(Account.order(:created_at).last)
end
end
test "can add optional start date and balance to an account on create" do
assert_difference -> { Account.count } => 1, -> { Account::Valuation.count } => 2 do
post accounts_path, params: {
account: {
name: "Test",
accountable_type: "Depository",
balance: 200,
currency: "USD",
subtype: "checking",
institution_id: institutions(:chase).id,
start_balance: 100,
start_date: 10.days.ago
}
}
assert_equal "New account created successfully", flash[:notice]
assert_redirected_to account_url(Account.order(:created_at).last)
end
end
end

View file

@ -1,12 +1,14 @@
require "test_helper"
class CreditCardsControllerTest < ActionDispatch::IntegrationTest
include AccountableResourceInterfaceTest
setup do
sign_in @user = users(:family_admin)
@account = accounts(:credit_card)
end
test "creates credit card" do
test "creates with credit card details" do
assert_difference -> { Account.count } => 1,
-> { CreditCard.count } => 1,
-> { Account::Valuation.count } => 2,
@ -17,8 +19,6 @@ class CreditCardsControllerTest < ActionDispatch::IntegrationTest
balance: 1000,
currency: "USD",
accountable_type: "CreditCard",
start_date: 1.month.ago.to_date,
start_balance: 0,
accountable_attributes: {
available_credit: 5000,
minimum_payment: 25,
@ -35,20 +35,20 @@ class CreditCardsControllerTest < ActionDispatch::IntegrationTest
assert_equal "New Credit Card", created_account.name
assert_equal 1000, created_account.balance
assert_equal "USD", created_account.currency
assert_equal 5000, created_account.credit_card.available_credit
assert_equal 25, created_account.credit_card.minimum_payment
assert_equal 15.99, created_account.credit_card.apr
assert_equal 2.years.from_now.to_date, created_account.credit_card.expiration_date
assert_equal 99, created_account.credit_card.annual_fee
assert_equal 5000, created_account.accountable.available_credit
assert_equal 25, created_account.accountable.minimum_payment
assert_equal 15.99, created_account.accountable.apr
assert_equal 2.years.from_now.to_date, created_account.accountable.expiration_date
assert_equal 99, created_account.accountable.annual_fee
assert_redirected_to account_path(created_account)
assert_equal "Credit card created successfully", flash[:notice]
assert_redirected_to created_account
assert_equal "Credit card account created", flash[:notice]
assert_enqueued_with(job: AccountSyncJob)
end
test "updates credit card" do
test "updates with credit card details" do
assert_no_difference [ "Account.count", "CreditCard.count" ] do
patch credit_card_path(@account), params: {
patch account_path(@account), params: {
account: {
name: "Updated Credit Card",
balance: 2000,
@ -70,14 +70,14 @@ class CreditCardsControllerTest < ActionDispatch::IntegrationTest
assert_equal "Updated Credit Card", @account.name
assert_equal 2000, @account.balance
assert_equal 6000, @account.credit_card.available_credit
assert_equal 50, @account.credit_card.minimum_payment
assert_equal 14.99, @account.credit_card.apr
assert_equal 3.years.from_now.to_date, @account.credit_card.expiration_date
assert_equal 0, @account.credit_card.annual_fee
assert_equal 6000, @account.accountable.available_credit
assert_equal 50, @account.accountable.minimum_payment
assert_equal 14.99, @account.accountable.apr
assert_equal 3.years.from_now.to_date, @account.accountable.expiration_date
assert_equal 0, @account.accountable.annual_fee
assert_redirected_to account_path(@account)
assert_equal "Credit card updated successfully", flash[:notice]
assert_redirected_to @account
assert_equal "Credit card account updated", flash[:notice]
assert_enqueued_with(job: AccountSyncJob)
end
end

View file

@ -0,0 +1,10 @@
require "test_helper"
class CryptosControllerTest < ActionDispatch::IntegrationTest
include AccountableResourceInterfaceTest
setup do
sign_in @user = users(:family_admin)
@account = accounts(:crypto)
end
end

View file

@ -0,0 +1,10 @@
require "test_helper"
class DepositoriesControllerTest < ActionDispatch::IntegrationTest
include AccountableResourceInterfaceTest
setup do
sign_in @user = users(:family_admin)
@account = accounts(:depository)
end
end

View file

@ -0,0 +1,10 @@
require "test_helper"
class InvestmentsControllerTest < ActionDispatch::IntegrationTest
include AccountableResourceInterfaceTest
setup do
sign_in @user = users(:family_admin)
@account = accounts(:investment)
end
end

View file

@ -57,7 +57,7 @@ class InvitationsControllerTest < ActionDispatch::IntegrationTest
}
end
invitation = Invitation.last
invitation = Invitation.order(created_at: :desc).first
assert_equal "admin", invitation.role
assert_equal @user.family, invitation.family
assert_equal @user, invitation.inviter

View file

@ -14,6 +14,6 @@ class Issue::ExchangeRateProviderMissingsControllerTest < ActionDispatch::Integr
}
assert_enqueued_with job: AccountSyncJob
assert_redirected_to account_url(@issue.issuable)
assert_redirected_to @issue.issuable
end
end

View file

@ -1,12 +1,14 @@
require "test_helper"
class LoansControllerTest < ActionDispatch::IntegrationTest
include AccountableResourceInterfaceTest
setup do
sign_in @user = users(:family_admin)
@account = accounts(:loan)
end
test "creates loan" do
test "creates with loan details" do
assert_difference -> { Account.count } => 1,
-> { Loan.count } => 1,
-> { Account::Valuation.count } => 2,
@ -17,8 +19,6 @@ class LoansControllerTest < ActionDispatch::IntegrationTest
balance: 50000,
currency: "USD",
accountable_type: "Loan",
start_date: 1.month.ago.to_date,
start_balance: 50000,
accountable_attributes: {
interest_rate: 5.5,
term_months: 60,
@ -33,18 +33,18 @@ class LoansControllerTest < ActionDispatch::IntegrationTest
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.loan.interest_rate
assert_equal 60, created_account.loan.term_months
assert_equal "fixed", created_account.loan.rate_type
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_redirected_to account_path(created_account)
assert_equal "Loan created successfully", flash[:notice]
assert_redirected_to created_account
assert_equal "Loan account created", flash[:notice]
assert_enqueued_with(job: AccountSyncJob)
end
test "updates loan" do
test "updates with loan details" do
assert_no_difference [ "Account.count", "Loan.count" ] do
patch loan_path(@account), params: {
patch account_path(@account), params: {
account: {
name: "Updated Loan",
balance: 45000,
@ -64,12 +64,12 @@ class LoansControllerTest < ActionDispatch::IntegrationTest
assert_equal "Updated Loan", @account.name
assert_equal 45000, @account.balance
assert_equal 4.5, @account.loan.interest_rate
assert_equal 48, @account.loan.term_months
assert_equal "fixed", @account.loan.rate_type
assert_equal 4.5, @account.accountable.interest_rate
assert_equal 48, @account.accountable.term_months
assert_equal "fixed", @account.accountable.rate_type
assert_redirected_to account_path(@account)
assert_equal "Loan updated successfully", flash[:notice]
assert_redirected_to @account
assert_equal "Loan account updated", flash[:notice]
assert_enqueued_with(job: AccountSyncJob)
end
end

View file

@ -0,0 +1,10 @@
require "test_helper"
class OtherAssetsControllerTest < ActionDispatch::IntegrationTest
include AccountableResourceInterfaceTest
setup do
sign_in @user = users(:family_admin)
@account = accounts(:other_asset)
end
end

View file

@ -0,0 +1,10 @@
require "test_helper"
class OtherLiabilitiesControllerTest < ActionDispatch::IntegrationTest
include AccountableResourceInterfaceTest
setup do
sign_in @user = users(:family_admin)
@account = accounts(:other_liability)
end
end

View file

@ -1,12 +1,14 @@
require "test_helper"
class PropertiesControllerTest < ActionDispatch::IntegrationTest
include AccountableResourceInterfaceTest
setup do
sign_in @user = users(:family_admin)
@account = accounts(:property)
end
test "creates property" do
test "creates with property details" do
assert_difference -> { Account.count } => 1,
-> { Property.count } => 1,
-> { Account::Valuation.count } => 2,
@ -17,8 +19,6 @@ class PropertiesControllerTest < ActionDispatch::IntegrationTest
balance: 500000,
currency: "USD",
accountable_type: "Property",
start_date: 3.years.ago.to_date,
start_balance: 450000,
accountable_attributes: {
year_built: 2002,
area_value: 1000,
@ -38,17 +38,17 @@ class PropertiesControllerTest < ActionDispatch::IntegrationTest
created_account = Account.order(:created_at).last
assert created_account.property.year_built.present?
assert created_account.property.address.line1.present?
assert created_account.accountable.year_built.present?
assert created_account.accountable.address.line1.present?
assert_redirected_to account_path(created_account)
assert_equal "Property created successfully", flash[:notice]
assert_redirected_to created_account
assert_equal "Property account created", flash[:notice]
assert_enqueued_with(job: AccountSyncJob)
end
test "updates property" do
test "updates with property details" do
assert_no_difference [ "Account.count", "Property.count" ] do
patch property_path(@account), params: {
patch account_path(@account), params: {
account: {
name: "Updated Property",
balance: 500000,
@ -72,8 +72,8 @@ class PropertiesControllerTest < ActionDispatch::IntegrationTest
}
end
assert_redirected_to account_path(@account)
assert_equal "Property updated successfully", flash[:notice]
assert_redirected_to @account
assert_equal "Property account updated", flash[:notice]
assert_enqueued_with(job: AccountSyncJob)
end
end

View file

@ -1,12 +1,14 @@
require "test_helper"
class VehiclesControllerTest < ActionDispatch::IntegrationTest
include AccountableResourceInterfaceTest
setup do
sign_in @user = users(:family_admin)
@account = accounts(:vehicle)
end
test "creates vehicle" do
test "creates with vehicle details" do
assert_difference -> { Account.count } => 1,
-> { Vehicle.count } => 1,
-> { Account::Valuation.count } => 2,
@ -17,8 +19,6 @@ class VehiclesControllerTest < ActionDispatch::IntegrationTest
balance: 30000,
currency: "USD",
accountable_type: "Vehicle",
start_date: 1.year.ago.to_date,
start_balance: 35000,
accountable_attributes: {
make: "Toyota",
model: "Camry",
@ -32,20 +32,20 @@ class VehiclesControllerTest < ActionDispatch::IntegrationTest
created_account = Account.order(:created_at).last
assert_equal "Toyota", created_account.vehicle.make
assert_equal "Camry", created_account.vehicle.model
assert_equal 2020, created_account.vehicle.year
assert_equal 15000, created_account.vehicle.mileage_value
assert_equal "mi", created_account.vehicle.mileage_unit
assert_equal "Toyota", created_account.accountable.make
assert_equal "Camry", created_account.accountable.model
assert_equal 2020, created_account.accountable.year
assert_equal 15000, created_account.accountable.mileage_value
assert_equal "mi", created_account.accountable.mileage_unit
assert_redirected_to account_path(created_account)
assert_equal "Vehicle created successfully", flash[:notice]
assert_redirected_to created_account
assert_equal "Vehicle account created", flash[:notice]
assert_enqueued_with(job: AccountSyncJob)
end
test "updates vehicle" do
test "updates with vehicle details" do
assert_no_difference [ "Account.count", "Vehicle.count" ] do
patch vehicle_path(@account), params: {
patch account_path(@account), params: {
account: {
name: "Updated Vehicle",
balance: 28000,
@ -64,8 +64,8 @@ class VehiclesControllerTest < ActionDispatch::IntegrationTest
}
end
assert_redirected_to account_path(@account)
assert_equal "Vehicle updated successfully", flash[:notice]
assert_redirected_to @account
assert_equal "Vehicle account updated", flash[:notice]
assert_enqueued_with(job: AccountSyncJob)
end
end