mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-19 13:19:39 +02:00
feat: add crypto account type to demo data (#555)
* feat: add crypto account type to demo data * fix: set currency to BTC, revert schema migration change and fix tests * fix: update dates in time_series tests
This commit is contained in:
parent
f904d9d062
commit
49d1fe0e11
8 changed files with 55 additions and 4 deletions
3
app/models/account/crypto.rb
Normal file
3
app/models/account/crypto.rb
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
class Account::Crypto < ApplicationRecord
|
||||||
|
include Accountable
|
||||||
|
end
|
|
@ -1,7 +1,7 @@
|
||||||
module Accountable
|
module Accountable
|
||||||
extend ActiveSupport::Concern
|
extend ActiveSupport::Concern
|
||||||
|
|
||||||
ASSET_TYPES = %w[ Account::Depository Account::Investment Account::OtherAsset Account::Property Account::Vehicle ]
|
ASSET_TYPES = %w[ Account::Depository Account::Investment Account::Crypto Account::OtherAsset Account::Property Account::Vehicle ]
|
||||||
LIABILITY_TYPES = %w[ Account::Credit Account::Loan Account::OtherLiability ]
|
LIABILITY_TYPES = %w[ Account::Credit Account::Loan Account::OtherLiability ]
|
||||||
TYPES = ASSET_TYPES + LIABILITY_TYPES
|
TYPES = ASSET_TYPES + LIABILITY_TYPES
|
||||||
|
|
||||||
|
|
7
db/migrate/20240319154732_create_account_cryptos.rb
Normal file
7
db/migrate/20240319154732_create_account_cryptos.rb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
class CreateAccountCryptos < ActiveRecord::Migration[7.2]
|
||||||
|
def change
|
||||||
|
create_table :account_cryptos, id: :uuid do |t|
|
||||||
|
t.timestamps
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
7
db/schema.rb
generated
7
db/schema.rb
generated
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema[7.2].define(version: 2024_03_09_180636) do
|
ActiveRecord::Schema[7.2].define(version: 2024_03_19_154732) do
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "pgcrypto"
|
enable_extension "pgcrypto"
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
@ -35,6 +35,11 @@ ActiveRecord::Schema[7.2].define(version: 2024_03_09_180636) do
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
create_table "account_cryptos", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||||
|
t.datetime "created_at", null: false
|
||||||
|
t.datetime "updated_at", null: false
|
||||||
|
end
|
||||||
|
|
||||||
create_table "account_depositories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
create_table "account_depositories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at", null: false
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
|
|
|
@ -219,6 +219,24 @@ namespace :demo_data do
|
||||||
|
|
||||||
brokerage.sync
|
brokerage.sync
|
||||||
|
|
||||||
|
crypto = Account.find_or_create_by(name: "Bitcoin Account") do |a|
|
||||||
|
a.family = family
|
||||||
|
a.accountable = Account::Crypto.new
|
||||||
|
a.currency = "BTC"
|
||||||
|
a.balance = 0.1
|
||||||
|
end
|
||||||
|
|
||||||
|
crypto_valuations = [
|
||||||
|
{ date: 1.year.ago.to_date, value: 0.05, currency: "BTC" },
|
||||||
|
{ date: 200.days.ago.to_date, value: 0.06, currency: "BTC" },
|
||||||
|
{ date: 100.days.ago.to_date, value: 0.08, currency: "BTC" },
|
||||||
|
{ date: 20.days.ago.to_date, value: 0.1, currency: "BTC" }
|
||||||
|
]
|
||||||
|
|
||||||
|
crypto.valuations.upsert_all(crypto_valuations, unique_by: :index_valuations_on_account_id_and_date)
|
||||||
|
|
||||||
|
crypto.sync
|
||||||
|
|
||||||
mortgage = Account.find_or_create_by(name: "Demo Mortgage") do |a|
|
mortgage = Account.find_or_create_by(name: "Demo Mortgage") do |a|
|
||||||
a.family = family
|
a.family = family
|
||||||
a.accountable = Account::Loan.new
|
a.accountable = Account::Loan.new
|
||||||
|
|
11
test/fixtures/account/cryptos.yml
vendored
Normal file
11
test/fixtures/account/cryptos.yml
vendored
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
||||||
|
# This model initially had no columns defined. If you add columns to the
|
||||||
|
# model remove the "{}" from the fixture names and add the columns immediately
|
||||||
|
# below each fixture, per the syntax in the comments below
|
||||||
|
#
|
||||||
|
# one: {}
|
||||||
|
# column: value
|
||||||
|
#
|
||||||
|
# two: {}
|
||||||
|
# column: value
|
7
test/models/account/crypto_test.rb
Normal file
7
test/models/account/crypto_test.rb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
require "test_helper"
|
||||||
|
|
||||||
|
class Account::CryptoTest < ActiveSupport::TestCase
|
||||||
|
# test "the truth" do
|
||||||
|
# assert true
|
||||||
|
# end
|
||||||
|
end
|
|
@ -39,12 +39,12 @@ class TimeSeriesTest < ActiveSupport::TestCase
|
||||||
expected_values = {
|
expected_values = {
|
||||||
values: [
|
values: [
|
||||||
{
|
{
|
||||||
date: "2024-03-17",
|
date: 1.day.ago.to_date,
|
||||||
value: { amount: "100.0", currency: "USD" },
|
value: { amount: "100.0", currency: "USD" },
|
||||||
trend: { type: "normal", direction: "flat", value: { amount: "0.0", currency: "USD" }, percent: 0.0 }
|
trend: { type: "normal", direction: "flat", value: { amount: "0.0", currency: "USD" }, percent: 0.0 }
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
date: "2024-03-18",
|
date: Date.current,
|
||||||
value: { amount: "200.0", currency: "USD" },
|
value: { amount: "200.0", currency: "USD" },
|
||||||
trend: { type: "normal", direction: "up", value: { amount: "100.0", currency: "USD" }, percent: 100.0 }
|
trend: { type: "normal", direction: "up", value: { amount: "100.0", currency: "USD" }, percent: 100.0 }
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue