2024-02-05 11:00:40 +11:00
|
|
|
require "test_helper"
|
|
|
|
|
|
|
|
class AccountsControllerTest < ActionDispatch::IntegrationTest
|
|
|
|
setup do
|
2024-02-27 12:43:49 -05:00
|
|
|
sign_in @user = users(:family_admin)
|
2024-03-04 08:31:22 -05:00
|
|
|
@account = accounts(:checking)
|
2024-02-05 11:00:40 +11:00
|
|
|
end
|
|
|
|
|
2024-06-13 14:37:27 -04:00
|
|
|
test "gets accounts list" do
|
|
|
|
get accounts_url
|
|
|
|
assert_response :success
|
|
|
|
|
|
|
|
@user.family.accounts.each do |account|
|
|
|
|
assert_dom "#" + dom_id(account), count: 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2024-02-05 11:00:40 +11:00
|
|
|
test "new" do
|
|
|
|
get new_account_path
|
|
|
|
assert_response :ok
|
|
|
|
end
|
|
|
|
|
|
|
|
test "show" do
|
|
|
|
get account_path(@account)
|
|
|
|
assert_response :ok
|
|
|
|
end
|
|
|
|
|
2024-06-13 17:03:38 -04:00
|
|
|
test "can sync an account" do
|
|
|
|
post sync_account_path(@account)
|
|
|
|
assert_redirected_to account_url(@account)
|
|
|
|
end
|
|
|
|
|
2024-06-11 18:47:38 -04:00
|
|
|
test "should update account" do
|
|
|
|
patch account_url(@account), params: {
|
|
|
|
account: {
|
2024-06-13 14:37:27 -04:00
|
|
|
name: "Updated name",
|
|
|
|
is_active: "0",
|
|
|
|
institution_id: institutions(:chase).id
|
2024-06-11 18:47:38 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_redirected_to account_url(@account)
|
|
|
|
assert_equal "Account updated", flash[:notice]
|
|
|
|
end
|
|
|
|
|
2024-06-13 09:16:00 -04:00
|
|
|
test "should create an account" do
|
2024-07-01 10:49:43 -04:00
|
|
|
assert_difference [ "Account.count", "Account::Valuation.count", "Account::Entry.count" ], 1 do
|
2024-06-13 09:16:00 -04:00
|
|
|
post accounts_path, params: {
|
|
|
|
account: {
|
2024-06-20 07:26:25 -04:00
|
|
|
accountable_type: "Depository",
|
2024-06-13 09:16:00 -04:00
|
|
|
balance: 200,
|
2024-06-13 14:37:27 -04:00
|
|
|
subtype: "checking",
|
|
|
|
institution_id: institutions(:chase).id
|
2024-06-13 09:16:00 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert_equal "New account created successfully", flash[:notice]
|
2024-06-11 18:47:38 -04:00
|
|
|
assert_redirected_to account_url(Account.order(:created_at).last)
|
2024-02-05 11:00:40 +11:00
|
|
|
end
|
|
|
|
end
|
2024-05-16 21:57:21 +02:00
|
|
|
|
2024-06-13 09:16:00 -04:00
|
|
|
test "can add optional start date and balance to an account on create" do
|
2024-06-21 16:23:28 -04:00
|
|
|
assert_difference -> { Account.count } => 1, -> { Account::Valuation.count } => 2 do
|
2024-06-13 09:16:00 -04:00
|
|
|
post accounts_path, params: {
|
|
|
|
account: {
|
2024-06-20 07:26:25 -04:00
|
|
|
accountable_type: "Depository",
|
2024-06-13 09:16:00 -04:00
|
|
|
balance: 200,
|
|
|
|
subtype: "checking",
|
2024-06-13 14:37:27 -04:00
|
|
|
institution_id: institutions(:chase).id,
|
2024-06-13 09:16:00 -04:00
|
|
|
start_balance: 100,
|
|
|
|
start_date: 10.days.ago
|
|
|
|
}
|
|
|
|
}
|
2024-05-16 21:57:21 +02:00
|
|
|
|
2024-06-13 09:16:00 -04:00
|
|
|
assert_equal "New account created successfully", flash[:notice]
|
|
|
|
assert_redirected_to account_url(Account.order(:created_at).last)
|
|
|
|
end
|
2024-05-16 21:57:21 +02:00
|
|
|
end
|
2024-02-05 11:00:40 +11:00
|
|
|
end
|