1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-24 23:59:40 +02:00

Account Issue Model and Resolution Flow + Troubleshooting guides (#1090)

* Rough draft of issue system

* Simplify design

* Remove stale files from merge conflicts

* STI for issues

* Cleanup

* Improve Synth api key flow

* Stub api key for test
This commit is contained in:
Zach Gollwitzer 2024-08-16 12:13:48 -04:00 committed by GitHub
parent c70a08aca2
commit 707c5ca0ca
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
52 changed files with 507 additions and 211 deletions

View file

@ -78,7 +78,9 @@ class Account::Balance::SyncerTest < ActiveSupport::TestCase
create_exchange_rate(1.day.ago.to_date, from: "EUR", to: "USD", rate: 2)
create_exchange_rate(Date.current, from: "EUR", to: "USD", rate: 2)
run_sync_for(@account)
with_env_overrides SYNTH_API_KEY: ENV["SYNTH_API_KEY"] || "fookey" do
run_sync_for(@account)
end
usd_balances = @account.balances.where(currency: "USD").chronological.map(&:balance)
eur_balances = @account.balances.where(currency: "EUR").chronological.map(&:balance)
@ -88,30 +90,29 @@ class Account::Balance::SyncerTest < ActiveSupport::TestCase
assert_equal [ 42000, 40000, 40000 ], usd_balances # converted balances at rate of 2:1
end
test "fails with error if exchange rate not available for any entry" do
create_transaction(account: @account, currency: "EUR")
test "raises issue if missing exchange rates" do
create_transaction(date: Date.current, account: @account, currency: "EUR")
ExchangeRate.expects(:find_rate).with(from: "EUR", to: "USD", date: Date.current).returns(nil)
@account.expects(:observe_missing_exchange_rates).with(from: "EUR", to: "USD", dates: [ Date.current ])
syncer = Account::Balance::Syncer.new(@account)
with_env_overrides SYNTH_API_KEY: nil do
assert_raises Money::ConversionError do
syncer.run
end
end
syncer.run
end
# Account is able to calculate balances in its own currency (i.e. can still show a historical graph), but
# doesn't have exchange rates available to convert those calculated balances to the family currency
test "completes with warning if exchange rates not available to convert to family currency" do
test "observes issue if exchange rate provider is not configured" do
@account.update! currency: "EUR"
syncer = Account::Balance::Syncer.new(@account)
@account.expects(:observe_missing_exchange_rate_provider)
with_env_overrides SYNTH_API_KEY: nil do
syncer.run
end
assert_equal 1, syncer.warnings.count
end
test "overwrites existing balances and purges stale balances" do

View file

@ -84,6 +84,8 @@ class Account::Holding::SyncerTest < ActiveSupport::TestCase
Security::Price.new(ticker: "AMZN", date: 1.day.ago.to_date, price: 215)
])
@account.expects(:observe_missing_price).with(ticker: "AMZN", date: Date.current).once
run_sync_for(@account)
assert_holdings(expected)

View file

@ -0,0 +1,7 @@
require "test_helper"
class Account::IssueTest < ActiveSupport::TestCase
test "the truth" do
assert true
end
end

View file

@ -14,14 +14,11 @@ class Account::SyncTest < ActiveSupport::TestCase
Account::Balance::Syncer.expects(:new).with(@account, start_date: nil).returns(@balance_syncer).once
Account::Holding::Syncer.expects(:new).with(@account, start_date: nil).returns(@holding_syncer).once
@account.expects(:resolve_stale_issues).once
@balance_syncer.expects(:run).once
@balance_syncer.expects(:warnings).returns([ "test balance sync warning" ]).once
@holding_syncer.expects(:run).once
@holding_syncer.expects(:warnings).returns([ "test holding sync warning" ]).once
assert_equal "pending", @sync.status
assert_equal [], @sync.warnings
assert_nil @sync.last_ran_at
@sync.run
@ -29,7 +26,6 @@ class Account::SyncTest < ActiveSupport::TestCase
streams = capture_turbo_stream_broadcasts [ @account.family, :notifications ]
assert_equal "completed", @sync.status
assert_equal [ "test balance sync warning", "test holding sync warning" ], @sync.warnings
assert @sync.last_ran_at
assert_equal "append", streams.first["action"]

View file

@ -1,21 +0,0 @@
require "test_helper"
class Help::ArticleTest < ActiveSupport::TestCase
include ActiveJob::TestHelper
setup do
Help::Article.stubs(:root_path).returns(Rails.root.join("test", "fixtures", "files"))
end
test "returns nil if article not found" do
assert_nil Help::Article.find("missing")
end
test "find and renders markdown article" do
article = Help::Article.find("placeholder")
assert_equal "Placeholder", article.title
assert_equal "Test help article", article.content
assert_equal "<p>Test help article</p>\n", article.html
end
end

View file

@ -0,0 +1,7 @@
require "test_helper"
class IssueTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end