mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-22 22:59:39 +02:00
Allow user to add buy and sell trade transactions for investment accounts (#1066)
* Consolidate modal form structure into partial + helper * Scaffold out trade transaction form * Normalize translations * Add buy and sell trade form with tests * Move entryable lists to dedicated controllers * Delegate entry group contents rendering * More cleanup * Extract transaction and valuation update logic from entries controller * Delegate edit and show actions to entryables * Trade builder * Update paths for transaction updates
This commit is contained in:
parent
6bca35fa22
commit
e05f03b314
75 changed files with 801 additions and 624 deletions
|
@ -5,114 +5,15 @@ class Account::EntriesControllerTest < ActionDispatch::IntegrationTest
|
|||
sign_in @user = users(:family_admin)
|
||||
@transaction = account_entries :transaction
|
||||
@valuation = account_entries :valuation
|
||||
@trade = account_entries :trade
|
||||
end
|
||||
|
||||
test "should edit valuation entry" do
|
||||
get edit_account_entry_url(@valuation.account, @valuation)
|
||||
assert_response :success
|
||||
end
|
||||
# =================
|
||||
# Shared
|
||||
# =================
|
||||
|
||||
test "should show transaction entry" do
|
||||
get account_entry_url(@transaction.account, @transaction)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should show valuation entry" do
|
||||
get account_entry_url(@valuation.account, @valuation)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get list of transaction entries" do
|
||||
get transaction_account_entries_url(@transaction.account)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should get list of valuation entries" do
|
||||
get valuation_account_entries_url(@valuation.account)
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "gets new entry by type" do
|
||||
get new_account_entry_url(@valuation.account, entryable_type: "Account::Valuation")
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "should create valuation" do
|
||||
assert_difference [ "Account::Entry.count", "Account::Valuation.count" ], 1 do
|
||||
post account_entries_url(@valuation.account), params: {
|
||||
account_entry: {
|
||||
name: "Manual valuation",
|
||||
amount: 19800,
|
||||
date: Date.current,
|
||||
currency: @valuation.account.currency,
|
||||
entryable_type: "Account::Valuation",
|
||||
entryable_attributes: {}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
assert_equal "Valuation created", flash[:notice]
|
||||
assert_enqueued_with job: AccountSyncJob
|
||||
assert_redirected_to account_path(@valuation.account)
|
||||
end
|
||||
|
||||
test "error when valuation already exists for date" do
|
||||
assert_no_difference_in_entries do
|
||||
post account_entries_url(@valuation.account), params: {
|
||||
account_entry: {
|
||||
amount: 19800,
|
||||
date: @valuation.date,
|
||||
currency: @valuation.currency,
|
||||
entryable_type: "Account::Valuation",
|
||||
entryable_attributes: {}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
assert_equal "Date has already been taken", flash[:alert]
|
||||
assert_redirected_to account_path(@valuation.account)
|
||||
end
|
||||
|
||||
test "can update entry without entryable attributes" do
|
||||
assert_no_difference_in_entries do
|
||||
patch account_entry_url(@valuation.account, @valuation), params: {
|
||||
account_entry: {
|
||||
name: "Updated name"
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
assert_redirected_to account_entry_url(@valuation.account, @valuation)
|
||||
assert_enqueued_with(job: AccountSyncJob)
|
||||
end
|
||||
|
||||
test "should update transaction entry with entryable attributes" do
|
||||
assert_no_difference_in_entries do
|
||||
patch account_entry_url(@transaction.account, @transaction), params: {
|
||||
account_entry: {
|
||||
name: "Updated name",
|
||||
date: Date.current,
|
||||
currency: "USD",
|
||||
amount: 20,
|
||||
entryable_type: @transaction.entryable_type,
|
||||
entryable_attributes: {
|
||||
id: @transaction.entryable_id,
|
||||
tag_ids: [ Tag.first.id, Tag.second.id ],
|
||||
category_id: Category.first.id,
|
||||
merchant_id: Merchant.first.id,
|
||||
notes: "test notes",
|
||||
excluded: false
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
assert_redirected_to account_entry_url(@transaction.account, @transaction)
|
||||
assert_enqueued_with(job: AccountSyncJob)
|
||||
end
|
||||
|
||||
test "should destroy transaction entry" do
|
||||
[ @transaction, @valuation ].each do |entry|
|
||||
test "should destroy entry" do
|
||||
[ @transaction, @valuation, @trade ].each do |entry|
|
||||
assert_difference -> { Account::Entry.count } => -1, -> { entry.entryable_class.count } => -1 do
|
||||
delete account_entry_url(entry.account, entry)
|
||||
end
|
||||
|
@ -122,6 +23,38 @@ class Account::EntriesControllerTest < ActionDispatch::IntegrationTest
|
|||
end
|
||||
end
|
||||
|
||||
test "gets show" do
|
||||
[ @transaction, @valuation, @trade ].each do |entry|
|
||||
get account_entry_url(entry.account, entry)
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
test "gets edit" do
|
||||
[ @valuation ].each do |entry|
|
||||
get edit_account_entry_url(entry.account, entry)
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
test "can update generic entry" do
|
||||
[ @transaction, @valuation, @trade ].each do |entry|
|
||||
assert_no_difference_in_entries do
|
||||
patch account_entry_url(entry.account, entry), params: {
|
||||
account_entry: {
|
||||
name: "Name",
|
||||
date: Date.current,
|
||||
currency: "USD",
|
||||
amount: 100
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
assert_redirected_to account_entry_url(entry.account, entry)
|
||||
assert_enqueued_with(job: AccountSyncJob)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# Simple guard to verify that nested attributes are passed the record ID to avoid new creation of record
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue