mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-19 05:09:38 +02:00
Account:: namespace simplifications and cleanup (#2110)
* Flatten Holding model * Flatten balance model * Entries domain renames * Fix valuations reference * Fix trades stream * Fix brakeman warnings * Fix tests * Replace existing entryable type references in DB
This commit is contained in:
parent
f181ba941f
commit
e657c40d19
172 changed files with 1297 additions and 1258 deletions
|
@ -1,11 +1,77 @@
|
|||
require "test_helper"
|
||||
|
||||
class TransactionsControllerTest < ActionDispatch::IntegrationTest
|
||||
include Account::EntriesTestHelper
|
||||
include EntryableResourceInterfaceTest, EntriesTestHelper
|
||||
|
||||
setup do
|
||||
sign_in @user = users(:family_admin)
|
||||
@transaction = account_entries(:transaction)
|
||||
@entry = entries(:transaction)
|
||||
end
|
||||
|
||||
test "creates with transaction details" do
|
||||
assert_difference [ "Entry.count", "Transaction.count" ], 1 do
|
||||
post transactions_url, params: {
|
||||
entry: {
|
||||
account_id: @entry.account_id,
|
||||
name: "New transaction",
|
||||
date: Date.current,
|
||||
currency: "USD",
|
||||
amount: 100,
|
||||
nature: "inflow",
|
||||
entryable_type: @entry.entryable_type,
|
||||
entryable_attributes: {
|
||||
tag_ids: [ Tag.first.id, Tag.second.id ],
|
||||
category_id: Category.first.id,
|
||||
merchant_id: Merchant.first.id
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
created_entry = Entry.order(:created_at).last
|
||||
|
||||
assert_redirected_to account_url(created_entry.account)
|
||||
assert_equal "Transaction created", flash[:notice]
|
||||
assert_enqueued_with(job: SyncJob)
|
||||
end
|
||||
|
||||
test "updates with transaction details" do
|
||||
assert_no_difference [ "Entry.count", "Transaction.count" ] do
|
||||
patch transaction_url(@entry), params: {
|
||||
entry: {
|
||||
name: "Updated name",
|
||||
date: Date.current,
|
||||
currency: "USD",
|
||||
amount: 100,
|
||||
nature: "inflow",
|
||||
entryable_type: @entry.entryable_type,
|
||||
notes: "test notes",
|
||||
excluded: false,
|
||||
entryable_attributes: {
|
||||
id: @entry.entryable_id,
|
||||
tag_ids: [ Tag.first.id, Tag.second.id ],
|
||||
category_id: Category.first.id,
|
||||
merchant_id: Merchant.first.id
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
@entry.reload
|
||||
|
||||
assert_equal "Updated name", @entry.name
|
||||
assert_equal Date.current, @entry.date
|
||||
assert_equal "USD", @entry.currency
|
||||
assert_equal -100, @entry.amount
|
||||
assert_equal [ Tag.first.id, Tag.second.id ], @entry.entryable.tag_ids.sort
|
||||
assert_equal Category.first.id, @entry.entryable.category_id
|
||||
assert_equal Merchant.first.id, @entry.entryable.merchant_id
|
||||
assert_equal "test notes", @entry.notes
|
||||
assert_equal false, @entry.excluded
|
||||
|
||||
assert_equal "Transaction updated", flash[:notice]
|
||||
assert_redirected_to account_url(@entry.account)
|
||||
assert_enqueued_with(job: SyncJob)
|
||||
end
|
||||
|
||||
test "transaction count represents filtered total" do
|
||||
|
@ -19,7 +85,7 @@ class TransactionsControllerTest < ActionDispatch::IntegrationTest
|
|||
|
||||
get transactions_url(per_page: 10)
|
||||
|
||||
assert_dom "#total-transactions", count: 1, text: family.entries.account_transactions.size.to_s
|
||||
assert_dom "#total-transactions", count: 1, text: family.entries.transactions.size.to_s
|
||||
|
||||
searchable_transaction = create_transaction(account: account, name: "Unique test name")
|
||||
|
||||
|
@ -39,7 +105,7 @@ class TransactionsControllerTest < ActionDispatch::IntegrationTest
|
|||
create_transaction(account: account)
|
||||
end
|
||||
|
||||
sorted_transactions = family.entries.account_transactions.reverse_chronological.to_a
|
||||
sorted_transactions = family.entries.transactions.reverse_chronological.to_a
|
||||
|
||||
assert_equal 11, sorted_transactions.count
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue