2024-06-20 07:26:25 -04:00
|
|
|
require "application_system_test_case"
|
|
|
|
|
|
|
|
class AccountsTest < ApplicationSystemTestCase
|
|
|
|
setup do
|
|
|
|
sign_in @user = users(:family_admin)
|
|
|
|
|
2024-11-15 13:49:37 -05:00
|
|
|
Family.any_instance.stubs(:get_link_token).returns("test-link-token")
|
|
|
|
|
2024-06-20 07:26:25 -04:00
|
|
|
visit root_url
|
|
|
|
open_new_account_modal
|
|
|
|
end
|
|
|
|
|
|
|
|
test "can create depository account" do
|
|
|
|
assert_account_created("Depository")
|
|
|
|
end
|
|
|
|
|
|
|
|
test "can create investment account" do
|
|
|
|
assert_account_created("Investment")
|
|
|
|
end
|
|
|
|
|
|
|
|
test "can create crypto account" do
|
|
|
|
assert_account_created("Crypto")
|
|
|
|
end
|
|
|
|
|
|
|
|
test "can create property account" do
|
2024-08-23 08:47:08 -04:00
|
|
|
assert_account_created "Property" do
|
2024-10-08 17:16:37 -04:00
|
|
|
fill_in "Year built", with: 2005
|
2024-11-04 20:27:31 -05:00
|
|
|
fill_in "Living area", with: 2250
|
|
|
|
fill_in "Street address", with: "123 Main St"
|
2024-08-23 08:47:08 -04:00
|
|
|
fill_in "City", with: "San Francisco"
|
2024-11-04 20:27:31 -05:00
|
|
|
fill_in "State/Province", with: "CA"
|
|
|
|
fill_in "ZIP/Postal code", with: "94101"
|
2024-08-23 08:47:08 -04:00
|
|
|
fill_in "Country", with: "US"
|
|
|
|
end
|
2024-06-20 07:26:25 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test "can create vehicle account" do
|
2024-08-23 09:33:42 -04:00
|
|
|
assert_account_created "Vehicle" do
|
|
|
|
fill_in "Make", with: "Toyota"
|
|
|
|
fill_in "Model", with: "Camry"
|
|
|
|
fill_in "Year", with: "2020"
|
|
|
|
fill_in "Mileage", with: "30000"
|
|
|
|
end
|
2024-06-20 07:26:25 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test "can create other asset account" do
|
|
|
|
assert_account_created("OtherAsset")
|
|
|
|
end
|
|
|
|
|
|
|
|
test "can create credit card account" do
|
2024-10-08 17:16:37 -04:00
|
|
|
assert_account_created "CreditCard" do
|
|
|
|
fill_in "Available credit", with: 1000
|
2025-01-27 20:03:56 +05:30
|
|
|
fill_in "account[accountable_attributes][minimum_payment]", with: 25.51
|
2024-10-08 17:16:37 -04:00
|
|
|
fill_in "APR", with: 15.25
|
|
|
|
fill_in "Expiration date", with: 1.year.from_now.to_date
|
|
|
|
fill_in "Annual fee", with: 100
|
|
|
|
end
|
2024-06-20 07:26:25 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test "can create loan account" do
|
2024-10-08 17:16:37 -04:00
|
|
|
assert_account_created "Loan" do
|
|
|
|
fill_in "Interest rate", with: 5.25
|
|
|
|
select "Fixed", from: "Rate type"
|
|
|
|
fill_in "Term (months)", with: 360
|
|
|
|
end
|
2024-06-20 07:26:25 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
test "can create other liability account" do
|
|
|
|
assert_account_created("OtherLiability")
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def open_new_account_modal
|
|
|
|
click_link "sidebar-new-account"
|
|
|
|
end
|
|
|
|
|
2024-08-23 08:47:08 -04:00
|
|
|
def assert_account_created(accountable_type, &block)
|
2024-11-04 20:27:31 -05:00
|
|
|
click_link humanized_accountable(accountable_type)
|
|
|
|
click_link "Enter account balance" if accountable_type.in?(%w[Depository Investment Crypto Loan CreditCard])
|
2024-06-20 07:26:25 -04:00
|
|
|
|
|
|
|
account_name = "[system test] #{accountable_type} Account"
|
|
|
|
|
2024-11-04 20:27:31 -05:00
|
|
|
fill_in "Account name*", with: account_name
|
2024-06-20 07:26:25 -04:00
|
|
|
fill_in "account[balance]", with: 100.99
|
2024-08-23 08:47:08 -04:00
|
|
|
|
2024-11-04 20:27:31 -05:00
|
|
|
yield if block_given?
|
|
|
|
|
2024-10-18 14:37:42 -04:00
|
|
|
click_button "Create Account"
|
2024-06-20 07:26:25 -04:00
|
|
|
|
|
|
|
find("details", text: humanized_accountable(accountable_type)).click
|
|
|
|
assert_text account_name
|
|
|
|
|
|
|
|
visit accounts_url
|
|
|
|
assert_text account_name
|
2024-08-23 08:47:08 -04:00
|
|
|
|
2024-10-18 17:18:54 -04:00
|
|
|
created_account = Account.order(:created_at).last
|
|
|
|
|
|
|
|
visit account_url(created_account)
|
2024-08-23 08:47:08 -04:00
|
|
|
|
|
|
|
within "header" do
|
|
|
|
find('button[data-menu-target="button"]').click
|
|
|
|
click_on "Edit"
|
|
|
|
end
|
|
|
|
|
|
|
|
fill_in "Account name", with: "Updated account name"
|
2024-10-18 14:37:42 -04:00
|
|
|
click_button "Update Account"
|
2024-08-23 08:47:08 -04:00
|
|
|
assert_selector "h2", text: "Updated account name"
|
2024-06-20 07:26:25 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def humanized_accountable(accountable_type)
|
|
|
|
accountable_type.constantize.model_name.human
|
|
|
|
end
|
|
|
|
end
|