1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-23 15:19:38 +02:00

Account::Entry Delegated Type (namespace updates part 7) (#923)

* Initial entryable models

* Update transfer and tests

* Update transaction controllers and tests

* Update sync process to use new entries model

* Get dashboard working again

* Update transfers, imports, and accounts to use Account::Entry

* Update system tests

* Consolidate transaction management into entries controller

* Add permitted partial key helper

* Move account transactions list to entries controller

* Delegate transaction entries search

* Move transfer relation to entry

* Update bulk transaction management flows to use entries

* Remove test code

* Test fix attempt

* Update demo data script

* Consolidate remaining transaction partials to entries

* Consolidate valuations controller to entries controller

* Lint fix

* Remove unused files, additional cleanup

* Add back valuation creation

* Make migrations fully reversible

* Stale routes cleanup

* Migrations reversible fix

* Move types to entryable concern

* Fix search when no entries found

* Remove more unused code
This commit is contained in:
Zach Gollwitzer 2024-07-01 10:49:43 -04:00 committed by GitHub
parent 320954282a
commit c3314e62d1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
105 changed files with 2150 additions and 1576 deletions

View file

@ -14,7 +14,7 @@ class SettingsTest < ApplicationSystemTestCase
[ "Tags", "Tags", tags_path ],
[ "Categories", "Categories", categories_path ],
[ "Merchants", "Merchants", merchants_path ],
[ "Rules", "Rules", account_transaction_rules_path ],
[ "Rules", "Rules", rules_transactions_path ],
[ "Imports", "Imports", imports_path ],
[ "What's New", "What's New", changelog_path ],
[ "Feedback", "Feedback", feedback_path ],

View file

@ -4,17 +4,25 @@ class TransactionsTest < ApplicationSystemTestCase
setup do
sign_in @user = users(:family_admin)
@latest_transactions = @user.family.transactions.ordered.limit(20).to_a
@page_size = 10
@latest_transactions = @user.family.entries
.account_transactions
.without_transfers
.reverse_chronological
.limit(20).to_a
@test_category = @user.family.categories.create! name: "System Test Category"
@test_merchant = @user.family.merchants.create! name: "System Test Merchant"
@target_txn = @user.family.accounts.first.transactions.create! \
@target_txn = @user.family.accounts.first.entries.create! \
name: "Oldest transaction",
date: 10.years.ago.to_date,
category: @test_category,
merchant: @test_merchant,
amount: 100
currency: @user.family.currency,
amount: 100,
entryable: Account::Transaction.new(category: @test_category,
merchant: @test_merchant)
visit transactions_url
visit transactions_url(per_page: @page_size)
end
test "can search for a transaction" do
@ -45,7 +53,7 @@ class TransactionsTest < ApplicationSystemTestCase
within "#transaction-search-filters" do
assert_text @target_txn.account.name
assert_text @target_txn.category.name
assert_text @target_txn.account_transaction.category.name
end
end
@ -75,22 +83,22 @@ class TransactionsTest < ApplicationSystemTestCase
click_button "Apply"
end
assert_text "No transactions found"
assert_text "No entries found"
# Page reload doesn't affect results
visit current_url
assert_text "No transactions found"
assert_text "No entries found"
within "ul#transaction-search-filters" do
find("li", text: @target_txn.account.name).first("a").click
find("li", text: "on or after #{10.days.ago.to_date}").first("a").click
find("li", text: "on or before #{Date.current}").first("a").click
find("li", text: @target_txn.category.name).first("a").click
find("li", text: @target_txn.merchant.name).first("a").click
find("li", text: @target_txn.account_transaction.category.name).first("a").click
find("li", text: @target_txn.account_transaction.merchant.name).first("a").click
end
assert_selector "#" + dom_id(@user.family.transactions.ordered.first), count: 1
assert_selector "#" + dom_id(@user.family.entries.reverse_chronological.first), count: 1
end
test "can select and deselect entire page of transactions" do
@ -132,17 +140,15 @@ class TransactionsTest < ApplicationSystemTestCase
private
def number_of_transactions_on_page
page_size = 10
[ @user.family.transactions.where(transfer_id: nil).count, page_size ].min
[ @user.family.entries.without_transfers.count, @page_size ].min
end
def all_transactions_checkbox
find("#selection_transaction")
find("#selection_entry")
end
def date_transactions_checkbox(date)
find("#selection_transaction_#{date}")
find("#selection_entry_#{date}")
end
def transaction_checkbox(transaction)
@ -151,9 +157,9 @@ class TransactionsTest < ApplicationSystemTestCase
def assert_selection_count(count)
if count == 0
assert_no_selector("#transaction-selection-bar")
assert_no_selector("#entry-selection-bar")
else
within "#transaction-selection-bar" do
within "#entry-selection-bar" do
assert_text "#{count} transaction#{count == 1 ? "" : "s"} selected"
end
end

View file

@ -22,45 +22,52 @@ class TransfersTest < ApplicationSystemTestCase
select savings_name, from: "To"
fill_in "account_transfer[amount]", with: 500
fill_in "Date", with: transfer_date
click_button "Create transfer"
within "#date-group-" + transfer_date.to_s do
transfer_name = "Transfer from #{checking_name} to #{savings_name}"
find("details", text: transfer_name).click
assert_text "Transfer txn name", count: 2
within "#entry-group-" + transfer_date.to_s do
assert_text "Transfer from"
end
end
test "can match 2 transactions and create a transfer" do
transfer_date = Date.current
outflow = Account::Transaction.create! name: "Outflow from savings account", date: transfer_date, account: accounts(:savings), amount: 100
inflow = Account::Transaction.create! name: "Inflow to checking account", date: transfer_date, account: accounts(:checking), amount: -100
outflow = accounts(:savings).entries.create! \
name: "Outflow from savings account",
date: transfer_date,
amount: 100,
currency: "USD",
entryable: Account::Transaction.new
inflow = accounts(:checking).entries.create! \
name: "Inflow to checking account",
date: transfer_date,
amount: -100,
currency: "USD",
entryable: Account::Transaction.new
visit transactions_url
transaction_checkbox(inflow).check
transaction_checkbox(outflow).check
transaction_entry_checkbox(inflow).check
transaction_entry_checkbox(outflow).check
bulk_transfer_action_button.click
click_on "Mark as transfers"
within "#date-group-" + transfer_date.to_s do
transfer_name = "Transfer from #{outflow.account.name} to #{inflow.account.name}"
find("details", text: transfer_name).click
assert_text inflow.name
assert_text outflow.name
within "#entry-group-" + transfer_date.to_s do
assert_text "Transfer from"
end
end
test "can mark a single transaction as a transfer" do
txn = @user.family.transactions.ordered.first
txn = @user.family.entries.reverse_chronological.first
within "#" + dom_id(txn) do
assert_text "Uncategorized"
end
transaction_checkbox(txn).check
transaction_entry_checkbox(txn).check
bulk_transfer_action_button.click
click_on "Mark as transfers"
@ -72,8 +79,8 @@ class TransfersTest < ApplicationSystemTestCase
private
def transaction_checkbox(transaction)
find("#" + dom_id(transaction, "selection"))
def transaction_entry_checkbox(transaction_entry)
find("#" + dom_id(transaction_entry, "selection"))
end
def bulk_transfer_action_button