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

Add loan and credit card views (#1268)

* Add loan and credit card views

* Lint fix

* Clean up overview card markup

* Lint fix

* Test fix
This commit is contained in:
Zach Gollwitzer 2024-10-08 17:16:37 -04:00 committed by GitHub
parent 9263dd3bbe
commit fd941d714d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
34 changed files with 564 additions and 102 deletions

View file

@ -0,0 +1,83 @@
require "test_helper"
class CreditCardsControllerTest < ActionDispatch::IntegrationTest
setup do
sign_in @user = users(:family_admin)
@account = accounts(:credit_card)
end
test "creates credit card" do
assert_difference -> { Account.count } => 1,
-> { CreditCard.count } => 1,
-> { Account::Valuation.count } => 2,
-> { Account::Entry.count } => 2 do
post credit_cards_path, params: {
account: {
name: "New Credit Card",
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,
apr: 15.99,
expiration_date: 2.years.from_now.to_date,
annual_fee: 99
}
}
}
end
created_account = Account.order(:created_at).last
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_redirected_to account_path(created_account)
assert_equal "Credit card created successfully", flash[:notice]
assert_enqueued_with(job: AccountSyncJob)
end
test "updates credit card" do
assert_no_difference [ "Account.count", "CreditCard.count" ] do
patch credit_card_path(@account), params: {
account: {
name: "Updated Credit Card",
balance: 2000,
currency: "USD",
accountable_type: "CreditCard",
accountable_attributes: {
id: @account.accountable_id,
available_credit: 6000,
minimum_payment: 50,
apr: 14.99,
expiration_date: 3.years.from_now.to_date,
annual_fee: 0
}
}
}
end
@account.reload
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_redirected_to account_path(@account)
assert_equal "Credit card updated successfully", flash[:notice]
assert_enqueued_with(job: AccountSyncJob)
end
end

View file

@ -0,0 +1,75 @@
require "test_helper"
class LoansControllerTest < ActionDispatch::IntegrationTest
setup do
sign_in @user = users(:family_admin)
@account = accounts(:loan)
end
test "creates loan" do
assert_difference -> { Account.count } => 1,
-> { Loan.count } => 1,
-> { Account::Valuation.count } => 2,
-> { Account::Entry.count } => 2 do
post loans_path, params: {
account: {
name: "New Loan",
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,
rate_type: "fixed"
}
}
}
end
created_account = Account.order(:created_at).last
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_redirected_to account_path(created_account)
assert_equal "Loan created successfully", flash[:notice]
assert_enqueued_with(job: AccountSyncJob)
end
test "updates loan" do
assert_no_difference [ "Account.count", "Loan.count" ] do
patch loan_path(@account), params: {
account: {
name: "Updated Loan",
balance: 45000,
currency: "USD",
accountable_type: "Loan",
accountable_attributes: {
id: @account.accountable_id,
interest_rate: 4.5,
term_months: 48,
rate_type: "fixed"
}
}
}
end
@account.reload
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_redirected_to account_path(@account)
assert_equal "Loan updated successfully", flash[:notice]
assert_enqueued_with(job: AccountSyncJob)
end
end

View file

@ -47,7 +47,7 @@ class PropertiesControllerTest < ActionDispatch::IntegrationTest
end
test "updates property" do
assert_no_difference [ "Account.count", "Property.count", "Account::Valuation.count", "Account::Entry.count" ] do
assert_no_difference [ "Account.count", "Property.count" ] do
patch property_path(@account), params: {
account: {
name: "Updated Property",

View file

@ -44,7 +44,7 @@ class VehiclesControllerTest < ActionDispatch::IntegrationTest
end
test "updates vehicle" do
assert_no_difference [ "Account.count", "Vehicle.count", "Account::Valuation.count", "Account::Entry.count" ] do
assert_no_difference [ "Account.count", "Vehicle.count" ] do
patch vehicle_path(@account), params: {
account: {
name: "Updated Vehicle",

View file

@ -1 +1,7 @@
one: { }
one:
available_credit: 5000.00
minimum_payment: 100.00
apr: 18.99
expiration_date: <%= 4.years.from_now.to_date %>
annual_fee: 95.00

View file

@ -1 +1,4 @@
one: { }
one:
interest_rate: 3.5
term_months: 360
rate_type: fixed

View file

@ -1,7 +1,18 @@
require "test_helper"
class LoanTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
test "calculates correct monthly payment for fixed rate loan" do
loan_account = Account.create! \
family: families(:dylan_family),
name: "Mortgage Loan",
balance: 500000,
currency: "USD",
accountable: Loan.create!(
interest_rate: 3.5,
term_months: 360,
rate_type: "fixed"
)
assert_equal 2245, loan_account.loan.monthly_payment.amount
end
end

View file

@ -22,13 +22,13 @@ class AccountsTest < ApplicationSystemTestCase
test "can create property account" do
assert_account_created "Property" do
fill_in "Year built (optional)", with: 2005
fill_in "Area value (optional)", with: 2250
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 "City", with: "San Francisco"
fill_in "State", with: "CA"
fill_in "Postal code (optional)", with: "94101"
fill_in "Postal code", with: "94101"
fill_in "Country", with: "US"
end
end
@ -47,11 +47,21 @@ class AccountsTest < ApplicationSystemTestCase
end
test "can create credit card account" do
assert_account_created("CreditCard")
assert_account_created "CreditCard" do
fill_in "Available credit", with: 1000
fill_in "Minimum payment", with: 25
fill_in "APR", with: 15.25
fill_in "Expiration date", with: 1.year.from_now.to_date
fill_in "Annual fee", with: 100
end
end
test "can create loan account" do
assert_account_created("Loan")
assert_account_created "Loan" do
fill_in "Interest rate", with: 5.25
select "Fixed", from: "Rate type"
fill_in "Term (months)", with: 360
end
end
test "can create other liability account" do