mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-04 21:15:19 +02:00
Account Activity View + Account Forms (#1406)
* 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:
parent
12e4f1067d
commit
65db49273c
216 changed files with 2043 additions and 1620 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
10
test/controllers/cryptos_controller_test.rb
Normal file
10
test/controllers/cryptos_controller_test.rb
Normal 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
|
10
test/controllers/depositories_controller_test.rb
Normal file
10
test/controllers/depositories_controller_test.rb
Normal 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
|
10
test/controllers/investments_controller_test.rb
Normal file
10
test/controllers/investments_controller_test.rb
Normal 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
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
10
test/controllers/other_assets_controller_test.rb
Normal file
10
test/controllers/other_assets_controller_test.rb
Normal 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
|
10
test/controllers/other_liabilities_controller_test.rb
Normal file
10
test/controllers/other_liabilities_controller_test.rb
Normal 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
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
16
test/fixtures/accounts.yml
vendored
16
test/fixtures/accounts.yml
vendored
|
@ -5,7 +5,6 @@ other_asset:
|
|||
currency: USD
|
||||
accountable_type: OtherAsset
|
||||
accountable: one
|
||||
mode: balance
|
||||
|
||||
other_liability:
|
||||
family: dylan_family
|
||||
|
@ -14,7 +13,6 @@ other_liability:
|
|||
currency: USD
|
||||
accountable_type: OtherLiability
|
||||
accountable: one
|
||||
mode: balance
|
||||
|
||||
depository:
|
||||
family: dylan_family
|
||||
|
@ -24,7 +22,6 @@ depository:
|
|||
accountable_type: Depository
|
||||
accountable: one
|
||||
institution: chase
|
||||
mode: transactions
|
||||
|
||||
credit_card:
|
||||
family: dylan_family
|
||||
|
@ -34,7 +31,6 @@ credit_card:
|
|||
accountable_type: CreditCard
|
||||
accountable: one
|
||||
institution: chase
|
||||
mode: transactions
|
||||
|
||||
investment:
|
||||
family: dylan_family
|
||||
|
@ -43,7 +39,6 @@ investment:
|
|||
currency: USD
|
||||
accountable_type: Investment
|
||||
accountable: one
|
||||
mode: transactions
|
||||
|
||||
loan:
|
||||
family: dylan_family
|
||||
|
@ -52,7 +47,6 @@ loan:
|
|||
currency: USD
|
||||
accountable_type: Loan
|
||||
accountable: one
|
||||
mode: transactions
|
||||
|
||||
property:
|
||||
family: dylan_family
|
||||
|
@ -61,7 +55,6 @@ property:
|
|||
currency: USD
|
||||
accountable_type: Property
|
||||
accountable: one
|
||||
mode: transactions
|
||||
|
||||
vehicle:
|
||||
family: dylan_family
|
||||
|
@ -70,4 +63,11 @@ vehicle:
|
|||
currency: USD
|
||||
accountable_type: Vehicle
|
||||
accountable: one
|
||||
mode: transactions
|
||||
|
||||
crypto:
|
||||
family: dylan_family
|
||||
name: Bitcoin
|
||||
balance: 10000
|
||||
currency: USD
|
||||
accountable_type: Crypto
|
||||
accountable: one
|
||||
|
|
90
test/interfaces/accountable_resource_interface_test.rb
Normal file
90
test/interfaces/accountable_resource_interface_test.rb
Normal file
|
@ -0,0 +1,90 @@
|
|||
require "test_helper"
|
||||
|
||||
module AccountableResourceInterfaceTest
|
||||
extend ActiveSupport::Testing::Declarative
|
||||
|
||||
test "shows new form" do
|
||||
get new_polymorphic_url(@account.accountable)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "shows edit form" do
|
||||
get edit_account_url(@account)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "renders accountable page" do
|
||||
get account_url(@account)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "destroys account" do
|
||||
delete account_url(@account)
|
||||
assert_redirected_to accounts_path
|
||||
assert_equal "#{@account.accountable_name.humanize} account deleted", flash[:notice]
|
||||
end
|
||||
|
||||
test "updates basic account balances" do
|
||||
assert_no_difference [ "Account.count", "@account.accountable_class.count" ] do
|
||||
patch account_url(@account), params: {
|
||||
account: {
|
||||
institution_id: institutions(:chase).id,
|
||||
name: "Updated name",
|
||||
balance: 10000,
|
||||
currency: "USD"
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
assert_redirected_to @account
|
||||
assert_equal "#{@account.accountable_name.humanize} account updated", flash[:notice]
|
||||
end
|
||||
|
||||
test "creates with basic attributes" do
|
||||
assert_difference [ "Account.count", "@account.accountable_class.count" ], 1 do
|
||||
post "/#{@account.accountable_name.pluralize}", params: {
|
||||
account: {
|
||||
accountable_type: @account.accountable_class,
|
||||
institution_id: institutions(:chase).id,
|
||||
name: "New accountable",
|
||||
balance: 10000,
|
||||
currency: "USD",
|
||||
subtype: "checking"
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
assert_redirected_to Account.order(:created_at).last
|
||||
assert_equal "#{@account.accountable_name.humanize} account created", 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
|
||||
assert_enqueued_with job: AccountSyncJob
|
||||
assert_equal "#{@account.accountable_name.humanize} 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
|
||||
assert_enqueued_with job: AccountSyncJob
|
||||
assert_equal "#{@account.accountable_name.humanize} account updated", flash[:notice]
|
||||
end
|
||||
end
|
|
@ -23,12 +23,11 @@ class AccountsTest < ApplicationSystemTestCase
|
|||
test "can create property account" do
|
||||
assert_account_created "Property" do
|
||||
fill_in "Year built", with: 2005
|
||||
fill_in "Area value", with: 2250
|
||||
fill_in "Address line 1", with: "123 Main St"
|
||||
fill_in "Address line 2", with: "Apt 4B"
|
||||
fill_in "Living area", with: 2250
|
||||
fill_in "Street address", with: "123 Main St"
|
||||
fill_in "City", with: "San Francisco"
|
||||
fill_in "State", with: "CA"
|
||||
fill_in "Postal code", with: "94101"
|
||||
fill_in "State/Province", with: "CA"
|
||||
fill_in "ZIP/Postal code", with: "94101"
|
||||
fill_in "Country", with: "US"
|
||||
end
|
||||
end
|
||||
|
@ -80,14 +79,16 @@ class AccountsTest < ApplicationSystemTestCase
|
|||
end
|
||||
|
||||
def assert_account_created(accountable_type, &block)
|
||||
click_link "Enter account manually"
|
||||
click_link humanized_accountable(accountable_type)
|
||||
click_link "Enter account balance" if accountable_type.in?(%w[Depository Investment Crypto Loan CreditCard])
|
||||
|
||||
account_name = "[system test] #{accountable_type} Account"
|
||||
|
||||
select accountable_type.titleize, from: "Account type"
|
||||
fill_in "Account name", with: account_name
|
||||
fill_in "Account name*", with: account_name
|
||||
fill_in "account[balance]", with: 100.99
|
||||
|
||||
yield if block_given?
|
||||
|
||||
click_button "Create Account"
|
||||
|
||||
find("details", text: humanized_accountable(accountable_type)).click
|
||||
|
@ -97,7 +98,6 @@ class AccountsTest < ApplicationSystemTestCase
|
|||
assert_text account_name
|
||||
|
||||
created_account = Account.order(:created_at).last
|
||||
created_account.update!(mode: "transactions")
|
||||
|
||||
visit account_url(created_account)
|
||||
|
||||
|
@ -106,8 +106,6 @@ class AccountsTest < ApplicationSystemTestCase
|
|||
click_on "Edit"
|
||||
end
|
||||
|
||||
yield if block_given?
|
||||
|
||||
fill_in "Account name", with: "Updated account name"
|
||||
click_button "Update Account"
|
||||
assert_selector "h2", text: "Updated account name"
|
||||
|
|
|
@ -66,15 +66,18 @@ class TradesTest < ApplicationSystemTestCase
|
|||
private
|
||||
|
||||
def open_new_trade_modal
|
||||
click_link "new_trade_account_#{@account.id}"
|
||||
within "[data-testid='activity-menu']" do
|
||||
click_on "New"
|
||||
click_on "New transaction"
|
||||
end
|
||||
end
|
||||
|
||||
def within_trades(&block)
|
||||
within "#" + dom_id(@account, "trades"), &block
|
||||
within "#" + dom_id(@account, "entries"), &block
|
||||
end
|
||||
|
||||
def visit_account_trades
|
||||
visit account_url(@account, tab: "transactions")
|
||||
visit account_path(@account)
|
||||
end
|
||||
|
||||
def select_combobox_option(text)
|
||||
|
|
|
@ -182,15 +182,13 @@ class TransactionsTest < ApplicationSystemTestCase
|
|||
investment_account = accounts(:investment)
|
||||
investment_account.entries.create!(name: "Investment account", date: Date.current, amount: 1000, currency: "USD", entryable: Account::Transaction.new)
|
||||
transfer_date = Date.current
|
||||
visit account_path(investment_account)
|
||||
visit account_url(investment_account)
|
||||
click_on "New"
|
||||
click_on "New transaction"
|
||||
select "Deposit", from: "Type"
|
||||
fill_in "Date", with: transfer_date
|
||||
fill_in "account_entry[amount]", with: 175.25
|
||||
click_button "Add transaction"
|
||||
within "#account_" + investment_account.id do
|
||||
click_on "Transactions"
|
||||
end
|
||||
within "#entry-group-" + transfer_date.to_s do
|
||||
assert_text "175.25"
|
||||
end
|
||||
|
|
|
@ -55,7 +55,8 @@ class TransfersTest < ApplicationSystemTestCase
|
|||
click_on "Mark as transfers"
|
||||
|
||||
within "#entry-group-" + transfer_date.to_s do
|
||||
assert_text "Transfer from"
|
||||
assert_text "Outflow"
|
||||
assert_text "Inflow"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue