mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-23 15:19:38 +02:00
* Add kind field to valuation * Fix schema conflict * Add kind to valuation * Scaffold opening balance manager * Opening balance manager implementation * Update account import to use opening balance manager + tests * Update account to use opening balance manager * Fix test assertions, usage of current balance manager * Lint fixes * Add Opening Balance manager, add tests to forward calculator * Add credit card to "all cash" designation * Simplify valuation model * Add current balance manager with tests * Add current balance logic to reverse calculator and plaid sync * Tweaks to initial calc logic * Ledger testing helper, tweak assertions for reverse calculator * Update test assertions * Extract balance transformer, simplify calculators * Algo simplifications * Final tweaks to calculators * Cleanup * Fix error, propagate sync errors up to parent * Update migration script, valuation naming
71 lines
2 KiB
Ruby
71 lines
2 KiB
Ruby
require "test_helper"
|
|
|
|
class VehiclesControllerTest < ActionDispatch::IntegrationTest
|
|
include AccountableResourceInterfaceTest
|
|
|
|
setup do
|
|
sign_in @user = users(:family_admin)
|
|
@account = accounts(:vehicle)
|
|
end
|
|
|
|
test "creates with vehicle details" do
|
|
assert_difference -> { Account.count } => 1,
|
|
-> { Vehicle.count } => 1,
|
|
-> { Valuation.count } => 1,
|
|
-> { Entry.count } => 1 do
|
|
post vehicles_path, params: {
|
|
account: {
|
|
name: "Vehicle",
|
|
balance: 30000,
|
|
currency: "USD",
|
|
accountable_type: "Vehicle",
|
|
accountable_attributes: {
|
|
make: "Toyota",
|
|
model: "Camry",
|
|
year: 2020,
|
|
mileage_value: 15000,
|
|
mileage_unit: "mi"
|
|
}
|
|
}
|
|
}
|
|
end
|
|
|
|
created_account = Account.order(:created_at).last
|
|
|
|
assert_equal "Toyota", created_account.accountable.make
|
|
assert_equal "Camry", created_account.accountable.model
|
|
assert_equal 2020, created_account.accountable.year
|
|
assert_equal 15000, created_account.accountable.mileage_value
|
|
assert_equal "mi", created_account.accountable.mileage_unit
|
|
|
|
assert_redirected_to created_account
|
|
assert_equal "Vehicle account created", flash[:notice]
|
|
assert_enqueued_with(job: SyncJob)
|
|
end
|
|
|
|
test "updates with vehicle details" do
|
|
assert_no_difference [ "Account.count", "Vehicle.count" ] do
|
|
patch account_path(@account), params: {
|
|
account: {
|
|
name: "Updated Vehicle",
|
|
balance: 28000,
|
|
currency: "USD",
|
|
accountable_type: "Vehicle",
|
|
accountable_attributes: {
|
|
id: @account.accountable_id,
|
|
make: "Honda",
|
|
model: "Accord",
|
|
year: 2021,
|
|
mileage_value: 20000,
|
|
mileage_unit: "mi",
|
|
purchase_price: 32000
|
|
}
|
|
}
|
|
}
|
|
end
|
|
|
|
assert_redirected_to @account
|
|
assert_equal "Vehicle account updated", flash[:notice]
|
|
assert_enqueued_with(job: SyncJob)
|
|
end
|
|
end
|