mirror of
https://github.com/we-promise/sure.git
synced 2026-04-19 12:04:08 +00:00
Deposit, Withdrawal, and Interest Transactions for Investment View (#1075)
* Trade and Transaction builders * Consolidate logic * Remove redundant fields from trade form * Add deposit, withdrawal, and interest form controls
This commit is contained in:
@@ -16,6 +16,81 @@ class Account::TradesControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "creates deposit entry" do
|
||||
from_account = accounts(:depository) # Account the deposit is coming from
|
||||
|
||||
assert_difference -> { Account::Entry.count } => 2,
|
||||
-> { Account::Transaction.count } => 2,
|
||||
-> { Account::Transfer.count } => 1 do
|
||||
post account_trades_url(@entry.account), params: {
|
||||
account_entry: {
|
||||
type: "transfer_in",
|
||||
date: Date.current,
|
||||
amount: 10,
|
||||
transfer_account_id: from_account.id
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
assert_redirected_to account_path(@entry.account)
|
||||
end
|
||||
|
||||
test "creates withdrawal entry" do
|
||||
to_account = accounts(:depository) # Account the withdrawal is going to
|
||||
|
||||
assert_difference -> { Account::Entry.count } => 2,
|
||||
-> { Account::Transaction.count } => 2,
|
||||
-> { Account::Transfer.count } => 1 do
|
||||
post account_trades_url(@entry.account), params: {
|
||||
account_entry: {
|
||||
type: "transfer_out",
|
||||
date: Date.current,
|
||||
amount: 10,
|
||||
transfer_account_id: to_account.id
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
assert_redirected_to account_path(@entry.account)
|
||||
end
|
||||
|
||||
test "deposit and withdrawal has optional transfer account" do
|
||||
assert_difference -> { Account::Entry.count } => 1,
|
||||
-> { Account::Transaction.count } => 1,
|
||||
-> { Account::Transfer.count } => 0 do
|
||||
post account_trades_url(@entry.account), params: {
|
||||
account_entry: {
|
||||
type: "transfer_out",
|
||||
date: Date.current,
|
||||
amount: 10
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
created_entry = Account::Entry.order(created_at: :desc).first
|
||||
|
||||
assert created_entry.amount.positive?
|
||||
assert created_entry.marked_as_transfer
|
||||
assert_redirected_to account_path(@entry.account)
|
||||
end
|
||||
|
||||
test "creates interest entry" do
|
||||
assert_difference [ "Account::Entry.count", "Account::Transaction.count" ], 1 do
|
||||
post account_trades_url(@entry.account), params: {
|
||||
account_entry: {
|
||||
type: "interest",
|
||||
date: Date.current,
|
||||
amount: 10
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
created_entry = Account::Entry.order(created_at: :desc).first
|
||||
|
||||
assert created_entry.amount.negative?
|
||||
assert_redirected_to account_path(@entry.account)
|
||||
end
|
||||
|
||||
test "creates trade buy entry" do
|
||||
assert_difference [ "Account::Entry.count", "Account::Trade.count", "Security.count" ], 1 do
|
||||
post account_trades_url(@entry.account), params: {
|
||||
|
||||
Reference in New Issue
Block a user