1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-19 21:29:38 +02:00
Maybe/test/interfaces/accountable_resource_interface_test.rb
Zach Gollwitzer e657c40d19
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
2025-04-14 11:40:34 -04:00

91 lines
2.7 KiB
Ruby

require "test_helper"
module AccountableResourceInterfaceTest
extend ActiveSupport::Testing::Declarative
test "shows new form" do
Family.any_instance.stubs(:get_link_token).returns("test-link-token")
get new_polymorphic_url(@account.accountable)
assert_response :success
end
test "shows edit form" do
get edit_account_url(@account)
assert_response :success
end
test "renders accountable page" do
get account_url(@account)
assert_response :success
end
test "destroys account" do
delete account_url(@account)
assert_redirected_to accounts_path
assert_enqueued_with job: DestroyJob
assert_equal "#{@account.accountable_name.underscore.humanize} account scheduled for deletion", flash[:notice]
end
test "updates basic account balances" do
assert_no_difference [ "Account.count", "@account.accountable_class.count" ] do
patch account_url(@account), params: {
account: {
name: "Updated name",
balance: 10000,
currency: "USD"
}
}
end
assert_redirected_to @account
assert_equal "#{@account.accountable_name.underscore.humanize} account updated", flash[:notice]
end
test "creates with basic attributes" do
assert_difference [ "Account.count", "@account.accountable_class.count" ], 1 do
post "/#{@account.accountable_name.pluralize}", params: {
account: {
accountable_type: @account.accountable_class,
name: "New accountable",
balance: 10000,
currency: "USD",
subtype: "checking"
}
}
end
assert_redirected_to Account.order(:created_at).last
assert_equal "#{@account.accountable_name.humanize} account created", flash[:notice]
end
test "updates account balance by creating new valuation if balance has changed" do
assert_difference [ "Entry.count", "Valuation.count" ], 1 do
patch account_url(@account), params: {
account: {
balance: 12000
}
}
end
assert_redirected_to @account
assert_enqueued_with job: SyncJob
assert_equal "#{@account.accountable_name.humanize} account updated", flash[:notice]
end
test "updates account balance by editing existing valuation for today" do
@account.entries.create! date: Date.current, amount: 6000, currency: "USD", name: "Balance update", entryable: Valuation.new
assert_no_difference [ "Entry.count", "Valuation.count" ] do
patch account_url(@account), params: {
account: {
balance: 12000
}
}
end
assert_redirected_to @account
assert_enqueued_with job: SyncJob
assert_equal "#{@account.accountable_name.humanize} account updated", flash[:notice]
end
end