mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-24 15:49:39 +02:00
Account::Sync model and test fixture simplifications (#968)
* Add sync model * Fresh fixtures for sync tests * Sync tests overhaul * Fix entry tests * Complete remaining model test updates * Update system tests * Update demo data task * Add system tests back to PR checks * More simplifications, add empty family to fixtures for easier testing
This commit is contained in:
parent
de5a2e55b3
commit
c6bdf49f10
60 changed files with 929 additions and 1353 deletions
|
@ -4,24 +4,28 @@ class TransactionsTest < ApplicationSystemTestCase
|
|||
setup do
|
||||
sign_in @user = users(:family_admin)
|
||||
|
||||
Account::Entry.delete_all # clean slate
|
||||
|
||||
create_transaction("one", 12.days.ago.to_date, 100)
|
||||
create_transaction("two", 10.days.ago.to_date, 100)
|
||||
create_transaction("three", 9.days.ago.to_date, 100)
|
||||
create_transaction("four", 8.days.ago.to_date, 100)
|
||||
create_transaction("five", 7.days.ago.to_date, 100)
|
||||
create_transaction("six", 7.days.ago.to_date, 100)
|
||||
create_transaction("seven", 4.days.ago.to_date, 100)
|
||||
create_transaction("eight", 3.days.ago.to_date, 100)
|
||||
create_transaction("nine", 1.days.ago.to_date, 100)
|
||||
create_transaction("ten", 1.days.ago.to_date, 100)
|
||||
create_transaction("eleven", Date.current, 100, category: categories(:food_and_drink), tags: [ tags(:one) ], merchant: merchants(:amazon))
|
||||
|
||||
@transactions = @user.family.entries
|
||||
.account_transactions
|
||||
.reverse_chronological
|
||||
|
||||
@transaction = @transactions.first
|
||||
|
||||
@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.entries.create! \
|
||||
name: "Oldest transaction",
|
||||
date: 10.years.ago.to_date,
|
||||
currency: @user.family.currency,
|
||||
amount: 100,
|
||||
entryable: Account::Transaction.new(category: @test_category,
|
||||
merchant: @test_merchant)
|
||||
|
||||
visit transactions_url(per_page: @page_size)
|
||||
end
|
||||
|
||||
|
@ -29,13 +33,13 @@ class TransactionsTest < ApplicationSystemTestCase
|
|||
assert_selector "h1", text: "Transactions"
|
||||
|
||||
within "form#transactions-search" do
|
||||
fill_in "Search transactions by name", with: @target_txn.name
|
||||
fill_in "Search transactions by name", with: @transaction.name
|
||||
end
|
||||
|
||||
assert_selector "#" + dom_id(@target_txn), count: 1
|
||||
assert_selector "#" + dom_id(@transaction), count: 1
|
||||
|
||||
within "#transaction-search-filters" do
|
||||
assert_text @target_txn.name
|
||||
assert_text @transaction.name
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -43,30 +47,34 @@ class TransactionsTest < ApplicationSystemTestCase
|
|||
find("#transaction-filters-button").click
|
||||
|
||||
within "#transaction-filters-menu" do
|
||||
check(@target_txn.account.name)
|
||||
check(@transaction.account.name)
|
||||
click_button "Category"
|
||||
check(@test_category.name)
|
||||
check(@transaction.account_transaction.category.name)
|
||||
click_button "Apply"
|
||||
end
|
||||
|
||||
assert_selector "#" + dom_id(@target_txn), count: 1
|
||||
assert_selector "#" + dom_id(@transaction), count: 1
|
||||
|
||||
within "#transaction-search-filters" do
|
||||
assert_text @target_txn.account.name
|
||||
assert_text @target_txn.account_transaction.category.name
|
||||
assert_text @transaction.account.name
|
||||
assert_text @transaction.account_transaction.category.name
|
||||
end
|
||||
end
|
||||
|
||||
test "all filters work and empty state shows if no match" do
|
||||
find("#transaction-filters-button").click
|
||||
|
||||
account = @transaction.account
|
||||
category = @transaction.account_transaction.category
|
||||
merchant = @transaction.account_transaction.merchant
|
||||
|
||||
within "#transaction-filters-menu" do
|
||||
click_button "Account"
|
||||
check(@target_txn.account.name)
|
||||
check(account.name)
|
||||
|
||||
click_button "Date"
|
||||
fill_in "q_start_date", with: 10.days.ago.to_date
|
||||
fill_in "q_end_date", with: Date.current
|
||||
fill_in "q_end_date", with: 1.day.ago.to_date
|
||||
|
||||
click_button "Type"
|
||||
assert_text "Filter by type coming soon..."
|
||||
|
@ -75,10 +83,10 @@ class TransactionsTest < ApplicationSystemTestCase
|
|||
assert_text "Filter by amount coming soon..."
|
||||
|
||||
click_button "Category"
|
||||
check(@test_category.name)
|
||||
check(category.name)
|
||||
|
||||
click_button "Merchant"
|
||||
check(@test_merchant.name)
|
||||
check(merchant.name)
|
||||
|
||||
click_button "Apply"
|
||||
end
|
||||
|
@ -91,14 +99,14 @@ class TransactionsTest < ApplicationSystemTestCase
|
|||
assert_text "No entries found"
|
||||
|
||||
within "ul#transaction-search-filters" do
|
||||
find("li", text: @target_txn.account.name).first("a").click
|
||||
find("li", text: 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.account_transaction.category.name).first("a").click
|
||||
find("li", text: @target_txn.account_transaction.merchant.name).first("a").click
|
||||
find("li", text: "on or before #{1.day.ago.to_date}").first("a").click
|
||||
find("li", text: category.name).first("a").click
|
||||
find("li", text: merchant.name).first("a").click
|
||||
end
|
||||
|
||||
assert_selector "#" + dom_id(@user.family.entries.reverse_chronological.first), count: 1
|
||||
assert_selector "#" + dom_id(@transaction), count: 1
|
||||
end
|
||||
|
||||
test "can select and deselect entire page of transactions" do
|
||||
|
@ -109,36 +117,52 @@ class TransactionsTest < ApplicationSystemTestCase
|
|||
end
|
||||
|
||||
test "can select and deselect groups of transactions" do
|
||||
date_transactions_checkbox(12.days.ago.to_date).check
|
||||
assert_selection_count(3)
|
||||
date_transactions_checkbox(12.days.ago.to_date).uncheck
|
||||
date_transactions_checkbox(1.day.ago.to_date).check
|
||||
assert_selection_count(2)
|
||||
|
||||
date_transactions_checkbox(1.day.ago.to_date).uncheck
|
||||
assert_selection_count(0)
|
||||
end
|
||||
|
||||
test "can select and deselect individual transactions" do
|
||||
transaction_checkbox(@latest_transactions.first).check
|
||||
transaction_checkbox(@transactions.first).check
|
||||
assert_selection_count(1)
|
||||
transaction_checkbox(@latest_transactions.second).check
|
||||
transaction_checkbox(@transactions.second).check
|
||||
assert_selection_count(2)
|
||||
transaction_checkbox(@latest_transactions.second).uncheck
|
||||
transaction_checkbox(@transactions.second).uncheck
|
||||
assert_selection_count(1)
|
||||
end
|
||||
|
||||
test "outermost group always overrides inner selections" do
|
||||
transaction_checkbox(@latest_transactions.first).check
|
||||
transaction_checkbox(@transactions.first).check
|
||||
assert_selection_count(1)
|
||||
|
||||
all_transactions_checkbox.check
|
||||
assert_selection_count(number_of_transactions_on_page)
|
||||
transaction_checkbox(@latest_transactions.first).uncheck
|
||||
|
||||
transaction_checkbox(@transactions.first).uncheck
|
||||
assert_selection_count(number_of_transactions_on_page - 1)
|
||||
date_transactions_checkbox(12.days.ago.to_date).uncheck
|
||||
assert_selection_count(number_of_transactions_on_page - 4)
|
||||
|
||||
date_transactions_checkbox(1.day.ago.to_date).uncheck
|
||||
assert_selection_count(number_of_transactions_on_page - 3)
|
||||
|
||||
all_transactions_checkbox.uncheck
|
||||
assert_selection_count(0)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def create_transaction(name, date, amount, category: nil, merchant: nil, tags: [])
|
||||
account = accounts(:depository)
|
||||
|
||||
account.entries.create! \
|
||||
name: name,
|
||||
date: date,
|
||||
amount: amount,
|
||||
currency: "USD",
|
||||
entryable: Account::Transaction.new(category: category, merchant: merchant, tags: tags)
|
||||
end
|
||||
|
||||
def number_of_transactions_on_page
|
||||
[ @user.family.entries.without_transfers.count, @page_size ].min
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue