2024-06-20 13:32:44 -04:00
|
|
|
require "application_system_test_case"
|
|
|
|
|
|
|
|
class TransfersTest < ApplicationSystemTestCase
|
|
|
|
setup do
|
|
|
|
sign_in @user = users(:family_admin)
|
|
|
|
visit transactions_url
|
|
|
|
end
|
|
|
|
|
|
|
|
test "can create a transfer" do
|
2024-07-10 11:22:59 -04:00
|
|
|
checking_name = accounts(:depository).name
|
|
|
|
savings_name = accounts(:credit_card).name
|
2024-06-20 13:32:44 -04:00
|
|
|
transfer_date = Date.current
|
|
|
|
|
|
|
|
click_on "New transaction"
|
|
|
|
|
|
|
|
# Will navigate to different route in same modal
|
|
|
|
click_on "Transfer"
|
|
|
|
assert_text "New transfer"
|
|
|
|
|
|
|
|
fill_in "Description", with: "Transfer txn name"
|
|
|
|
select checking_name, from: "From"
|
|
|
|
select savings_name, from: "To"
|
|
|
|
fill_in "account_transfer[amount]", with: 500
|
|
|
|
fill_in "Date", with: transfer_date
|
2024-07-01 10:49:43 -04:00
|
|
|
|
2024-06-20 13:32:44 -04:00
|
|
|
click_button "Create transfer"
|
|
|
|
|
2024-07-01 10:49:43 -04:00
|
|
|
within "#entry-group-" + transfer_date.to_s do
|
|
|
|
assert_text "Transfer from"
|
2024-06-20 13:32:44 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test "can match 2 transactions and create a transfer" do
|
|
|
|
transfer_date = Date.current
|
2024-07-10 11:22:59 -04:00
|
|
|
outflow = accounts(:depository).entries.create! \
|
|
|
|
name: "Outflow from checking account",
|
2024-07-01 10:49:43 -04:00
|
|
|
date: transfer_date,
|
|
|
|
amount: 100,
|
|
|
|
currency: "USD",
|
|
|
|
entryable: Account::Transaction.new
|
|
|
|
|
2024-07-10 11:22:59 -04:00
|
|
|
inflow = accounts(:credit_card).entries.create! \
|
|
|
|
name: "Inflow to cc account",
|
2024-07-01 10:49:43 -04:00
|
|
|
date: transfer_date,
|
|
|
|
amount: -100,
|
|
|
|
currency: "USD",
|
|
|
|
entryable: Account::Transaction.new
|
2024-06-20 13:32:44 -04:00
|
|
|
|
|
|
|
visit transactions_url
|
|
|
|
|
2024-07-01 10:49:43 -04:00
|
|
|
transaction_entry_checkbox(inflow).check
|
|
|
|
transaction_entry_checkbox(outflow).check
|
2024-06-20 13:32:44 -04:00
|
|
|
|
|
|
|
bulk_transfer_action_button.click
|
|
|
|
|
|
|
|
click_on "Mark as transfers"
|
|
|
|
|
2024-07-01 10:49:43 -04:00
|
|
|
within "#entry-group-" + transfer_date.to_s do
|
|
|
|
assert_text "Transfer from"
|
2024-06-20 13:32:44 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test "can mark a single transaction as a transfer" do
|
2024-07-16 09:26:49 -04:00
|
|
|
txn = @user.family.entries.account_transactions.reverse_chronological.first
|
2024-06-20 13:32:44 -04:00
|
|
|
|
|
|
|
within "#" + dom_id(txn) do
|
2024-07-10 11:22:59 -04:00
|
|
|
assert_text txn.account_transaction.category.name || "Uncategorized"
|
2024-06-20 13:32:44 -04:00
|
|
|
end
|
|
|
|
|
2024-07-01 10:49:43 -04:00
|
|
|
transaction_entry_checkbox(txn).check
|
2024-06-20 13:32:44 -04:00
|
|
|
|
|
|
|
bulk_transfer_action_button.click
|
|
|
|
click_on "Mark as transfers"
|
|
|
|
|
|
|
|
within "#" + dom_id(txn) do
|
|
|
|
assert_no_text "Uncategorized"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2024-07-01 10:49:43 -04:00
|
|
|
def transaction_entry_checkbox(transaction_entry)
|
|
|
|
find("#" + dom_id(transaction_entry, "selection"))
|
2024-06-20 13:32:44 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def bulk_transfer_action_button
|
|
|
|
find("#bulk-transfer-btn")
|
|
|
|
end
|
|
|
|
end
|